Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
Resource.h
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#ifndef _Stroika_Foundation_DataExchange_XML_Resource_h_
5#define _Stroika_Foundation_DataExchange_XML_Resource_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
10#include "Stroika/Foundation/Containers/Sequence.h"
13
14namespace Stroika::Foundation::DataExchange::XML::Resource {
15
16 using Characters::String;
17 using Containers::Sequence;
18 using IO::Network::URI;
19 using Traversal::Iterable;
20
21 /**
22 * This is a 'name' of something that can be #included, or referred to from a DTD, Schema etc. Typically think
23 * of this like a 'URL'.
24 */
25 struct Name {
26 optional<URI> fNamespace;
27 optional<String> fPublicID;
28 optional<String> fSystemID;
29
30 bool operator== (const Name&) const = default;
31#if qCompilerAndStdLib_explicitly_defaulted_threeway_warning_Buggy
32 DISABLE_COMPILER_CLANG_WARNING_START ("clang diagnostic ignored \"-Wdefaulted-function-deleted\"")
33#endif
34 auto operator<=> (const Name&) const = default;
35#if qCompilerAndStdLib_explicitly_defaulted_threeway_warning_Buggy
36 DISABLE_COMPILER_CLANG_WARNING_END ("clang diagnostic ignored \"-Wdefaulted-function-deleted\"")
37#endif
38
39 /**
40 */
41 nonvirtual String ToString () const;
42 };
43
44 /**
45 * This is a resource which is the data associated with a name (to be looked up by the resolver, typically during a parse).
46 * Think of this as a file someplace, with a name, and some data in it.
47 */
48 struct Definition {
49 Name fName;
50 Memory::BLOB fData; // maybe add MIME:ContentType?
51 };
52
53 /**
54 */
55 struct IResolverRep {
56 virtual ~IResolverRep () = default;
57 /*
58 * return nullopt if not found
59 */
60 virtual optional<Definition> Lookup (const Name& n) const = 0;
61 };
62
63 /**
64 * 3 main kinds of resolvers:
65 * o NONE (very often you have all the data you need right in the initial parse call
66 * o in-memory (preloaded)
67 * o from external URLs (filesystem, or network).
68 */
70 public:
71 ResolverPtr () = default;
72 ResolverPtr (nullptr_t);
73 ResolverPtr (const shared_ptr<IResolverRep>& rep);
74
75 public:
76 bool operator== (const ResolverPtr&) const = default;
77
78 public:
79 nonvirtual optional<Definition> Lookup (const Name& n) const;
80
81 private:
82 shared_ptr<IResolverRep> fRep_;
83 };
84
85 namespace MemoryResolver {
86 /**
87 * To use in memory or static or preloaded data definitions for parsing xml resources.
88 * NOTE - this could be replaced with a resolver that loads resources from file, or from the network.
89 */
90 ResolverPtr New (const Iterable<Definition>& defs);
91 }
92
93}
94
95/*
96 ********************************************************************************
97 ***************************** Implementation Details ***************************
98 ********************************************************************************
99 */
100#include "Resource.inl"
101
102#endif /*_Stroika_Foundation_DataExchange_XML_Resource_h_*/
String is like std::u32string, except it is much easier to use, often much more space efficient,...
Definition String.h:201
Iterable<T> is a base class for containers which easily produce an Iterator<T> to traverse them.
Definition Iterable.h:237