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