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