Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
Variant/Reader.inl
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#include "Stroika/Foundation/Streams/TextToBinary.h"
5
6namespace Stroika::Foundation::DataExchange::Variant {
7
8 /*
9 ********************************************************************************
10 ********************* Variant::Reader::_Rep_Cloner *****************************
11 ********************************************************************************
12 */
13 inline Reader::_SharedPtrIRep Reader::_Rep_Cloner::operator() (const _IRep& t) const
14 {
15 return t.Clone ();
16 }
17
18 /*
19 ********************************************************************************
20 ******************************* Variant::Reader ********************************
21 ********************************************************************************
22 */
23 inline Reader::Reader (const shared_ptr<_IRep>& rep)
24 : fRep_{rep}
25 {
26 RequireNotNull (rep);
27 }
28 inline optional<filesystem::path> Reader::GetDefaultFileSuffix () const
29 {
30 AssertNotNull (fRep_);
31 return fRep_->GetDefaultFileSuffix ();
32 }
33 inline VariantValue Reader::Read (const Streams::InputStream::Ptr<byte>& in)
34 {
35 AssertNotNull (fRep_);
36 return fRep_->Read (in);
37 }
38 inline VariantValue Reader::Read (const Streams::InputStream::Ptr<Characters::Character>& in)
39 {
40 AssertNotNull (fRep_);
41 return fRep_->Read (in);
42 }
43 inline VariantValue Variant::Reader::Read (const Traversal::Iterable<Characters::Character>& in)
44 {
45 return Read (_ToCharacterReader (in));
46 }
47 inline VariantValue Variant::Reader::Read (istream& in)
48 {
49 return Read (_ToByteReader (in));
50 }
51 inline VariantValue Variant::Reader::Read (wistream& in)
52 {
53 return Read (_ToCharacterReader (in));
54 }
55 inline Reader::_IRep& Reader::_GetRep ()
56 {
57 AssertNotNull (fRep_);
58 EnsureNotNull (fRep_.rwget ());
59 return *fRep_.rwget ();
60 }
61 inline const Reader::_IRep& Reader::_GetRep () const
62 {
63 EnsureNotNull (fRep_.cget ());
64 return *fRep_.cget ();
65 }
71 {
72 return Streams::TextToBinary::Reader::New (in);
73 }
78
79}
#define AssertNotNull(p)
Definition Assertions.h:333
#define EnsureNotNull(p)
Definition Assertions.h:340
#define RequireNotNull(p)
Definition Assertions.h:347
static Streams::InputStream::Ptr< byte > _ToByteReader(const Streams::InputStream::Ptr< byte > &in)
simple helper so subclasses can more easily provide varied Read overloads
static Streams::InputStream::Ptr< Characters::Character > _ToCharacterReader(const Streams::InputStream::Ptr< Characters::Character > &in)
simple helper so subclasses can more easily provide varied Read overloads
Simple variant-value (case variant union) object, with (variant) basic types analogous to a value in ...
nonvirtual const element_type * cget() const noexcept
InputStream<>::Ptr is Smart pointer (with abstract Rep) class defining the interface to reading from ...
Iterable<T> is a base class for containers which easily produce an Iterator<T> to traverse them.
Definition Iterable.h:237