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/stringatom.h"
17#include "util/dictionary.h"
18#include "io/uri.h"
19
20//------------------------------------------------------------------------------
21namespace IO
22{
23class URN
24{
25public:
27 URN();
29 explicit URN(const Util::String& s);
31 explicit URN(const char* s);
33 explicit URN(const char* nid, const Util::String& nss);
35 explicit URN(const char* nid, const char* nss);
37 URN(const URN& rhs);
39 void operator=(const URN& rhs);
41 bool operator==(const URN& rhs) const;
43 bool operator!=(const URN& rhs) const;
44
46 void Set(const Util::String& s);
48 const Util::String& AsString();
49
51 bool IsEmpty() const;
53 bool IsValid() const;
55 bool IsFolder() const;
57 void Clear();
59 void SetNamespace(const Util::String& s);
61 const Util::String& GetNamespace() const;
63 void SetSpecific(const Util::String& s);
65 const Util::String& GetSpecific() const;
67 void SetQuery(const Util::String& s);
69 const Util::String& GetQuery() const;
71 void SetFragment(const Util::String& s);
73 const Util::String& GetFragment() const;
75 void Build();
76private:
78 bool Split(const Util::String& s);
79
81 bool isEmpty;
82 bool isDirty;
88
89
90};
91
92//------------------------------------------------------------------------------
95inline
97 isEmpty(true),
98 isFolder(false)
99{
100 // empty
101}
102
103//------------------------------------------------------------------------------
106inline
108 isEmpty(true),
109 isFolder(false)
110{
111 bool validUrn = this->Split(s);
112}
113
114//------------------------------------------------------------------------------
117inline
118URN::URN(const char* s) :
119 isEmpty(true),
120 isFolder(false)
121{
122 bool validUrn = this->Split(s);
123 n_assert2(validUrn, s);
124}
125
126//------------------------------------------------------------------------------
129inline
130URN::URN(const char* nid, const Util::String& nss)
131{
132 this->isFolder = strlen(nid) == 0;
133 this->isEmpty = this->isFolder && nss.Length() == 0;
134 this->nid = nid;
135 this->nss = nss;
136 this->Build();
137}
138
139//------------------------------------------------------------------------------
142inline
143URN::URN(const char* nid, const char* nss)
144{
145 this->isFolder = strlen(nid) == 0;
146 this->isEmpty = this->isFolder && strlen(nss) == 0;
147 this->nid = nid;
148 this->nss = nss;
149 this->Build();
150}
151
152//------------------------------------------------------------------------------
155inline
156URN::URN(const URN& rhs) :
157 isEmpty(rhs.isEmpty),
158 isFolder(rhs.isFolder),
159 nid(rhs.nid),
160 nss(rhs.nss),
161 query(rhs.query),
162 fragment(rhs.fragment),
163 string(rhs.string)
164{
165 // empty
166}
167
168//------------------------------------------------------------------------------
171inline void
173{
174 this->isEmpty = rhs.isEmpty;
175 this->isFolder = rhs.isFolder;
176 this->nid = rhs.nid;
177 this->nss = rhs.nss;
178 this->query = rhs.query;
179 this->fragment = rhs.fragment;
180 this->string = rhs.string;
181}
182
183//------------------------------------------------------------------------------
186inline bool
187URN::operator==(const URN& rhs) const
188{
189 if (this->isEmpty && rhs.isEmpty)
190 {
191 return true;
192 }
193 return ((this->nid == rhs.nid) &&
194 (this->nss == rhs.nss) &&
195 (this->query == rhs.query) &&
196 (this->fragment == rhs.fragment));
197}
198
199//------------------------------------------------------------------------------
202inline bool
203URN::operator!=(const URN& rhs) const
204{
205 return !(*this == rhs);
206}
207
208//------------------------------------------------------------------------------
211inline bool
213{
214 return this->isEmpty;
215}
216
217//------------------------------------------------------------------------------
220inline bool
222{
223 return !this->isEmpty;
224}
225
226//------------------------------------------------------------------------------
229inline bool
231{
232 return this->isFolder;
233}
234
235//------------------------------------------------------------------------------
238inline void
240{
241 this->isEmpty = true;
242 this->nid.Clear();
243 this->nss.Clear();
244 this->query.Clear();
245 this->fragment.Clear();
246 this->string.Clear();
247}
248
249//------------------------------------------------------------------------------
252inline const Util::String&
254{
255 if (this->isDirty)
256 this->Build();
257 this->isDirty = false;
258 return this->string;
259}
260
261//------------------------------------------------------------------------------
264inline void
266{
267 this->Split(s);
268}
269
270//------------------------------------------------------------------------------
273inline void
275{
276 this->isEmpty = false;
277 this->isDirty = true;
278 this->nid = s;
279}
280
281//------------------------------------------------------------------------------
284inline const Util::String&
286{
287 return this->nid;
288}
289
290//------------------------------------------------------------------------------
293inline void
295{
296 this->isEmpty = false;
297 this->isDirty = true;
298 this->nss = s;
299}
300
301//------------------------------------------------------------------------------
304inline const Util::String&
306{
307 return this->nss;
308}
309
310//------------------------------------------------------------------------------
313inline void
315{
316 this->isEmpty = false;
317 this->isDirty = true;
318 this->query = s;
319}
320
321//------------------------------------------------------------------------------
324inline const Util::String&
326{
327 return this->query;
328}
329
330//------------------------------------------------------------------------------
333inline void
335{
336 this->isEmpty = false;
337 this->isDirty = true;
338 this->fragment = s;
339}
340
341//------------------------------------------------------------------------------
344inline const Util::String&
346{
347 return this->fragment;
348}
349
350} // namespace IO
351
352//------------------------------------------------------------------------------
355IO::URN operator ""_urn(const char* c, std::size_t s);
356
357//------------------------------------------------------------------------------
358
A URN (Uniform Resource Name) is a URI (Uniform Resource Identifier) that uses the "urn" scheme.
Definition urn.h:24
bool IsEmpty() const
return true if the URN is empty
Definition urn.h:212
void Set(const Util::String &s)
set complete URI string
Definition urn.h:265
bool Split(const Util::String &s)
split string into components
Definition urn.cc:33
bool isFolder
Definition urn.h:80
const Util::String & GetSpecific() const
get Specific component (can be empty)
Definition urn.h:305
void SetSpecific(const Util::String &s)
set Specific component
Definition urn.h:294
void SetFragment(const Util::String &s)
set fragment component
Definition urn.h:334
Util::String string
Definition urn.h:87
Util::String query
Definition urn.h:85
bool IsFolder() const
Returns true if the URN is a folder.
Definition urn.h:230
Util::String nss
Definition urn.h:84
void SetQuery(const Util::String &s)
set query component
Definition urn.h:314
Util::String nid
Definition urn.h:83
Util::String fragment
Definition urn.h:86
void Clear()
clear the URN
Definition urn.h:239
const Util::String & GetNamespace() const
get Namespace component
Definition urn.h:285
const Util::String & GetQuery() const
get query component (can be empty)
Definition urn.h:325
bool IsValid() const
return true if the URN is not empty
Definition urn.h:221
void Build()
build string from components
Definition urn.cc:97
const Util::String & GetFragment() const
get fragment component (can be empty)
Definition urn.h:345
const Util::String & AsString()
return as concatenated string
Definition urn.h:253
void SetNamespace(const Util::String &s)
set Namespace component
Definition urn.h:274
bool operator!=(const URN &rhs) const
inequality operator
Definition urn.h:203
URN()
default constructor
Definition urn.h:96
void operator=(const URN &rhs)
assignmnent operator
Definition urn.h:172
bool isDirty
Definition urn.h:82
bool operator==(const URN &rhs) const
equality operator
Definition urn.h:187
bool isEmpty
Definition urn.h:81
Set()
default constructor
Definition set.h:79
Nebula's universal string class.
Definition string.h:50
void Clear()
clear the string
Definition string.h:701
SizeT Length() const
return length of string
Definition string.h:692
#define n_assert2(exp, msg)
Definition debug.h:59
Instances of wrapped stream classes.
Definition multiplayerfeatureunit.cc:324