Nebula
Loading...
Searching...
No Matches
urn.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
14#include "core/types.h"
15#include "util/string.h"
16#include "util/dictionary.h"
17
18//------------------------------------------------------------------------------
19namespace IO
20{
21class URN
22{
23public:
25 URN();
27 URN(const Util::String& s);
29 URN(const char* s);
31 URN(const URN& rhs);
33 void operator=(const URN& rhs);
35 bool operator==(const URN& rhs) const;
37 bool operator!=(const URN& rhs) const;
38
40 void Set(const Util::String& s);
42 Util::String AsString() const;
43
45 bool IsEmpty() const;
47 bool IsValid() const;
49 void Clear();
51 void SetNamespace(const Util::String& s);
53 const Util::String& GetNamespace() const;
55 void SetSpecific(const Util::String& s);
57 const Util::String& GetSpecific() const;
59 void SetQuery(const Util::String& s);
61 const Util::String& GetQuery() const;
63 void SetFragment(const Util::String& s);
65 const Util::String& GetFragment() const;
66private:
68 bool Split(const Util::String& s);
70 Util::String Build() const;
71
72 bool isEmpty;
77};
78
79//------------------------------------------------------------------------------
82inline
84 isEmpty(true)
85{
86 // empty
87}
88
89//------------------------------------------------------------------------------
92inline
94 isEmpty(true)
95{
96 bool validUrn = this->Split(s);
97 n_assert2(validUrn, s.AsCharPtr());
98}
99
100//------------------------------------------------------------------------------
103inline
104URN::URN(const char* s) :
105 isEmpty(true)
106{
107 bool validUrn = this->Split(s);
108 n_assert2(validUrn, s);
109}
110
111//------------------------------------------------------------------------------
114inline
115URN::URN(const URN& rhs) :
116 isEmpty(rhs.isEmpty),
117 nid(rhs.nid),
118 nss(rhs.nss),
119 query(rhs.query),
120 fragment(rhs.fragment)
121{
122 // empty
123}
124
125//------------------------------------------------------------------------------
128inline
129void
131{
132 this->isEmpty = rhs.isEmpty;
133 this->nid = rhs.nid;
134 this->nss = rhs.nss;
135 this->query = rhs.query;
136 this->fragment = rhs.fragment;
137}
138
139//------------------------------------------------------------------------------
142inline
143bool
144URN::operator==(const URN& rhs) const
145{
146 if (this->isEmpty && rhs.isEmpty)
147 {
148 return true;
149 }
150 return ((this->nid == rhs.nid) &&
151 (this->nss == rhs.nss) &&
152 (this->query == rhs.query) &&
153 (this->fragment == rhs.fragment));
154}
155
156//------------------------------------------------------------------------------
159inline
160bool
161URN::operator!=(const URN& rhs) const
162{
163 return !(*this == rhs);
164}
165
166//------------------------------------------------------------------------------
169inline
170bool
172{
173 return this->isEmpty;
174}
175
176//------------------------------------------------------------------------------
179inline
180bool
182{
183 return !this->isEmpty;
184}
185
186//------------------------------------------------------------------------------
189inline
190void
192{
193 this->isEmpty = true;
194 this->nid.Clear();
195 this->nss.Clear();
196 this->query.Clear();
197 this->fragment.Clear();
198}
199
200//------------------------------------------------------------------------------
203inline
206{
207 return this->Build();
208}
209
210//------------------------------------------------------------------------------
213inline
214void
216{
217 this->Split(s);
218}
219
220//------------------------------------------------------------------------------
223inline
224void
226{
227 this->isEmpty = false;
228 this->nid = s;
229}
230
231//------------------------------------------------------------------------------
234inline
235const Util::String&
237{
238 return this->nid;
239}
240
241//------------------------------------------------------------------------------
244inline
245void
247{
248 this->isEmpty = false;
249 this->nss = s;
250}
251
252//------------------------------------------------------------------------------
255inline
256const Util::String&
258{
259 return this->nss;
260}
261
262//------------------------------------------------------------------------------
265inline
266void
268{
269 this->isEmpty = false;
270 this->query = s;
271}
272
273//------------------------------------------------------------------------------
276inline
277const Util::String&
279{
280 return this->query;
281}
282
283//------------------------------------------------------------------------------
286inline
287void
289{
290 this->isEmpty = false;
291 this->fragment = s;
292}
293
294//------------------------------------------------------------------------------
297inline
298const Util::String&
300{
301 return this->fragment;
302}
303
304} // namespace IO
305//------------------------------------------------------------------------------
308IO::URN operator ""_urn(const char* c, std::size_t s);
309
310//------------------------------------------------------------------------------
311
A URN (Uniform Resource Name) is a URI (Uniform Resource Identifier) that uses the "urn" scheme.
Definition urn.h:22
bool IsEmpty() const
return true if the URI is empty
Definition urn.h:171
void Set(const Util::String &s)
set complete URI string
Definition urn.h:215
bool Split(const Util::String &s)
split string into components
Definition urn.cc:32
const Util::String & GetSpecific() const
get Specific component (can be empty)
Definition urn.h:257
void SetSpecific(const Util::String &s)
set Specific component
Definition urn.h:246
void SetFragment(const Util::String &s)
set fragment component
Definition urn.h:288
Util::String query
Definition urn.h:75
Util::String nss
Definition urn.h:74
void SetQuery(const Util::String &s)
set query component
Definition urn.h:267
Util::String Build() const
build string from components
Definition urn.cc:106
Util::String nid
Definition urn.h:73
Util::String fragment
Definition urn.h:76
void Clear()
clear the URI
Definition urn.h:191
const Util::String & GetNamespace() const
get Namespace component
Definition urn.h:236
const Util::String & GetQuery() const
get query component (can be empty)
Definition urn.h:278
bool IsValid() const
return true if the URI is not empty
Definition urn.h:181
const Util::String & GetFragment() const
get fragment component (can be empty)
Definition urn.h:299
Util::String AsString() const
return as concatenated string
Definition urn.h:205
void SetNamespace(const Util::String &s)
set Namespace component
Definition urn.h:225
bool operator!=(const URN &rhs) const
inequality operator
Definition urn.h:161
URN()
default constructor
Definition urn.h:83
void operator=(const URN &rhs)
assignmnent operator
Definition urn.h:130
bool operator==(const URN &rhs) const
equality operator
Definition urn.h:144
bool isEmpty
Definition urn.h:72
#define n_assert2(exp, msg)
Definition debug.h:51
Instances of wrapped stream classes.
Definition multiplayerfeatureunit.cc:289
Nebula's universal string class.
Definition String.cs:8
const char * AsCharPtr() const
return contents as character pointer
Definition string.h:564