Stroika Library 3.0d25
 
Loading...
Searching...
No Matches
Variant/Reader.h
Go to the documentation of this file.
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2026. 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
13
14/**
15 * \file
16 *
17 * \note Code-Status: <a href="Code-Status.md#Beta">Beta</a>
18 *
19 * \em Design Note:
20 * One question was whether or not to natively include support for istream sources or not.
21 * Its easy todo if not supported, by just using BinaryInputStreamFromIStreamAdapter. However,
22 * I decided it would be best to directly support it so typical users (who may not want to
23 * lookup those mapper classes) will just get the right results automagically.
24 *
25 * Also note - since there are no virtual functions involved in the call, the linker/optimizer
26 * can eliminate the code if this feature isn't used.
27 *
28 * This comports with a similar choice made in the String and Container classes (direct builtin
29 * first-class support for native STL objects where appropriate).
30 */
31
32namespace Stroika::Foundation::Memory {
33 class BLOB;
34}
35
36namespace Stroika::Foundation::DataExchange::Variant {
37
38 /**
39 * \brief abstract class specifying interface for readers that map a source like XML or JSON to a VariantValue objects
40 *
41 * **A Reader is configured when it is constructed, and immutable after**: what the subclass's constructor was given (its
42 * Options, say) is how it reads, and every method is const. To read differently, construct another Reader - that is
43 * cheap. Copies share one representation, never modified, so a Reader is cheap to copy - to store, to pass by value, to
44 * hand out from a factory.
45 *
46 * \note \em Thread-Safety <a href="Thread-Safety.md#C++-Standard-Thread-Safety">C++-Standard-Thread-Safety</a>
47 */
48 class Reader {
49 protected:
50 class _IRep;
51
52 protected:
53 Reader () = delete; // @todo may want to allow?
54
55 protected:
56 /**
57 * \pre rep != nullptr
58 */
59 explicit Reader (const shared_ptr<const _IRep>& rep);
60
61 public:
62 /**
63 */
64 nonvirtual optional<filesystem::path> GetDefaultFileSuffix () const;
65
66 public:
67 /**
68 */
69 nonvirtual VariantValue Read (const Streams::InputStream::Ptr<byte>& in) const;
70 nonvirtual VariantValue Read (const Streams::InputStream::Ptr<Characters::Character>& in) const;
71 nonvirtual VariantValue Read (const Traversal::Iterable<Characters::Character>& in) const;
72 nonvirtual VariantValue Read (istream& in) const;
73 nonvirtual VariantValue Read (wistream& in) const;
74
75 protected:
76 nonvirtual const _IRep& _ConstGetRep () const;
77
78 protected:
79 /**
80 * \brief simple helper so subclasses can more easily provide varied Read overloads
81 */
86
87 protected:
88 /**
89 * \brief simple helper so subclasses can more easily provide varied Read overloads
90 */
94
95 private:
96 shared_ptr<const _IRep> fRep_;
97 };
98
99 /**
100 */
101 class Reader::_IRep {
102 public:
103 virtual ~_IRep () = default;
104 virtual optional<filesystem::path> GetDefaultFileSuffix () const = 0;
105 virtual VariantValue Read (const Streams::InputStream::Ptr<byte>& in) const = 0;
106 virtual VariantValue Read (const Streams::InputStream::Ptr<Characters::Character>& in) const = 0;
107 };
108
109}
110
111/*
112 ********************************************************************************
113 ***************************** Implementation Details ***************************
114 ********************************************************************************
115 */
116#include "Reader.inl"
117
118#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:234