Stroika Library 3.0d25
 
Loading...
Searching...
No Matches
Namespace.h
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2026. All rights reserved
3 */
4#ifndef _Stroika_Foundation_DataExchange_XML_Namespace_h_
5#define _Stroika_Foundation_DataExchange_XML_Namespace_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
10#include "Stroika/Foundation/Containers/Mapping.h"
11#include "Stroika/Foundation/Containers/Sequence.h"
14
15namespace Stroika::Foundation::DataExchange::XML {
16
17 using Characters::String;
18 using Containers::Mapping;
19 using Containers::Sequence;
20 using IO::Network::URI;
21
22 /**
23 * \brief used to specify default namespace, and any n: prefixes applicable to elements.
24 *
25 * \note default namespace does NOT apply to attributes, only element names...
26 */
28 public:
29 NamespaceDefinitions () = default;
30 NamespaceDefinitions (const optional<URI>& defaultNamespace, const Mapping<String, URI>& prefixedNamespaces = {});
31 NamespaceDefinitions (const Mapping<String, URI>& prefixedNamespaces);
32
33 public:
34 nonvirtual bool operator== (const NamespaceDefinitions&) const = default;
35
36 public:
37 nonvirtual optional<URI> GetDefaultNamespace () const;
38
39 public:
40 nonvirtual Mapping<String, URI> GetPrefixedNamespaces () const;
41
42 public:
43 /**
44 */
45 nonvirtual String ToString () const;
46
47 private:
48 optional<URI> fDefaultNamespace_;
49 Mapping<String, URI> fPrefixedNS_;
50 };
51
52 /**
53 * \brief An element's or attribute's name (local-name, not including a prefix), plus the namespace that name is in
54 *
55 * Reading <x:Why xmlns:x="urn:example:why"/> gives {.fName = "Why", .fNamespace = "urn:example:why"}
56 *
57 * \note similar to NamespaceDefinition, but this refers to elements which may or may not have an associated namespace.
58 *
59 * \note The one-argument CTOR takes anything a String can be built from, so that a literal can be passed wherever
60 * a NameWithNamespace is wanted - Append ("kid"sv) - which C++ allows only because that is a single
61 * user-defined conversion.
62 */
64 /**
65 * \brief The LOCAL name - "Why" for <x:Why>
66 */
68
69 /**
70 * \brief The namespace fName is in, however the document said so - nullopt for a name in no namespace
71 */
72 optional<URI> fNamespace;
73
74 template <Characters::IConvertibleToString NAME_TYPE>
75 NameWithNamespace (NAME_TYPE&& name);
76 NameWithNamespace (const optional<URI>& ns, const String& name);
77
78 bool operator== (const NameWithNamespace& rhs) const = default;
79#if qCompilerAndStdLib_explicitly_defaulted_threeway_warning_Buggy
80 DISABLE_COMPILER_CLANG_WARNING_START ("clang diagnostic ignored \"-Wdefaulted-function-deleted\"")
81#endif
82 auto operator<=> (const NameWithNamespace& rhs) const = default;
83#if qCompilerAndStdLib_explicitly_defaulted_threeway_warning_Buggy
84 DISABLE_COMPILER_CLANG_WARNING_END ("clang diagnostic ignored \"-Wdefaulted-function-deleted\"")
85#endif
86 /**
87 */
88 nonvirtual String ToString () const;
89 };
90
91 /**
92 * Common 'name/namespace' combo used internally in XML.
93 */
94 inline const NameWithNamespace kXMLNS{"http://www.w3.org/2000/xmlns/"sv, "xmlns"sv};
95
96 /**
97 * \brief NameWithNamespace::fNamespace for a name in NO namespace - which XML spells as an empty namespace name, and
98 * a document writes as xmlns="" where a default namespace would otherwise be in scope
99 *
100 * Distinct from kInheritNamespace, which these two are named apart from each other to make unmissable: an element
101 * saying nothing about its namespace takes its parent's, where one saying kNoNamespace takes none at all. Say which
102 * with these, never with the optional<URI> underneath - which of them is nullopt is only history (@see
103 * kInheritNamespace), and neither reading of a bare nullopt would be obvious.
104 *
105 * \par Example Usage
106 * \code
107 * // SOAP 1.1 has a Fault's own children unqualified (section 4.4), inside an Envelope that is not
108 * faultElt.Append (NameWithNamespace{kNoNamespace, "faultcode"sv}, "s:Client"sv);
109 * \endcode
110 *
111 * \note An ATTRIBUTE is in no namespace unless it carries a prefix, whatever default is in scope (XML Namespaces,
112 * section 6.2) - so for an attribute this is what an unprefixed name means anyway.
113 */
114 inline const optional<IO::Network::URI> kNoNamespace{IO::Network::URI{}};
115
116 /**
117 * \brief NameWithNamespace::fNamespace for a name in whatever namespace the element it is created under is in - the
118 * default, and what a name constructed without a namespace means
119 *
120 * Unlike kNoNamespace this is not an XML notion at all: a document only ever says a namespace or none. It is a
121 * convenience for BUILDING one, most of whose elements are in the same namespace as their parent, and it is nullopt
122 * only because that is what every name built without a namespace has always meant.
123 */
124 inline const optional<IO::Network::URI> kInheritNamespace{};
125
126}
127
128/*
129 ********************************************************************************
130 ***************************** Implementation Details ***************************
131 ********************************************************************************
132 */
133#include "Namespace.inl"
134
135#endif /*_Stroika_Foundation_DataExchange_XML_Namespace_h_*/
String is like std::u32string, except it is much easier to use, often much more space efficient,...
Definition String.h:201
A Mapping uniquely associates two elements: a key and a value (use Assocation to allow multiple value...
An element's or attribute's name (local-name, not including a prefix), plus the namespace that name i...
Definition Namespace.h:63
String fName
The LOCAL name - "Why" for <x:Why>
Definition Namespace.h:67
optional< URI > fNamespace
The namespace fName is in, however the document said so - nullopt for a name in no namespace.
Definition Namespace.h:72
used to specify default namespace, and any n: prefixes applicable to elements.
Definition Namespace.h:27