Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
Variant/Reader.h
Go to the documentation of this file.
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#ifndef _Stroika_Foundation_DataExchange_Variant_Reader_h_
5#define _Stroika_Foundation_DataExchange_Variant_Reader_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
9#include <istream>
10
14
15/**
16 * \file
17 *
18 * \note Code-Status: <a href="Code-Status.md#Beta">Beta</a>
19 *
20 * \em Design Note:
21 * One question was whether or not to natively include support for istream sources or not.
22 * Its easy todo if not supported, by just using BinaryInputStreamFromIStreamAdapter. However,
23 * I decided it would be best to directly support it so typical users (who may not want to
24 * lookup those mapper classes) will just get the right results automagically.
25 *
26 * Also note - since there are no virtual functions involved in the call, the linker/optimizer
27 * can eliminate the code if this feature isn't used.
28 *
29 * This comports with a similar choice made in the String and Container classes (direct builtin
30 * first-class support for native STL objects where appropriate).
31 */
32
33namespace Stroika::Foundation::Memory {
34 class BLOB;
35}
36
37namespace Stroika::Foundation::DataExchange::Variant {
38
39 /**
40 * \brief abstract class specifying interface for readers that map a source like XML or JSON to a VariantValue objects
41 */
42 class Reader {
43 protected:
44 class _IRep;
45
46 protected:
47 Reader () = delete; // @todo may want to allow?
48
49 protected:
50 /**
51 * \pre rep != nullptr
52 */
53 explicit Reader (const shared_ptr<_IRep>& rep);
54
55 public:
56 /**
57 */
58 nonvirtual optional<filesystem::path> GetDefaultFileSuffix () const;
59
60 public:
61 /**
62 */
63 nonvirtual VariantValue Read (const Streams::InputStream::Ptr<byte>& in);
66 nonvirtual VariantValue Read (istream& in);
67 nonvirtual VariantValue Read (wistream& in);
68
69 protected:
70 nonvirtual _IRep& _GetRep ();
71 nonvirtual const _IRep& _GetRep () const;
72
73 protected:
74 /**
75 * \brief simple helper so subclasses can more easily provide varied Read overloads
76 */
81
82 protected:
83 /**
84 * \brief simple helper so subclasses can more easily provide varied Read overloads
85 */
89
90 protected:
91 using _SharedPtrIRep = shared_ptr<_IRep>;
92
93 private:
94 struct _Rep_Cloner {
95 _SharedPtrIRep operator() (const _IRep& t) const;
96 };
98
99 private:
101 };
102
103 class Reader::_IRep {
104 public:
105 virtual ~_IRep () = default;
106 virtual _SharedPtrIRep Clone () const = 0;
107 virtual optional<filesystem::path> GetDefaultFileSuffix () const = 0;
108 virtual VariantValue Read (const Streams::InputStream::Ptr<byte>& in) = 0;
110 };
111
112}
113
114/*
115 ********************************************************************************
116 ***************************** Implementation Details ***************************
117 ********************************************************************************
118 */
119#include "Reader.inl"
120
121#endif /*_Stroika_Foundation_DataExchange_Variant_Reader_h_*/
abstract class specifying interface for readers that map a source like XML or JSON to a VariantValue ...
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 ...
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