OpenLexocad  27.0
StringTool.h
Go to the documentation of this file.
1 #pragma once
2 #pragma warning(disable : 4251)
3 
4 #include <Base/String.h>
5 #include <Geom/Dir.h>
6 #include <Geom/Pnt.h>
7 #include <Geom/Vec.h>
8 #include <Geom/XYZ.h>
9 #include <Geom/geom_defines.h>
10 
11 #include <iomanip>
12 #include <sstream>
13 #include <string>
14 
15 #if _MSC_VER >= 1600
16 #define BOOST_HAS_STDINT_H
17 #endif
18 #include <stdint.h>
19 
20 class QString;
21 
22 #if _MSC_VER >= 1800
23 class QUuid;
24 #else
25 struct QUuid;
26 #endif
27 
28 namespace Geom
29 {
31 {
32 public:
33  template <typename T>
34  static std::string toStlString(const T& t)
35  {
36  std::stringstream ss;
37  ss << t;
38  return ss.str();
39  }
40 
41  template <typename T>
42  static std::string toStlString(const T& t, int precision)
43  {
44  std::stringstream ss;
45  ss.precision(precision);
46  ss << t;
47  return ss.str();
48  }
49 
50  template <typename T>
51  static std::string toStlString(const T& t, int fieldWidth, char fillChar)
52  {
53  std::stringstream ss;
54  ss << std::setfill(fillChar) << std::setw(fieldWidth) << t;
55  return ss.str();
56  }
57 
58 
59 
60  template <>
61  static std::string toStlString<Geom::Pnt>(const Geom::Pnt& p, int precision)
62  {
63  std::stringstream ss;
64  ss.precision(precision);
65  ss << "x: " << p.x() << " y: " << p.y() << " z: " << p.z();
66  return ss.str();
67  }
68 
69  template <>
70  static std::string toStlString<Geom::Vec>(const Geom::Vec& v, int precision)
71  {
72  std::stringstream ss;
73  ss.precision(precision);
74  ss << "x: " << v.x() << " y: " << v.y() << " z: " << v.z();
75  return ss.str();
76  }
77 
78  template <>
79  static std::string toStlString<Geom::XYZ>(const Geom::XYZ& xyz, int precision)
80  {
81  std::stringstream ss;
82  ss.precision(precision);
83  ss << "x: " << xyz.x() << " y: " << xyz.y() << " z: " << xyz.z();
84  return ss.str();
85  }
86 
87  template <>
88  static std::string toStlString<Geom::Dir>(const Geom::Dir& dir, int precision)
89  {
90  std::stringstream ss;
91  ss.precision(precision);
92  ss << "x: " << dir.x() << " y: " << dir.y() << " z: " << dir.z();
93  return ss.str();
94  }
95 
96  template <typename T>
97  static Base::String toString(const T& t)
98  {
99  std::wstringstream ss;
100  ss << t;
101  return ss.str();
102  }
103 
104  template <typename T>
105  static Base::String toString(const T& t, int precision)
106  {
107  std::wstringstream ss;
108  ss.precision(precision);
109  ss << t;
110  return ss.str();
111  }
112 
113  template <typename T>
114  static Base::String toString(const T& t, int fieldWidth, wchar_t fillChar)
115  {
116  std::wstringstream ss;
117  ss << std::setfill(fillChar) << std::setw(fieldWidth) << t;
118  return ss.str();
119  }
120 
121  template <>
122  static Base::String toString<Geom::Pnt>(const Geom::Pnt& p, int precision)
123  {
124  std::wstringstream ss;
125  ss.precision(precision);
126  ss << "x: " << p.x() << " y: " << p.y() << " z: " << p.z();
127  return ss.str();
128  }
129 
130  template <>
131  static Base::String toString<Geom::Vec>(const Geom::Vec& v, int precision)
132  {
133  std::wstringstream ss;
134  ss.precision(precision);
135  ss << "x: " << v.x() << " y: " << v.y() << " z: " << v.z();
136  return ss.str();
137  }
138 
139  template <>
140  static Base::String toString<Geom::XYZ>(const Geom::XYZ& xyz, int precision)
141  {
142  std::wstringstream ss;
143  ss.precision(precision);
144  ss << "x: " << xyz.x() << " y: " << xyz.y() << " z: " << xyz.z();
145  return ss.str();
146  }
147 
148  template <>
149  static Base::String toString<Geom::Dir>(const Geom::Dir& dir, int precision)
150  {
151  std::wstringstream ss;
152  ss.precision(precision);
153  ss << "x: " << dir.x() << " y: " << dir.y() << " z: " << dir.z();
154  return ss.str();
155  }
156  void to_do();
157 };
158 
159 } // namespace Geom
double z() const
For this point, returns its X coordinate.
Definition: Rotation.h:5
double x() const
Returns the X coordinate for a unit vector.
double y() const
Returns the Y coordinate for a unit vector.
double z() const
Returns the Z coordinate for a unit vector.
Defines a non-persistent 3D Cartesian point.
Definition: Pnt.h:42
double y() const
For this point, returns its X coordinate.
double x() const
For this vector, returns its X coordinate.
double z() const
Returns the X, Y, or Z coordinate of this number triple.
static std::string toStlString(const T &t, int fieldWidth, char fillChar)
Definition: StringTool.h:51
static Base::String toString(const T &t, int precision)
Definition: StringTool.h:105
#define GEOM_EXPORT
Definition: geom_defines.h:8
A Utf-16 (windows) or ucs4 (unix) encoded string class.
Definition: String.h:29
double x() const
For this point, returns its X coordinate.
Definition: StringTool.h:30
Definition: XYZ.h:46
double z() const
For this vector, returns its Z coordinate.
static std::string toStlString(const T &t, int precision)
Definition: StringTool.h:42
Definition: Dir.h:46
static std::string toStlString(const T &t)
Definition: StringTool.h:34
static Base::String toString(const T &t)
Definition: StringTool.h:97
double x() const
Returns the X, Y, or Z coordinate of this number triple.
Defines a non-persistent vector in 3D space.
Definition: Vec.h:45
double y() const
For this vector, returns its Y coordinate.
static Base::String toString(const T &t, int fieldWidth, wchar_t fillChar)
Definition: StringTool.h:114
double y() const
Returns the X, Y, or Z coordinate of this number triple.