NDEVR
API Documentation
StringStream.h
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/BufferBase.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;
48 class TranslatedString;
49 class StringView;
50 typedef PrimitiveAlignedBuffer<StringView, sizeof(char*) == 4 ? 8 : 16> StringViewBuffer;
54 class NDEVR_BASE_API StringSplitter
55 {
56 public:
62 static const char* begin(const StringView& s);
68 static const char* end(const StringView& s);
75 static StringViewBuffer split(const StringView& s, char split);
76 };
77
80 class NDEVR_BASE_API TypeInfoRegex
81 {
82 public:
88 static const char* ValidRegex(const TypeInfo& info);
89 };
90
252 template<class t_type>
254 {
255 public:
260 static void toString(const t_type& value, StringAllocatingView& string);
261
267 static void toDisplayString(const t_type& value, TranslatedString& string);
268
273 static void fromString(const StringView& string, t_type& value);
274
279 static const char* getValidRegex();
280 };
281
284 template<>
285 class NDEVR_BASE_API StringStream<String>
286 {
287 public:
293 static void toString(const String& value, StringAllocatingView& string);
299 static void toDisplayString(const String& value, TranslatedString& string);
305 static void fromString(const StringView& string, String& value);
310 static const char* getValidRegex();
311 };
312
315 template<>
316 class NDEVR_BASE_API StringStream<StringView>
317 {
318 public:
324 static void toString(const StringView& value, StringAllocatingView& string);
330 static void toDisplayString(const StringView& value, TranslatedString& string);
336 static void fromString(const StringView& string, StringView& value);
341 static const char* getValidRegex();
342 };
343
346 template<>
347 class NDEVR_BASE_API StringStream<StringAllocatingView>
348 {
349 public:
355 static void toString(const StringAllocatingView& value, StringAllocatingView& string);
361 static void toDisplayString(const StringAllocatingView& value, TranslatedString& string);
367 static void fromString(const StringView& string, StringAllocatingView& value);
372 static const char* getValidRegex();
373 };
374
377 template<uint01 t_dims, class t_type>
378 class StringStream<Vector<t_dims, t_type>>
379 {
380 public:
386 static void toString(const Vector<t_dims, t_type>& value, StringAllocatingView& string)
387 {
388 StringStream<t_type>::toString(value[0], string);
389 for (uint01 dim = 1; dim < t_dims; ++dim)
390 {
391 StringStream<char>::toString(',', string);
392 StringStream<t_type>::toString(value[dim], string);
393 }
394 }
395
401 static void fromString(const StringView& string, Vector<t_dims, t_type>& value)
402 {
403 if constexpr (ObjectInfo<t_type>::Number)
404 {
405 const char* iter = StringSplitter::begin(string);
406 const char* end = StringSplitter::end(string);
407 for (uint01 dim = 0; dim < t_dims; ++dim)
408 {
409 value[dim] = NumberParser::parse<t_type>(iter, &iter);
410 for (; iter < end; iter++)
411 {
412 if (*iter == ',')
413 break;
414 }
415 if (iter == end)
416 {
417 ++dim;
418 for (; dim < t_dims; ++dim)
419 {
420 value[dim] = Constant<t_type>::Invalid;
421 }
422 return;
423 }
424 iter++;//skip over ,
425 }
426 }
427 else
428 {
429 StringViewBuffer parts = StringSplitter::split(string, ',');
430 for (uint01 dim = 0; dim < t_dims; ++dim)
431 {
432 if (parts.size() > dim)
433 {
434 t_type val = value[dim];
435 StringStream<t_type>::fromString(parts[dim], val);
436 value[dim] = val;
437 }
438 else
439 value[dim] = Constant<t_type>::Invalid;
440 }
441 }
442 }
443
447 static const char* getValidRegex()
448 {
449 return ".*";
450 };
451 };
452
453
457 template<uint01 t_dims, class t_type>
458 class StringStream<Bounds<t_dims, t_type>>
459 {
460 public:
466 static void toString(const Bounds<t_dims, t_type>& value, StringAllocatingView& string)
467 {
469 StringStream<char>::toString('^', string);
471 }
472
478 static void fromString(const StringView& string, Bounds<t_dims, t_type>& value)
479 {
480 StringViewBuffer parts = StringSplitter::split(string, '^');
481 if (parts.size() < 2)
482 {
483 value = Constant<Bounds<t_dims, t_type>>::Invalid;
484 }
485 else
486 {
489 }
490
491 }
492
496 static const char* getValidRegex()
497 {
498 return ".*";
499 };
500 };
501
505 template<uint01 t_dims, class t_type, class t_vector_type>
506 class StringStream<Vertex<t_dims, t_type, t_vector_type>>
507 {
508 public:
515 {
517 }
518
525 {
527 }
528
532 static const char* getValidRegex()
533 {
534 return ".*";
535 };
536 };
537
540 template<uint01 t_dims, class t_type, class t_vector_type>
541 class StringStream<Ray<t_dims, t_type, t_vector_type>>
542 {
543 public:
549 static void toString(const Ray<t_dims, t_type, t_vector_type>& value, StringAllocatingView& string)
550 {
552 }
553
559 static void fromString(const StringView& string, Ray<t_dims, t_type, t_vector_type>& value)
560 {
562 }
563
567 static const char* getValidRegex()
568 {
569 return ".*";
570 };
571 };
572
575 template<class t_type, class t_memory_manager>
576 class StringStream<Buffer<t_type, t_memory_manager>>
577 {
578 public:
585 {
586 for (uint04 i = 0; i < value.size(); i++)
587 {
588 StringStream<t_type>::toString(value[i], string);
589 }
590 }
591
597 static void fromString(const StringView& string, Buffer<t_type, t_memory_manager>& value)
598 {
599 StringViewBuffer strings = StringSplitter::split(string, ',');
600 value.setSize(strings.size());
601 for (uint04 i = 0; i < value.size(); i++)
602 {
603 StringStream<t_type>::fromString(strings[i], value[i]);
604 }
605 }
606
610 static const char* getValidRegex()
611 {
612 return ".*";
613 };
614 };
615
616 /*template<typename t_type, typename std::enable_if<std::is_enum<t_type>::value>::type>
617 class StringStream<t_type>
618 {
619 public:
620 static void toString(const t_type& value, StringAllocatingView& string)
621 {
622 StringStream<sint04>::toString(value, string);
623 }
624 static void fromString(const StringAllocatingView& string, t_type& value)
625 {
626 StringStream<sint04>::fromString(string, value);
627 }
628
629 static const char* getValidRegex()
630 {
631 return StringStream<sint04>::getValidRegex();
632 };
633 };*/
638 template<class t_type, uint01 t_row_dims, uint01 t_col_dims>
639 class StringStream<Matrix<t_type, t_row_dims, t_col_dims>>
640 {
641 public:
648 {
649 for (uint01 col = 0; col < t_col_dims; ++col)
650 {
651 StringStream<t_type>::toString(value[col][0], string);
652 for (uint01 row = 1; row < t_row_dims; ++row)
653 {
654 StringStream<char>::toString(',', string);
655 StringStream<t_type>::toString(value[col][row], string);
656 }
657 StringStream<char>::toString(';', string);
658 }
659 }
660
667 {
668 StringViewBuffer columns = StringSplitter::split(string, ';');
669 for (uint01 col = 0; col < t_col_dims; ++col)
670 {
671 if (col < columns.size())
672 {
673 StringViewBuffer rows = StringSplitter::split(columns[col], ',');
674 for (uint01 row = 0; row < t_row_dims; ++row)
675 {
676 if (row < rows.size())
677 StringStream<t_type>::fromString(rows[row], value[col][row]);
678 else
679 value[col][row] = Constant<t_type>::Invalid;
680 }
681 }
682 else
683 {
684 for (uint01 row = 0; row < t_row_dims; ++row)
685 {
686 value[col][row] = Constant<t_type>::Invalid;
687 }
688 }
689 }
690 }
691
695 static const char* getValidRegex()
696 {
697 return ".*";
698 };
699 };
700 template class NDEVR_BASE_API StringStream<bool>;
701 template class NDEVR_BASE_API StringStream<char>;
702 template class NDEVR_BASE_API StringStream<wchar>;
703 template class NDEVR_BASE_API StringStream<sint01>;
704 template class NDEVR_BASE_API StringStream<sint02>;
705 template class NDEVR_BASE_API StringStream<sint04>;
706 template class NDEVR_BASE_API StringStream<sint08>;
707 template class NDEVR_BASE_API StringStream<uint01>;
708 template class NDEVR_BASE_API StringStream<uint02>;
709 template class NDEVR_BASE_API StringStream<uint04>;
710 template class NDEVR_BASE_API StringStream<uint08>;
711 template class NDEVR_BASE_API StringStream<fltp04>;
712 template class NDEVR_BASE_API StringStream<fltp08>;
713 class BitReference;
714 template class NDEVR_BASE_API StringStream<BitReference>;
716 template class NDEVR_BASE_API StringStream<InterpolationValues>;
717
718 template class NDEVR_BASE_API StringStream<char const*>;
719 template class NDEVR_BASE_API StringStream<char*>;
720 template class NDEVR_BASE_API StringStream<wchar const*>;
721 template class NDEVR_BASE_API StringStream<wchar*>;
722 class BitFlag;
723 template class NDEVR_BASE_API StringStream<BitFlag>;
724 class Font;
725 template class NDEVR_BASE_API StringStream<Font>;
726 class RGBColor;
727 template class NDEVR_BASE_API StringStream<RGBColor>;
728 class ACIColor;
729 template class NDEVR_BASE_API StringStream<ACIColor>;
730 class XYZColor;
731 template class NDEVR_BASE_API StringStream<XYZColor>;
732 class LABColor;
733 template class NDEVR_BASE_API StringStream<LABColor>;
734 class HSLColor;
735 template class NDEVR_BASE_API StringStream<HSLColor>;
736 class HSBColor;
737 template class NDEVR_BASE_API StringStream<HSBColor>;
738 class Time;
739 template class NDEVR_BASE_API StringStream<Time>;
740 class TimeSpan;
741 template class NDEVR_BASE_API StringStream<TimeSpan>;
742 class UUID;
743 template class NDEVR_BASE_API StringStream<UUID>;
744 template<class t_type>
745 class Angle;
746 template class NDEVR_BASE_API StringStream<Angle<sint04>>;
747 template class NDEVR_BASE_API StringStream<Angle<fltp08>>;
748 class File;
749 template class NDEVR_BASE_API StringStream<File>;
750 class TranslatedString;
751 template class NDEVR_BASE_API StringStream<TranslatedString>;
752
753 template class NDEVR_BASE_API StringStream<std::string>;
754 template class NDEVR_BASE_API StringStream<std::wstring>;
755}
A specification of upper and lower bounds in N-dimensions.
Definition Bounds.hpp:54
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
Templated logic for doing matrix multiplication.
Definition Matrix.hpp:182
This class is like a string view, but may optionally store the data internally Useful if the return t...
Definition String.h:1278
Logic for splitting a string into two.
static StringViewBuffer split(const StringView &s, char split)
Splits a string into parts using the given delimiter character.
static const char * begin(const StringView &s)
Returns a pointer to the beginning of the string data.
static const char * end(const StringView &s)
Returns a pointer to the end of the string data.
static const char * getValidRegex()
Returns a regex pattern that validates Bounds input.
static void toString(const Bounds< t_dims, t_type > &value, StringAllocatingView &string)
Converts a Bounds to a string with min and max vectors separated by '^'.
static void fromString(const StringView &string, Bounds< t_dims, t_type > &value)
Parses a Bounds from a '^'-separated string of min and max vectors.
static void toString(const Buffer< t_type, t_memory_manager > &value, StringAllocatingView &string)
Converts a Buffer to a string by concatenating the string form of each element.
static const char * getValidRegex()
Returns a regex pattern that validates Buffer input.
static void fromString(const StringView &string, Buffer< t_type, t_memory_manager > &value)
Parses a Buffer from a comma-separated string, populating each element.
static void toString(const Matrix< t_type, t_row_dims, t_col_dims > &value, StringAllocatingView &string)
Converts a Matrix to a string with ',' separating row values and ';' separating columns.
static void fromString(const StringView &string, Matrix< t_type, t_row_dims, t_col_dims > &value)
Parses a Matrix from a string with ';'-separated columns and ','-separated row values.
static const char * getValidRegex()
Returns a regex pattern that validates Matrix input.
static void fromString(const StringView &string, Ray< t_dims, t_type, t_vector_type > &value)
Parses a Ray from a string by delegating to its vector type.
static void toString(const Ray< t_dims, t_type, t_vector_type > &value, StringAllocatingView &string)
Converts a Ray to its string representation by delegating to its vector type.
static const char * getValidRegex()
Returns a regex pattern that validates Ray input.
static const char * getValidRegex()
Returns a regex pattern that validates StringAllocatingView input.
static void toDisplayString(const StringAllocatingView &value, TranslatedString &string)
Converts a StringAllocatingView to a user-facing translated string.
static void fromString(const StringView &string, StringAllocatingView &value)
Parses a StringAllocatingView from a string view.
static void toString(const StringAllocatingView &value, StringAllocatingView &string)
Converts a StringAllocatingView to its string representation.
static void toDisplayString(const StringView &value, TranslatedString &string)
Converts a StringView to a user-facing translated string.
static void toString(const StringView &value, StringAllocatingView &string)
Converts a StringView to its string representation.
static const char * getValidRegex()
Returns a regex pattern that validates StringView input.
static void fromString(const StringView &string, StringView &value)
Parses a StringView from another string view.
static void toString(const String &value, StringAllocatingView &string)
Converts a String to its string representation.
static void fromString(const StringView &string, String &value)
Parses a String from a string view.
static const char * getValidRegex()
Returns a regex pattern that validates String input.
static void toDisplayString(const String &value, TranslatedString &string)
Converts a String to a user-facing translated string.
static const char * getValidRegex()
Returns a regex pattern that validates Vector input.
static void fromString(const StringView &string, Vector< t_dims, t_type > &value)
Parses a Vector from a comma-separated string representation.
static void toString(const Vector< t_dims, t_type > &value, StringAllocatingView &string)
Converts a Vector to a comma-separated string representation.
static void fromString(const StringView &string, Vertex< t_dims, t_type, t_vector_type > &value)
Parses a Vertex from a string by delegating to its vector type.
static const char * getValidRegex()
Returns a regex pattern that validates Vertex input.
static void toString(const Vertex< t_dims, t_type, t_vector_type > &value, StringAllocatingView &string)
Converts a Vertex to its string representation by delegating to its vector type.
Logic for reading or writing to a string or a user friendly, TranslatedString.
static void fromString(const StringView &string, t_type &value)
Logic for converting an object from an NDEVR API String allowing it to be used automatically with get...
static const char * getValidRegex()
Optionally specified to allow the software to do a check on user or file input to ensure that fromStr...
static void toDisplayString(const t_type &value, TranslatedString &string)
Logic for converting an object to an NDEVR API translated, user facing string.
static void toString(const t_type &value, StringAllocatingView &string)
Logic for converting an object to an NDEVR API String allowing it to be used automatically with the S...
The core String View class for the NDEVR API.
Definition StringView.h:58
The core String class for the NDEVR API.
Definition String.h:95
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
Logic for creating a regex for a given type of data.
static const char * ValidRegex(const TypeInfo &info)
Returns a valid regex string for the given type info.
Stores information about a type, relevant for certain templated functions.
Definition TypeInfo.h:43
A fixed-size array with N dimensions used as the basis for geometric and mathematical types.
Definition Vector.hpp:62
A point in N-dimensional space, used primarily for spatial location information.
Definition Vertex.hpp:44
The primary namespace for the NDEVR SDK.
@ BitFlag
Per-vertex bit flags (selected, hidden, etc.).
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
InterpolationValues
Values that represent interpolation functions.
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Defines for a given type (such as sint04, fltp08, UUID, etc) a maximum, minimum, and reserved 'invali...
Information about the object.
Definition ObjectInfo.h:55