Nebula
Toggle main menu visibility
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
//------------------------------------------------------------------------------
21
namespace
IO
22
{
23
class
URN
24
{
25
public
:
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
();
76
private
:
78
bool
Split
(
const
Util::String
& s);
79
80
bool
isFolder
;
81
bool
isEmpty
;
82
bool
isDirty
;
83
Util::String
nid
;
84
Util::String
nss
;
85
Util::String
query
;
86
Util::String
fragment
;
87
Util::String
string
;
88
89
90
};
91
92
//------------------------------------------------------------------------------
95
inline
96
URN::URN
() :
97
isEmpty
(true),
98
isFolder
(false)
99
{
100
// empty
101
}
102
103
//------------------------------------------------------------------------------
106
inline
107
URN::URN
(
const
Util::String
& s) :
108
isEmpty
(true),
109
isFolder
(false)
110
{
111
bool
validUrn = this->
Split
(s);
112
}
113
114
//------------------------------------------------------------------------------
117
inline
118
URN::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
//------------------------------------------------------------------------------
129
inline
130
URN::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
//------------------------------------------------------------------------------
142
inline
143
URN::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
//------------------------------------------------------------------------------
155
inline
156
URN::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
//------------------------------------------------------------------------------
171
inline
void
172
URN::operator=
(
const
URN
& rhs)
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
//------------------------------------------------------------------------------
186
inline
bool
187
URN::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
//------------------------------------------------------------------------------
202
inline
bool
203
URN::operator!=
(
const
URN
& rhs)
const
204
{
205
return
!(*
this
== rhs);
206
}
207
208
//------------------------------------------------------------------------------
211
inline
bool
212
URN::IsEmpty
()
const
213
{
214
return
this->
isEmpty
;
215
}
216
217
//------------------------------------------------------------------------------
220
inline
bool
221
URN::IsValid
()
const
222
{
223
return
!this->
isEmpty
;
224
}
225
226
//------------------------------------------------------------------------------
229
inline
bool
230
URN::IsFolder
()
const
231
{
232
return
this->
isFolder
;
233
}
234
235
//------------------------------------------------------------------------------
238
inline
void
239
URN::Clear
()
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
//------------------------------------------------------------------------------
252
inline
const
Util::String
&
253
URN::AsString
()
254
{
255
if
(this->
isDirty
)
256
this->
Build
();
257
this->
isDirty
=
false
;
258
return
this->
string
;
259
}
260
261
//------------------------------------------------------------------------------
264
inline
void
265
URN::Set
(
const
Util::String
& s)
266
{
267
this->
Split
(s);
268
}
269
270
//------------------------------------------------------------------------------
273
inline
void
274
URN::SetNamespace
(
const
Util::String
& s)
275
{
276
this->
isEmpty
=
false
;
277
this->
isDirty
=
true
;
278
this->
nid
= s;
279
}
280
281
//------------------------------------------------------------------------------
284
inline
const
Util::String
&
285
URN::GetNamespace
()
const
286
{
287
return
this->
nid
;
288
}
289
290
//------------------------------------------------------------------------------
293
inline
void
294
URN::SetSpecific
(
const
Util::String
& s)
295
{
296
this->
isEmpty
=
false
;
297
this->
isDirty
=
true
;
298
this->
nss
= s;
299
}
300
301
//------------------------------------------------------------------------------
304
inline
const
Util::String
&
305
URN::GetSpecific
()
const
306
{
307
return
this->
nss
;
308
}
309
310
//------------------------------------------------------------------------------
313
inline
void
314
URN::SetQuery
(
const
Util::String
& s)
315
{
316
this->
isEmpty
=
false
;
317
this->
isDirty
=
true
;
318
this->
query
= s;
319
}
320
321
//------------------------------------------------------------------------------
324
inline
const
Util::String
&
325
URN::GetQuery
()
const
326
{
327
return
this->
query
;
328
}
329
330
//------------------------------------------------------------------------------
333
inline
void
334
URN::SetFragment
(
const
Util::String
& s)
335
{
336
this->
isEmpty
=
false
;
337
this->
isDirty
=
true
;
338
this->
fragment
= s;
339
}
340
341
//------------------------------------------------------------------------------
344
inline
const
Util::String
&
345
URN::GetFragment
()
const
346
{
347
return
this->
fragment
;
348
}
349
350
}
// namespace IO
351
352
//------------------------------------------------------------------------------
355
IO::URN
operator
""
_urn(
const
char
* c, std::size_t s);
356
357
//------------------------------------------------------------------------------
358
IO::URN
A URN (Uniform Resource Name) is a URI (Uniform Resource Identifier) that uses the "urn" scheme.
Definition
urn.h:24
IO::URN::IsEmpty
bool IsEmpty() const
return true if the URN is empty
Definition
urn.h:212
IO::URN::Set
void Set(const Util::String &s)
set complete URI string
Definition
urn.h:265
IO::URN::Split
bool Split(const Util::String &s)
split string into components
Definition
urn.cc:33
IO::URN::isFolder
bool isFolder
Definition
urn.h:80
IO::URN::GetSpecific
const Util::String & GetSpecific() const
get Specific component (can be empty)
Definition
urn.h:305
IO::URN::SetSpecific
void SetSpecific(const Util::String &s)
set Specific component
Definition
urn.h:294
IO::URN::SetFragment
void SetFragment(const Util::String &s)
set fragment component
Definition
urn.h:334
IO::URN::string
Util::String string
Definition
urn.h:87
IO::URN::query
Util::String query
Definition
urn.h:85
IO::URN::IsFolder
bool IsFolder() const
Returns true if the URN is a folder.
Definition
urn.h:230
IO::URN::nss
Util::String nss
Definition
urn.h:84
IO::URN::SetQuery
void SetQuery(const Util::String &s)
set query component
Definition
urn.h:314
IO::URN::nid
Util::String nid
Definition
urn.h:83
IO::URN::fragment
Util::String fragment
Definition
urn.h:86
IO::URN::Clear
void Clear()
clear the URN
Definition
urn.h:239
IO::URN::GetNamespace
const Util::String & GetNamespace() const
get Namespace component
Definition
urn.h:285
IO::URN::GetQuery
const Util::String & GetQuery() const
get query component (can be empty)
Definition
urn.h:325
IO::URN::IsValid
bool IsValid() const
return true if the URN is not empty
Definition
urn.h:221
IO::URN::Build
void Build()
build string from components
Definition
urn.cc:97
IO::URN::GetFragment
const Util::String & GetFragment() const
get fragment component (can be empty)
Definition
urn.h:345
IO::URN::AsString
const Util::String & AsString()
return as concatenated string
Definition
urn.h:253
IO::URN::SetNamespace
void SetNamespace(const Util::String &s)
set Namespace component
Definition
urn.h:274
IO::URN::operator!=
bool operator!=(const URN &rhs) const
inequality operator
Definition
urn.h:203
IO::URN::URN
URN()
default constructor
Definition
urn.h:96
IO::URN::operator=
void operator=(const URN &rhs)
assignmnent operator
Definition
urn.h:172
IO::URN::isDirty
bool isDirty
Definition
urn.h:82
IO::URN::operator==
bool operator==(const URN &rhs) const
equality operator
Definition
urn.h:187
IO::URN::isEmpty
bool isEmpty
Definition
urn.h:81
Util::Set::Set
Set()
default constructor
Definition
set.h:79
Util::String
Nebula's universal string class.
Definition
string.h:50
Util::String::Clear
void Clear()
clear the string
Definition
string.h:701
Util::String::Length
SizeT Length() const
return length of string
Definition
string.h:692
n_assert2
#define n_assert2(exp, msg)
Definition
debug.h:59
dictionary.h
IO
Instances of wrapped stream classes.
Definition
multiplayerfeatureunit.cc:324
string.h
stringatom.h
types.h
uri.h
code
foundation
io
urn.h
Generated on
for Nebula. Dark theme by
Tilen Majerle
. All rights reserved.