4#include "Stroika/Foundation/StroikaPreComp.h"
6#include "Stroika/Foundation/DataExchange/XML/WriterUtils.h"
8#include "Stroika/Foundation/Streams/TextToBinary.h"
17using namespace Stroika::Foundation::DataExchange::XML;
18using namespace Stroika::Foundation::Streams;
20using Memory::MakeSharedPtr;
25 for (
int i = 0; i < indentLevel; ++i) {
31 static const String kTrueLbl_ =
"true"sv;
32 static const String kFalseLbl_ =
"false"sv;
37 out.
Write (kTrueLbl_);
40 out.
Write (kFalseLbl_);
46 ::swprintf (buf, std::size (buf), L
"%lld", v);
52 ::swprintf (buf, std::size (buf), L
"%llu", v);
58 ::swprintf (buf, std::size (buf), L
"%Lf", v);
59 Assert (::wcslen (buf) >= 1);
61 for (
size_t i = ::wcslen (buf) - 1; buf[i] ==
'0'; --i) {
62 if (i != 0 and buf[i - 1] !=
'.') {
78 for (
auto i = v.begin (); i != v.end (); ++i) {
79 PrettyPrint_ (*i, out, indentLevel + 1);
82 Indent_ (out, indentLevel);
88 for (
auto i = v.begin (); i != v.end ();) {
89 Indent_ (out, indentLevel);
91 out.
Write (i->first.c_str ());
93 PrettyPrint_ (i->second, out, indentLevel + 1);
95 out.
Write (i->first.c_str ());
103 switch (v.GetType ()) {
104 case VariantValue::eNull:
106 case VariantValue::eBoolean:
107 PrettyPrint_ (v.
As<
bool> (), out);
109 case VariantValue::eDate:
110 PrettyPrint_ (v.
As<
String> (), out);
112 case VariantValue::eDateTime:
113 PrettyPrint_ (v.
As<
String> (), out);
115 case VariantValue::eInteger:
116 PrettyPrint_ (v.
As<
long long int> (), out);
118 case VariantValue::eUnsignedInteger:
119 PrettyPrint_ (v.
As<
unsigned long long int> (), out);
121 case VariantValue::eFloat:
122 PrettyPrint_ (v.
As<
long double> (), out);
124 case VariantValue::eString:
125 PrettyPrint_ (v.
As<
String> (), out);
127 case VariantValue::eMap:
128 PrettyPrint_ (v.
As<map<wstring, VariantValue>> (), out, indentLevel);
130 case VariantValue::eArray:
131 PrettyPrint_ (v.
As<vector<VariantValue>> (), out, indentLevel);
147 : fSerializationConfiguration_{config}
148 , fDocumentElementName_{config.GetDocumentElementName ().value_or (
String{})}
151 virtual _SharedPtrIRep Clone ()
const override
153 return MakeSharedPtr<Rep_> (fSerializationConfiguration_);
155 virtual optional<filesystem::path> GetDefaultFileSuffix ()
const override
161 if (fDocumentElementName_.empty ()) {
162 Require (v.GetType () == VariantValue::eMap);
167 v2.
Add (fDocumentElementName_, v);
173 if (fDocumentElementName_.empty ()) {
174 Require (v.GetType () == VariantValue::eMap);
175 PrettyPrint_ (v, out, 0);
179 v2.
Add (fDocumentElementName_, v);
185 return fSerializationConfiguration_;
189 fSerializationConfiguration_ = config;
190 fDocumentElementName_ = config.GetDocumentElementName ().value_or (
String{});
195 String fDocumentElementName_;
203Variant::XML::Writer::Rep_& Variant::XML::Writer::GetRep_ ()
206 return reinterpret_cast<Rep_&
> (inherited::_GetRep ());
209const Variant::XML::Writer::Rep_& Variant::XML::Writer::GetRep_ ()
const
212 return reinterpret_cast<const Rep_&
> (inherited::_GetRep ());
217 return GetRep_ ().GetConfiguration ();
222 GetRep_ ().SetConfiguration (config);
#define RequireNotReached()
#define EnsureMember(p, c)
auto MakeSharedPtr(ARGS_TYPE &&... args) -> shared_ptr< T >
same as make_shared, but if type T has block allocation, then use block allocation for the 'shared pa...
conditional_t< qStroika_Foundation_Memory_PreferBlockAllocation and andTrueCheck, BlockAllocationUseHelper< T >, Common::Empty > UseBlockAllocationIfAppropriate
Use this to enable block allocation for a particular class. Beware of subclassing.
String is like std::u32string, except it is much easier to use, often much more space efficient,...
nonvirtual bool Add(ArgByValueType< key_type > key, ArgByValueType< mapped_type > newElt, AddReplaceMode addReplaceMode=AddReplaceMode::eAddReplaces)
Simple variant-value (case variant union) object, with (variant) basic types analogous to a value in ...
nonvirtual RETURNTYPE As() const
OutputStream<>::Ptr is Smart pointer to a stream-based sink of data.
nonvirtual void Write(span< ELEMENT_TYPE2, EXTENT_2 > elts) const
Ptr New(const Streams::OutputStream::Ptr< byte > &src, const Characters::CodeCvt<> &char2OutputConverter)