4#include "Stroika/Foundation/StroikaPreComp.h"
10#include "Stroika/Foundation/Containers/Mapping.h"
11#include "Stroika/Foundation/DataExchange/ObjectVariantMapper.h"
19#include "Stroika/Foundation/Streams/MemoryStream.h"
21#include "ObjectVariantMapper.h"
32 void SimpleGettingStarted_ ()
37 struct MyType2Serialize1_ {
41 bool operator== (
const MyType2Serialize1_& rhs)
const =
default;
48 mapper.
AddClass<MyType2Serialize1_> ({
49 {
"Enabled"sv, &MyType2Serialize1_::fEnabled},
53 MyType2Serialize1_ tmp;
77 void UseObjectVariantMapperTry2_ ()
82 struct SharedContactsConfig_ {
84 optional<DateTime> fLastSynchronizedAt;
88 bool operator== (
const SharedContactsConfig_& rhs)
const =
default;
95 sb <<
" Enabled: "sv << fEnabled <<
", "sv;
96 sb <<
" Last-Synchronized-At: "sv << fLastSynchronizedAt <<
", "sv;
97 sb <<
" This-PHRs-ID-To-Shared-Contact-ID: "sv << fThisPHRsIDToSharedContactID;
109 mapper.
AddClass<SharedContactsConfig_> ({
110 {
"Enabled"sv, &SharedContactsConfig_::fEnabled},
111 {
"Last-Synchronized-At"sv, &SharedContactsConfig_::fLastSynchronizedAt},
112 {
"This-HR-ContactID-To-SharedContactID-Map"sv, &SharedContactsConfig_::fThisPHRsIDToSharedContactID},
116 SharedContactsConfig_ tmp;
118 bool newEnabled =
true;
119 tmp.fEnabled = newEnabled;
120 tmp.fThisPHRsIDToSharedContactID.Add (
"A"sv,
"B"sv);
121 tmp.fLastSynchronizedAt = DateTime{1998y / Time::April / 11d,
Time::TimeOfDay::Parse (
"3pm"sv, locale::classic ())};
136 constexpr bool kWrite2FileAsWell_ =
true;
137 if (kWrite2FileAsWell_) {
139 IO::FileSystem::FileOutputStream::Ptr tmpFileStream =
149 Assert (tmp2 == tmp);
157 Assert (tmp2 == tmp);
162 void GeneratingReadOnlyFieldsTry3_ ()
167 struct MyType2Serialize1_ {
168 bool fEnabled{
false};
175 mapper.
AddClass<MyType2Serialize1_> ({
176 {
"Enabled"sv, &MyType2Serialize1_::fEnabled},
184 DbgTrace (
"vv = {}"_f, Characters::ToString (vv));
190 using namespace Characters;
195 MyType2Serialize1_ tmp;
197 trySerializing (mapper, tmp);
200 mapper.
AddClass<MyType2Serialize1_> (
202 {
"Enabled"sv, &MyType2Serialize1_::fEnabled},
209 trySerializing (mapper, tmp);
213void Samples::Serialization::ObjectVariantMapper::RunDemo ()
215 SimpleGettingStarted_ ();
216 UseObjectVariantMapperTry2_ ();
217 GeneratingReadOnlyFieldsTry3_ ();
Similar to String, but intended to more efficiently construct a String. Mutable type (String is large...
String is like std::u32string, except it is much easier to use, often much more space efficient,...
nonvirtual String ReplaceAll(const RegularExpression ®Ex, const String &with) const
nonvirtual CONTAINER_OF_Key_T As() const
nonvirtual bool Add(ArgByValueType< key_type > key, ArgByValueType< mapped_type > newElt, AddReplaceMode addReplaceMode=AddReplaceMode::eAddReplaces)
ObjectVariantMapper can be used to map C++ types to and from variant-union types, which can be transp...
nonvirtual void AddClass(const Traversal::Iterable< StructFieldInfo > &fieldDescriptions, const ClassMapperOptions< CLASS > &mapperOptions={})
nonvirtual VariantValue FromObject(const T &from) const
nonvirtual T ToObject(const VariantValue &v) const
nonvirtual void Write(const VariantValue &v, const Streams::OutputStream::Ptr< byte > &out) const
Simple variant-value (case variant union) object, with (variant) basic types analogous to a value in ...
static TimeOfDay Parse(const String &rep, const locale &l=locale{})
String ToString(T &&t, ARGS... args)
Return a debug-friendly, display version of the argument: not guaranteed parsable or usable except fo...
filesystem::path GetTemporary()