API Documentation
Loading...
Searching...
No Matches
StringStream.h
Go to the documentation of this file.
1/**--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Base
28File: StringStream
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include <NDEVR/Vector.h>
34#include <NDEVR/Bounds.h>
35#include <NDEVR/NumberParser.h>
36#include <NDEVR/ObjectInfo.h>
37#include <NDEVR/Buffer.h>
38#include "Matrix.hpp"
39#include <string>
40#if _MSC_VER
41#pragma warning( disable : 4661)
42#endif
43namespace NDEVR
44{
45 class TypeInfo;
46 class String;
47 class TranslatedString;
49 {
50 public:
51 static const char* begin(const String& s);
52 static const char* end(const String& s);
53 static Buffer<String, uint04, ObjectAllocator<false>> split(const String& s, char split);
54 };
56 {
57 public:
58 static const char* ValidRegex(const TypeInfo& info);
59 };
60 template<class t_type>
62 {
63 public:
64 static void toString(const t_type& value, String& string);
65 static void toDisplayString(const t_type& value, TranslatedString& string);
66 static void fromString(const String& string, t_type& value);
67 static const char* getValidRegex();
68 };
69 template<>
71 {
72 public:
73 static void toString(const String& value, String& string);
74 static void toDisplayString(const String& value, TranslatedString& string);
75 static void fromString(const String& string, String& value);
76 static const char* getValidRegex();
77 };
78 template<uint01 t_dims, class t_type>
79 class StringStream<Vector<t_dims, t_type>>
80 {
81 public:
82 static void toString(const Vector<t_dims, t_type>& value, String& string)
83 {
84 StringStream<t_type>::toString(value[0], string);
85 for (uint01 dim = 1; dim < t_dims; ++dim)
86 {
88 StringStream<t_type>::toString(value[dim], string);
89 }
90 }
91
92 static void fromString(const String& string, Vector<t_dims, t_type>& value)
93 {
94 if constexpr (ObjectInfo<t_type>::Number)
95 {
96 const char* iter = StringSplitter::begin(string);
97 const char* end = StringSplitter::end(string);
98 for (uint01 dim = 0; dim < t_dims; ++dim)
99 {
100 value[dim] = NumberParser::parse<t_type>(iter, &iter);
101 for (; iter < end; iter++)
102 {
103 if (*iter == ',')
104 break;
105 }
106 if (iter == end)
107 {
108 ++dim;
109 for (; dim < t_dims; ++dim)
110 {
111 value[dim] = Constant<t_type>::NaN;
112 }
113 return;
114 }
115 iter++;//skip over ,
116 }
117 }
118 else
119 {
121 for (uint01 dim = 0; dim < t_dims; ++dim)
122 {
123 if (parts.size() > dim)
124 {
125 t_type val = value[dim];
126 StringStream<t_type>::fromString(parts[dim], val);
127 value[dim] = val;
128 }
129 else
130 value[dim] = Constant<t_type>::NaN;
131 }
132 }
133 }
134 static void toDisplayString(const Vector<t_dims, t_type>& value, TranslatedString& string) { return toString(value, string); }
135 static const char* getValidRegex()
136 {
137 return ".*";
138 };
139 };
140
141
142 template<uint01 t_dims, class t_type>
143 class StringStream<Bounds<t_dims, t_type>>
144 {
145 public:
146 static void toString(const Bounds<t_dims, t_type>& value, String& string)
147 {
149 StringStream<char>::toString('^', string);
151 }
152
153 static void fromString(const String& string, Bounds<t_dims, t_type>& value)
154 {
156 if (parts.size() < 2)
157 {
159 }
160 else
161 {
164 }
165
166 }
167 static void toDisplayString(const Bounds<t_dims, t_type>& value, String& string) { return toString(value, string); }
168 static const char* getValidRegex()
169 {
170 return ".*";
171 };
172 };
173
174 template<uint01 t_dims, class t_type, class t_vector_type>
175 class StringStream<Vertex<t_dims, t_type, t_vector_type>>
176 {
177 public:
178 static void toString(const Vertex<t_dims, t_type, t_vector_type>& value, String& string)
179 {
181 }
182
183 static void fromString(const String& string, Vertex<t_dims, t_type, t_vector_type>& value)
184 {
186 }
187 static void toDisplayString(const Vertex<t_dims, t_type, t_vector_type>& value, TranslatedString& string) { return toString(value, string); }
188 static const char* getValidRegex()
189 {
190 return ".*";
191 };
192 };
193 template<uint01 t_dims, class t_type, class t_vector_type>
194 class StringStream<Ray<t_dims, t_type, t_vector_type>>
195 {
196 public:
197 static void toString(const Ray<t_dims, t_type, t_vector_type>& value, String& string)
198 {
200 }
201
202 static void fromString(const String& string, Ray<t_dims, t_type, t_vector_type>& value)
203 {
205 }
206 static void toDisplayString(const Ray<t_dims, t_type, t_vector_type>& value, TranslatedString& string) { return toString(value, string); }
207 static const char* getValidRegex()
208 {
209 return ".*";
210 };
211 };
212 template<class t_type, class t_index_type, class t_memory_allocater, class t_memory_manager>
213 class StringStream<Buffer<t_type, t_index_type, t_memory_allocater, t_memory_manager>>
214 {
215 public:
217 {
218 for (uint04 i = 0; i < value.size(); i++)
219 {
220 StringStream<t_type>::toString(value[i], string);
221 }
222 }
223
225 {
227 value.setSize(strings.size());
228 for (uint04 i = 0; i < value.size(); i++)
229 {
230 StringStream<t_type>::fromString(strings[i], value[i]);
231 }
232 }
234 static const char* getValidRegex()
235 {
236 return ".*";
237 };
238 };
239
240 /*template<typename t_type, typename std::enable_if<std::is_enum<t_type>::value>::type>
241 class StringStream<t_type>
242 {
243 public:
244 static void toString(const t_type& value, String& string)
245 {
246 StringStream<sint04>::toString(value, string);
247 }
248 static void fromString(const String& string, t_type& value)
249 {
250 StringStream<sint04>::fromString(string, value);
251 }
252
253 static const char* getValidRegex()
254 {
255 return StringStream<sint04>::getValidRegex();
256 };
257 };*/
258 template<class t_type, uint01 t_row_dims, uint01 t_col_dims>
259 class StringStream<Matrix<t_type, t_row_dims, t_col_dims>>
260 {
261 public:
262 static void toString(const Matrix<t_type, t_row_dims, t_col_dims>& value, String& string)
263 {
264 for (uint01 col = 0; col < t_col_dims; ++col)
265 {
266 StringStream<t_type>::toString(value[col][0], string);
267 for (uint01 row = 1; row < t_row_dims; ++row)
268 {
269 StringStream<char>::toString(',', string);
270 StringStream<t_type>::toString(value[col][row], string);
271 }
272 StringStream<char>::toString(';', string);
273 }
274 }
275
277 {
279 for (uint01 col = 0; col < t_col_dims; ++col)
280 {
281 if (col < columns.size())
282 {
284 for (uint01 row = 0; row < t_row_dims; ++row)
285 {
286 if (row < rows.size())
287 StringStream<t_type>::fromString(rows[row], value[col][row]);
288 else
289 value[col][row] = Constant<t_type>::NaN;
290 }
291 }
292 else
293 {
294 for (uint01 row = 0; row < t_row_dims; ++row)
295 {
296 value[col][row] = Constant<t_type>::NaN;
297 }
298 }
299 }
300 }
301 static void toDisplayString(const Matrix<t_type, t_row_dims, t_col_dims>& value, TranslatedString& string) { return toString(value, string); }
302 static const char* getValidRegex()
303 {
304 return ".*";
305 };
306 };
320 class BitReference;
324
329 class BitFlag;
331 struct Font;
333 class RGBColor;
335 class ACIColor;
337 class XYZColor;
339 class LABColor;
341 class HSLColor;
343 class HSBColor;
345 class Time;
347 class TimeSpan;
349 class UUID;
351 template<class t_type>
352 class Angle;
355 class File;
357 class TranslatedString;
359
362}
#define NDEVR_BASE_API
Definition DLLInfo.h:78
ACI colors are the standard colors used in AutoCAD-based products. Each color is identified by an ACI...
Definition ACIColor.h:58
Stores an angle in an optimized format.
Definition StringStream.h:352
Definition BitReference.hpp:38
A specification of upper and lower bounds in N-dimensions.
Definition Bounds.hpp:57
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:64
constexpr t_index_type size() const
Definition Buffer.hpp:1461
void setSize(t_index_type new_size)
Definition Buffer.hpp:1413
Definition File.h:47
Definition HSBColor.h:56
Definition HSLColor.h:54
Definition LABColor.h:60
Definition Matrix.hpp:173
static t_type parse(const char *in, const char **out=nullptr, t_type NaN_Value=Constant< t_type >::NaN, bool check_overflow=true)
Definition NumberParser.hpp:83
Represents a color in the RGB space with optional alpha transparency.
Definition RGBColor.h:53
Definition Vertex.hpp:341
Definition String.h:40
Definition StringStream.h:49
static const char * begin(const String &s)
Definition String.cpp:1343
static const char * end(const String &s)
Definition String.cpp:1347
static Buffer< String, uint04, ObjectAllocator< false > > split(const String &s, char split)
Definition String.cpp:1339
static void toString(const Bounds< t_dims, t_type > &value, String &string)
Definition StringStream.h:146
static const char * getValidRegex()
Definition StringStream.h:168
static void toDisplayString(const Bounds< t_dims, t_type > &value, String &string)
Definition StringStream.h:167
static void fromString(const String &string, Bounds< t_dims, t_type > &value)
Definition StringStream.h:153
static void toDisplayString(const Buffer< t_type, t_index_type, t_memory_allocater, t_memory_manager > &value, TranslatedString &string)
Definition StringStream.h:233
static void fromString(const String &string, Buffer< t_type, t_index_type, t_memory_allocater, t_memory_manager > &value)
Definition StringStream.h:224
static void toString(const Buffer< t_type, t_index_type, t_memory_allocater, t_memory_manager > &value, String &string)
Definition StringStream.h:216
static const char * getValidRegex()
Definition StringStream.h:302
static void toDisplayString(const Matrix< t_type, t_row_dims, t_col_dims > &value, TranslatedString &string)
Definition StringStream.h:301
static void toString(const Matrix< t_type, t_row_dims, t_col_dims > &value, String &string)
Definition StringStream.h:262
static void fromString(const String &string, Matrix< t_type, t_row_dims, t_col_dims > &value)
Definition StringStream.h:276
static void toString(const Ray< t_dims, t_type, t_vector_type > &value, String &string)
Definition StringStream.h:197
static void toDisplayString(const Ray< t_dims, t_type, t_vector_type > &value, TranslatedString &string)
Definition StringStream.h:206
static const char * getValidRegex()
Definition StringStream.h:207
static void fromString(const String &string, Ray< t_dims, t_type, t_vector_type > &value)
Definition StringStream.h:202
static void fromString(const String &string, Vector< t_dims, t_type > &value)
Definition StringStream.h:92
static const char * getValidRegex()
Definition StringStream.h:135
static void toString(const Vector< t_dims, t_type > &value, String &string)
Definition StringStream.h:82
static void toDisplayString(const Vector< t_dims, t_type > &value, TranslatedString &string)
Definition StringStream.h:134
static void fromString(const String &string, Vertex< t_dims, t_type, t_vector_type > &value)
Definition StringStream.h:183
static void toString(const Vertex< t_dims, t_type, t_vector_type > &value, String &string)
Definition StringStream.h:178
static const char * getValidRegex()
Definition StringStream.h:188
static void toDisplayString(const Vertex< t_dims, t_type, t_vector_type > &value, TranslatedString &string)
Definition StringStream.h:187
Definition StringStream.h:62
static void toString(const t_type &value, String &string)
static void fromString(const String &string, t_type &value)
static const char * getValidRegex()
static void toDisplayString(const t_type &value, TranslatedString &string)
Represents a timestamp with utilities for manipulation and conversion.
Definition Time.h:54
Definition TimeSpan.h:40
Definition TranslatedString.h:9
Definition TypeInfo.h:39
Definition StringStream.h:56
Definition UUID.h:66
An element of a vector space. An element of the real coordinate space Rn Basis vector,...
Definition Vector.hpp:62
A vertex.
Definition Vertex.hpp:54
Definition XYZColor.h:50
Definition ACIColor.h:37
@ MIN
Definition BaseValues.hpp:226
@ MAX
Definition BaseValues.hpp:227
InterpolationValues
Values that represent interpolation functions. Useful in large or complicated geological or time.
Definition BaseValues.hpp:255
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:98
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:120
Definition BaseValues.hpp:272
Definition Font.h:41
Information about the object.
Definition ObjectInfo.h:56