ALib C++ Library
Library Version: 2412 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
vmeta.cpp
1// #################################################################################################
2// ALib C++ Library
3//
4// Copyright 2013-2024 A-Worx GmbH, Germany
5// Published under 'Boost Software License' (a free software license, see LICENSE.txt)
6// #################################################################################################
8
9#if !DOXYGEN
10# include "alib/config/vmeta.hpp"
16#endif // !DOXYGEN
17
18namespace alib::config::detail {
19
20
21
22} // namespace [alib::config::detail]
23
24namespace alib::config {
25DOX_MARKER([DOX_ENUMS_RECORD_PARSER])
26void Declaration::Parse()
27{
28 enums::EnumRecordParser::Get( ERSerializable::EnumElementName ); // field from parent class
29 ERSerializable::MinimumRecognitionLength= 0; // omit reading, but fix to zero
30 enums::EnumRecordParser::Get( typeName , true ); // last field!
31}
32DOX_MARKER([DOX_ENUMS_RECORD_PARSER])
33}
34
35#if !DOXYGEN
36namespace alib::config::detail {
37
38void VMeta_Bool ::imPort(VDATA* data, Configuration& cfg, const StringEscaper& , const String& src ) { auto result= cfg.ParseBooleanToken(src); data->As<Bool>()= result.first; data->As<Bool>().TokenIndex= result.second; }
39void VMeta_integer ::imPort(VDATA* data, Configuration& cfg, const StringEscaper& , const String& src ) { data->As<integer>()= integer(Substring(src).TrimStart().ParseInt (0, &cfg.NumberFormat)); }
40void VMeta_float ::imPort(VDATA* data, Configuration& cfg, const StringEscaper& , const String& src ) { data->As<double >()= Substring(src).TrimStart().ParseFloat(0, &cfg.NumberFormat) ; }
41void VMeta_String ::imPort(VDATA* data, Configuration& , const StringEscaper& esc, const String& src ) { String2K buf; esc.Unescape(src, buf); data->As<AStringPA>().Reset(buf); }
42
43void VMeta_Bool ::exPort(VDATA* data, Configuration& cfg, const StringEscaper& esc, AString& dest) { String64 buf; esc.Escape(cfg.WriteBooleanToken( data->As<Bool>().Value, data->As<Bool>().TokenIndex, buf ), dest, A_CHAR("\0")); }
44void VMeta_integer ::exPort(VDATA* data, Configuration& , const StringEscaper& , AString& dest) { dest << data->As<integer>(); }
45void VMeta_float ::exPort(VDATA* data, Configuration& , const StringEscaper& , AString& dest) { dest << data->As<double >(); }
46void VMeta_String ::exPort(VDATA* data, Configuration& , const StringEscaper& esc, AString& dest) { esc.Escape(data->As<AStringPA>() , dest, A_CHAR("\0")); }
47void VMeta_Box ::exPort(VDATA* data, Configuration& , const StringEscaper& esc, AString& dest) { esc.Escape(String1K() << data->As<Box>(), dest, A_CHAR("\0")); }
48void VMeta_Box ::imPort(VDATA* data, Configuration& , const StringEscaper& esc, const String& src )
49{
50 Substring parser;
51 String2K buf;
52 esc.Unescape(src, buf );
53 parser= buf;
54
55 // try integral
56 {
57 integer val;
58 if(parser.ConsumeInt(val) && parser.Trim().IsEmpty())
59 {
60 data->As<Box>()= val;
61 return;
62 }
63 parser= src;
64 }
65
66 // try float
67 {
68 double val;
69 if(parser.ConsumeFloat(val) && parser.Trim().IsEmpty())
70 {
71 data->As<Box>()= val;
72 return;
73 }
74 parser= src;
75 }
76
77 // we just store the source string
78 data->As<Box>()= src;
79}
80
81namespace {
82void imPortStringVector(VDATA* data, const StringEscaper& esc, const String& src, const String& delimiter )
83{
85 StringVectorMA results(la);
86 esc.UnescapeTokens(results, src, delimiter);
87 auto& dataSA= data->As<StringVectorPA>();
88 dataSA.clear();
89 for( auto it : results )
90 {
91 Substring value= it;
92 value.ConsumeChar('\r');
93 value.ConsumeChar('\n');
94 value.ConsumeCharFromEnd('\n');
95 value.ConsumeCharFromEnd('\r');
96 dataSA.Add( value );
97 }
98}
99
100void exPortStringVector(VDATA* data, const StringEscaper& esc, AString& dest, const String& delimiter )
101{
102 auto& dataSA= data->As<StringVectorPA>();
103 if( !dataSA.empty())
104 for( auto it= dataSA.begin() ;; )
105 {
106 esc.Escape(*it, dest, delimiter);
107
108 if( ++it == dataSA.end() )
109 break;
110
111 dest << delimiter;
112 dest << NEW_LINE;
113 }
114}
115
116}
117void VMeta_StringVectorComma::imPort(VDATA* data, Configuration& , const StringEscaper& esc, const String& src )
118{
119 imPortStringVector(data, esc, src, A_CHAR(","));
120}
121
122void VMeta_StringVectorComma::exPort(VDATA* data, Configuration& , const StringEscaper& esc, AString& dest)
123{
124 exPortStringVector(data, esc, dest, A_CHAR(","));
125}
126
127void VMeta_StringVectorSemicolon::imPort(VDATA* data, Configuration&, const StringEscaper& esc, const String& src )
128{
129 imPortStringVector(data, esc, src, A_CHAR(";"));
130}
131
132void VMeta_StringVectorSemicolon::exPort(VDATA* data, Configuration&, const StringEscaper& esc, AString& dest)
133{
134 exPortStringVector(data, esc, dest,A_CHAR(";"));
135}
136
137} // namespace [alib::config]
138#endif // if !DOXYGEN
ALIB_API std::pair< bool, int8_t > ParseBooleanToken(const String &src)
ALIB_API double ParseFloat(integer startIdx=0, TNumberFormat< TChar > *numberFormat=nullptr, integer *newIdx=nullptr) const
TSubstring & TrimStart(const TCString< TChar > &whiteSpaces=TT_CStringConstants< TChar >::DefaultWhitespaces())
Definition substring.hpp:89
#define A_CHAR(STR)
LocalString< 64 > String64
Type alias name for TLocalString<character,64>.
config::Configuration Configuration
Type alias in namespace alib.
monomem::TLocalAllocator< 4 > LocalAllocator4K
Type alias in namespace alib. Allocates 4kB of stack memory.
strings::TAString< character, lang::HeapAllocator > AString
Type alias in namespace alib.
strings::util::TStringVector< character, PoolAllocator > StringVectorPA
Type alias in namespace alib.
strings::TSubstring< character > Substring
Type alias in namespace alib.
LocalString< 2048 > String2K
Type alias name for TLocalString<character,2048>.
constexpr CString NEW_LINE
A zero-terminated string containing the new-line character sequence.
Definition cstring.hpp:580
strings::TString< character > String
Type alias in namespace alib.
strings::util::StringEscaper StringEscaper
Type alias in namespace alib.
Definition escaper.hpp:206
LocalString< 1024 > String1K
Type alias name for TLocalString<character,1024>.
boxing::Box Box
Type alias in namespace alib.
strings::util::TStringVector< character, MonoAllocator > StringVectorMA
Type alias in namespace alib.
lang::integer integer
Type alias in namespace alib.
Definition integers.hpp:273
strings::TAString< character, PoolAllocator > AStringPA
Type alias in namespace alib.
Definition astringpa.hpp:45
static ALIB_API void Get(String &result, bool isLastField=false)