blob: d589c89963dff6e32a3b6a9567071bd84713a820 [file] [log] [blame]
Jeff Thompson47eecfc2013-07-07 22:56:46 -07001/**
Jeff Thompson7687dc02013-09-13 11:54:07 -07002 * Copyright (C) 2013 Regents of the University of California.
3 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
Jeff Thompsonec39fbd2013-10-04 10:56:23 -07004 * @author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
5 * @author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
Jeff Thompson47eecfc2013-07-07 22:56:46 -07006 * See COPYING for copyright and distribution information.
Jeff Thompson9c41dfe2013-06-27 12:10:25 -07007 */
8
9#ifndef NDN_NAME_HPP
Jeff Thompson2d27e2f2013-08-09 12:55:00 -070010#define NDN_NAME_HPP
Jeff Thompson9c41dfe2013-06-27 12:10:25 -070011
12#include <vector>
Jeff Thompson443398d2013-07-02 19:45:46 -070013#include <string>
Jeff Thompsonec7789a2013-08-21 11:08:36 -070014#include <sstream>
Jeff Thompson53412192013-08-06 13:35:50 -070015#include "c/name.h"
16#include "encoding/binary-xml-wire-format.hpp"
Jeff Thompson995aba52013-09-12 12:04:52 -070017#include "util/blob.hpp"
Jeff Thompson9c41dfe2013-06-27 12:10:25 -070018
19namespace ndn {
Jeff Thompson5a6b5ab2013-08-05 15:43:47 -070020
Jeff Thompson9c41dfe2013-06-27 12:10:25 -070021class Name {
22public:
Jeff Thompsonc1c12e42013-09-13 19:08:45 -070023 /**
Jeff Thompson46411c92013-09-13 19:31:25 -070024 * A Name::Component is holds a read-only name component value.
Jeff Thompsonc1c12e42013-09-13 19:08:45 -070025 */
Jeff Thompson5a6b5ab2013-08-05 15:43:47 -070026 class Component {
27 public:
28 /**
Jeff Thompson46411c92013-09-13 19:31:25 -070029 * Create a new Name::Component with a null value.
Jeff Thompson5a6b5ab2013-08-05 15:43:47 -070030 */
31 Component()
32 {
33 }
34
35 /**
36 * Create a new Name::Component, copying the given value.
37 * @param value The value byte array.
38 */
Jeff Thompson10ad12a2013-09-24 16:19:11 -070039 Component(const std::vector<uint8_t>& value)
Jeff Thompson5a6b5ab2013-08-05 15:43:47 -070040 : value_(value)
41 {
42 }
43
44 /**
45 * Create a new Name::Component, copying the given value.
46 * @param value Pointer to the value byte array.
47 * @param valueLen Length of value.
48 */
Jeff Thompson97223af2013-09-24 17:01:27 -070049 Component(const uint8_t *value, size_t valueLen)
Jeff Thompson995aba52013-09-12 12:04:52 -070050 : value_(value, valueLen)
Jeff Thompson5a6b5ab2013-08-05 15:43:47 -070051 {
52 }
Jeff Thompson0f743452013-09-12 14:23:18 -070053
54 /**
55 * Create a new Name::Component, taking another pointer to the Blob value.
56 * @param value A blob with a pointer to an immutable array. The pointer is copied.
57 */
58 Component(const Blob &value)
59 : value_(value)
60 {
61 }
Jeff Thompson5a6b5ab2013-08-05 15:43:47 -070062
63 /**
64 * Set the componentStruct to point to this component, without copying any memory.
65 * WARNING: The resulting pointer in componentStruct is invalid after a further use of this object which could reallocate memory.
66 * @param componentStruct The C ndn_NameComponent struct to receive the pointer.
67 */
Jeff Thompson0050abe2013-09-17 12:50:25 -070068 void
69 get(struct ndn_NameComponent& componentStruct) const
Jeff Thompson5a6b5ab2013-08-05 15:43:47 -070070 {
Jeff Thompson93034532013-10-08 11:52:43 -070071 value_.get(componentStruct.value);
Jeff Thompson5a6b5ab2013-08-05 15:43:47 -070072 }
73
Jeff Thompson0050abe2013-09-17 12:50:25 -070074 const Blob&
75 getValue() const { return value_; }
Jeff Thompson6653b0b2013-09-23 12:32:39 -070076
77 /**
78 * Write this component value to result, escaping characters according to the NDN URI Scheme.
79 * This also adds "..." to a value with zero or more ".".
80 * @param value the buffer with the value to escape
81 * @param result the string stream to write to.
82 */
83 void
Jeff Thompsond0159d72013-09-23 13:34:15 -070084 toEscapedString(std::ostringstream& result) const
Jeff Thompson6653b0b2013-09-23 12:32:39 -070085 {
86 Name::toEscapedString(*value_, result);
87 }
88
89 /**
90 * Convert this component value by escaping characters according to the NDN URI Scheme.
91 * This also adds "..." to a value with zero or more ".".
92 * @return The escaped string.
93 */
94 std::string
Jeff Thompsond0159d72013-09-23 13:34:15 -070095 toEscapedString() const
Jeff Thompson6653b0b2013-09-23 12:32:39 -070096 {
97 return Name::toEscapedString(*value_);
98 }
Jeff Thompson9bdb3b22013-09-12 12:42:13 -070099
Jeff Thompsonc1c12e42013-09-13 19:08:45 -0700100 /**
Jeff Thompson46411c92013-09-13 19:31:25 -0700101 * Make a component value by decoding the escapedString between beginOffset and endOffset according to the NDN URI Scheme.
102 * If the escaped string is "", "." or ".." then return a Blob with a null pointer, which means this component value was not changed, and
Jeff Thompsonc1c12e42013-09-13 19:08:45 -0700103 * the component should be skipped in a URI name.
104 * @param escapedString The escaped string. It does not need to be null-terminated because we only scan to endOffset.
105 * @param beginOffset The offset in escapedString of the beginning of the portion to decode.
106 * @param endOffset The offset in escapedString of the end of the portion to decode.
Jeff Thompson46411c92013-09-13 19:31:25 -0700107 * @return The component value as a Blob, or a Blob with a null pointer if escapedString is not a valid escaped component.
Jeff Thompsonc1c12e42013-09-13 19:08:45 -0700108 */
Jeff Thompson0050abe2013-09-17 12:50:25 -0700109 static Blob
Jeff Thompson97223af2013-09-24 17:01:27 -0700110 makeFromEscapedString(const char *escapedString, size_t beginOffset, size_t endOffset);
Jeff Thompson8aac1992013-08-12 17:26:02 -0700111
112 /**
Jeff Thompson46411c92013-09-13 19:31:25 -0700113 * Make a component as the encoded segment number.
Jeff Thompson8aac1992013-08-12 17:26:02 -0700114 * @param segment The segment number.
Jeff Thompson46411c92013-09-13 19:31:25 -0700115 * @return The component value as a Blob.
Jeff Thompson8aac1992013-08-12 17:26:02 -0700116 */
Jeff Thompson0050abe2013-09-17 12:50:25 -0700117 static Blob
118 makeSegment(unsigned long segment);
Jeff Thompson5a6b5ab2013-08-05 15:43:47 -0700119
120 private:
Jeff Thompson995aba52013-09-12 12:04:52 -0700121 Blob value_;
Jeff Thompson5a6b5ab2013-08-05 15:43:47 -0700122 };
123
Jeff Thompson443398d2013-07-02 19:45:46 -0700124 /**
125 * Create a new Name with no components.
126 */
Jeff Thompson016ed642013-07-02 14:39:06 -0700127 Name() {
128 }
Jeff Thompson443398d2013-07-02 19:45:46 -0700129
130 /**
Jeff Thompson3f2175b2013-07-31 17:12:47 -0700131 * Create a new Name, copying the name components.
Jeff Thompson5a6b5ab2013-08-05 15:43:47 -0700132 * @param components A vector of Component
Jeff Thompson3f2175b2013-07-31 17:12:47 -0700133 */
Jeff Thompson1656e6a2013-08-29 18:01:48 -0700134 Name(const std::vector<Component>& components)
Jeff Thompson3f2175b2013-07-31 17:12:47 -0700135 : components_(components)
136 {
137 }
138
139 /**
Jeff Thompson443398d2013-07-02 19:45:46 -0700140 * Parse the uri according to the NDN URI Scheme and create the name with the components.
Jeff Thompson3f2175b2013-07-31 17:12:47 -0700141 * @param uri The URI string.
Jeff Thompson443398d2013-07-02 19:45:46 -0700142 */
Jeff Thompson3549ef32013-09-25 14:05:17 -0700143 Name(const char* uri)
Jeff Thompson67515bd2013-08-15 17:43:22 -0700144 {
145 set(uri);
146 }
Jeff Thompson5a6b5ab2013-08-05 15:43:47 -0700147
Jeff Thompsone5f839b2013-06-28 12:50:38 -0700148 /**
Jeff Thompson3549ef32013-09-25 14:05:17 -0700149 * Parse the uri according to the NDN URI Scheme and create the name with the components.
150 * @param uri The URI string.
151 */
152 Name(const std::string& uri)
153 {
154 set(uri.c_str());
155 }
Jeff Thompsonec39fbd2013-10-04 10:56:23 -0700156
Jeff Thompson3549ef32013-09-25 14:05:17 -0700157 /**
Jeff Thompson016ed642013-07-02 14:39:06 -0700158 * Set the nameStruct to point to the components in this name, without copying any memory.
159 * WARNING: The resulting pointers in nameStruct are invalid after a further use of this object which could reallocate memory.
Jeff Thompson3f2175b2013-07-31 17:12:47 -0700160 * @param nameStruct A C ndn_Name struct where the components array is already allocated.
Jeff Thompson016ed642013-07-02 14:39:06 -0700161 */
Jeff Thompson0050abe2013-09-17 12:50:25 -0700162 void
163 get(struct ndn_Name& nameStruct) const;
Jeff Thompson016ed642013-07-02 14:39:06 -0700164
165 /**
Jeff Thompson8b27e3a2013-07-03 18:19:53 -0700166 * Clear this name, and set the components by copying from the name struct.
Jeff Thompson3f2175b2013-07-31 17:12:47 -0700167 * @param nameStruct A C ndn_Name struct
Jeff Thompsonb468c312013-07-01 17:50:14 -0700168 */
Jeff Thompson0050abe2013-09-17 12:50:25 -0700169 void
170 set(const struct ndn_Name& nameStruct);
Jeff Thompsonb468c312013-07-01 17:50:14 -0700171
172 /**
Jeff Thompson67515bd2013-08-15 17:43:22 -0700173 * Parse the uri according to the NDN URI Scheme and set the name with the components.
174 * @param uri The URI string.
175 */
Jeff Thompson0050abe2013-09-17 12:50:25 -0700176 void
177 set(const char *uri);
Jeff Thompson67515bd2013-08-15 17:43:22 -0700178
179 /**
Jeff Thompson0aa66f22013-09-23 13:02:13 -0700180 * Append a new component, copying from value of length valueLength.
Jeff Thompson26b0d792013-09-23 16:19:01 -0700181 * @return This name so that you can chain calls to append.
Jeff Thompsone5f839b2013-06-28 12:50:38 -0700182 */
Jeff Thompson26b0d792013-09-23 16:19:01 -0700183 Name&
Jeff Thompson97223af2013-09-24 17:01:27 -0700184 append(const uint8_t *value, size_t valueLength)
Jeff Thompson0f743452013-09-12 14:23:18 -0700185 {
Jeff Thompson5a6b5ab2013-08-05 15:43:47 -0700186 components_.push_back(Component(value, valueLength));
Jeff Thompson26b0d792013-09-23 16:19:01 -0700187 return *this;
Jeff Thompsone5f839b2013-06-28 12:50:38 -0700188 }
Jeff Thompsonf72b1ac2013-08-16 16:44:41 -0700189
190 /**
Jeff Thompson0aa66f22013-09-23 13:02:13 -0700191 * Append a new component, copying from value.
Jeff Thompson26b0d792013-09-23 16:19:01 -0700192 * @return This name so that you can chain calls to append.
Jeff Thompsonf72b1ac2013-08-16 16:44:41 -0700193 */
Jeff Thompson26b0d792013-09-23 16:19:01 -0700194 Name&
Jeff Thompson10ad12a2013-09-24 16:19:11 -0700195 append(const std::vector<uint8_t>& value)
Jeff Thompson0f743452013-09-12 14:23:18 -0700196 {
197 components_.push_back(value);
Jeff Thompson26b0d792013-09-23 16:19:01 -0700198 return *this;
Jeff Thompson0f743452013-09-12 14:23:18 -0700199 }
200
Jeff Thompson26b0d792013-09-23 16:19:01 -0700201 Name&
202 append(const Blob &value)
Jeff Thompson0f743452013-09-12 14:23:18 -0700203 {
Jeff Thompsonf72b1ac2013-08-16 16:44:41 -0700204 components_.push_back(value);
Jeff Thompson26b0d792013-09-23 16:19:01 -0700205 return *this;
Jeff Thompsonf72b1ac2013-08-16 16:44:41 -0700206 }
Jeff Thompsone5f839b2013-06-28 12:50:38 -0700207
Jeff Thompson21eb7212013-09-26 09:05:40 -0700208 Name&
209 append(const Component &value)
210 {
211 components_.push_back(value);
212 return *this;
213 }
214
Jeff Thompsone5f839b2013-06-28 12:50:38 -0700215 /**
Jeff Thompson26b0d792013-09-23 16:19:01 -0700216 * Append the components of the given name to this name.
217 * @param name The Name with components to append.
218 * @return This name so that you can chain calls to append.
Jeff Thompson0aa66f22013-09-23 13:02:13 -0700219 */
Jeff Thompson26b0d792013-09-23 16:19:01 -0700220 Name&
221 append(const Name& name);
222
223 /**
224 * @deprecated Use append.
225 */
226 Name&
Jeff Thompson97223af2013-09-24 17:01:27 -0700227 appendComponent(const uint8_t *value, size_t valueLength)
Jeff Thompson0aa66f22013-09-23 13:02:13 -0700228 {
Jeff Thompson26b0d792013-09-23 16:19:01 -0700229 return append(value, valueLength);
Jeff Thompson0aa66f22013-09-23 13:02:13 -0700230 }
231
232 /**
Jeff Thompson26b0d792013-09-23 16:19:01 -0700233 * @deprecated Use append.
Jeff Thompson0aa66f22013-09-23 13:02:13 -0700234 */
Jeff Thompson26b0d792013-09-23 16:19:01 -0700235 Name&
Jeff Thompson10ad12a2013-09-24 16:19:11 -0700236 appendComponent(const std::vector<uint8_t>& value)
Jeff Thompson0aa66f22013-09-23 13:02:13 -0700237 {
Jeff Thompson26b0d792013-09-23 16:19:01 -0700238 return append(value);
Jeff Thompson0aa66f22013-09-23 13:02:13 -0700239 }
240
241 /**
Jeff Thompson26b0d792013-09-23 16:19:01 -0700242 * @deprecated Use append.
Jeff Thompson0aa66f22013-09-23 13:02:13 -0700243 */
Jeff Thompson26b0d792013-09-23 16:19:01 -0700244 Name&
245 appendComponent(const Blob &value)
246 {
247 return append(value);
248 }
249
250 /**
251 * @deprecated Use append.
252 */
253 Name&
Jeff Thompson97223af2013-09-24 17:01:27 -0700254 addComponent(const uint8_t *value, size_t valueLength)
Jeff Thompson26b0d792013-09-23 16:19:01 -0700255 {
256 return append(value, valueLength);
257 }
258
259 /**
260 * @deprecated Use append.
261 */
262 Name&
Jeff Thompson10ad12a2013-09-24 16:19:11 -0700263 addComponent(const std::vector<uint8_t>& value)
Jeff Thompson26b0d792013-09-23 16:19:01 -0700264 {
265 return append(value);
266 }
267
268 /**
269 * @deprecated Use append.
270 */
271 Name&
Jeff Thompson0aa66f22013-09-23 13:02:13 -0700272 addComponent(const Blob &value)
273 {
Jeff Thompson26b0d792013-09-23 16:19:01 -0700274 return append(value);
Jeff Thompson0aa66f22013-09-23 13:02:13 -0700275 }
276
277 /**
Jeff Thompsone5f839b2013-06-28 12:50:38 -0700278 * Clear all the components.
279 */
Jeff Thompson0050abe2013-09-17 12:50:25 -0700280 void
281 clear() {
Jeff Thompsone5f839b2013-06-28 12:50:38 -0700282 components_.clear();
283 }
284
285 /**
286 * Get the number of components.
Jeff Thompson3f2175b2013-07-31 17:12:47 -0700287 * @return The number of components.
Jeff Thompsone5f839b2013-06-28 12:50:38 -0700288 */
Jeff Thompson97223af2013-09-24 17:01:27 -0700289 size_t
Jeff Thompson0050abe2013-09-17 12:50:25 -0700290 getComponentCount() const {
Jeff Thompsone5f839b2013-06-28 12:50:38 -0700291 return components_.size();
292 }
293
Jeff Thompsonec39fbd2013-10-04 10:56:23 -0700294 /**
295 * Get the component at the given index.
296 * @param i The index of the component, starting from 0.
297 * @return The name component at the index.
298 */
Jeff Thompson0050abe2013-09-17 12:50:25 -0700299 const Component&
Jeff Thompson97223af2013-09-24 17:01:27 -0700300 getComponent(size_t i) const { return components_[i]; }
Jeff Thompson443398d2013-07-02 19:45:46 -0700301
Jeff Thompsone6063512013-07-01 15:11:28 -0700302 /**
Jeff Thompsond0159d72013-09-23 13:34:15 -0700303 * Get a new name, constructed as a subset of components.
304 * @param iStartComponent The index if the first component to get.
305 * @param nComponents The number of components starting at iStartComponent.
306 * @return A new name.
307 */
308 Name
309 getSubName(size_t iStartComponent, size_t nComponents) const;
310
311 /**
312 * Get a new name, constructed as a subset of components starting at iStartComponent until the end of the name.
313 * @param iStartComponent The index if the first component to get.
314 * @return A new name.
315 */
316 Name
317 getSubName(size_t iStartComponent) const;
318
319 /**
320 * Return a new Name with the first nComponents components of this Name.
321 * @param nComponents The number of prefix components.
322 * @return A new Name.
323 */
324 Name
325 getPrefix(size_t nComponents) const
326 {
327 return getSubName(0, nComponents);
328 }
329
330 /**
Jeff Thompsone6063512013-07-01 15:11:28 -0700331 * Encode this name as a URI.
Jeff Thompson3f2175b2013-07-31 17:12:47 -0700332 * @return The encoded URI.
Jeff Thompsone6063512013-07-01 15:11:28 -0700333 */
Jeff Thompson0050abe2013-09-17 12:50:25 -0700334 std::string
335 toUri() const;
Jeff Thompsone6063512013-07-01 15:11:28 -0700336
Jeff Thompson21844fc2013-08-08 14:52:51 -0700337 /**
338 * @deprecated Use toUri().
339 */
Jeff Thompson0050abe2013-09-17 12:50:25 -0700340 std::string
341 to_uri() const
Jeff Thompson21844fc2013-08-08 14:52:51 -0700342 {
343 return toUri();
344 }
Jeff Thompson26b0d792013-09-23 16:19:01 -0700345
Jeff Thompson8aac1992013-08-12 17:26:02 -0700346 /**
347 * Append a component with the encoded segment number.
348 * @param segment The segment number.
Jeff Thompson26b0d792013-09-23 16:19:01 -0700349 * @return This name so that you can chain calls to append.
350 */
351 Name&
Jeff Thompson0050abe2013-09-17 12:50:25 -0700352 appendSegment(unsigned long segment)
Jeff Thompson8aac1992013-08-12 17:26:02 -0700353 {
Jeff Thompson46411c92013-09-13 19:31:25 -0700354 components_.push_back(Component(Component::makeSegment(segment)));
Jeff Thompson26b0d792013-09-23 16:19:01 -0700355 return *this;
Jeff Thompson8aac1992013-08-12 17:26:02 -0700356 }
Jeff Thompsoncc35cd42013-08-20 12:23:14 -0700357
Jeff Thompsonec7789a2013-08-21 11:08:36 -0700358 /**
Jeff Thompson3c2ab012013-10-02 14:18:16 -0700359 * Check if this name has the same component count and components as the given name.
360 * @param name The Name to check.
361 * @return true if the names are equal, otherwise false.
362 */
363 bool
364 equals(const Name& name) const;
365
366 /**
Jeff Thompsonec7789a2013-08-21 11:08:36 -0700367 * Check if the N components of this name are the same as the first N components of the given name.
368 * @param name The Name to check.
369 * @return true if this matches the given name, otherwise false. This always returns true if this name is empty.
370 */
Jeff Thompson0050abe2013-09-17 12:50:25 -0700371 bool
372 match(const Name& name) const;
Jeff Thompsonec7789a2013-08-21 11:08:36 -0700373
374 /**
375 * Write the value to result, escaping characters according to the NDN URI Scheme.
376 * This also adds "..." to a value with zero or more ".".
377 * @param value the buffer with the value to escape
378 * @param result the string stream to write to.
379 */
Jeff Thompson0050abe2013-09-17 12:50:25 -0700380 static void
Jeff Thompson10ad12a2013-09-24 16:19:11 -0700381 toEscapedString(const std::vector<uint8_t>& value, std::ostringstream& result);
Jeff Thompson21844fc2013-08-08 14:52:51 -0700382
Jeff Thompson6653b0b2013-09-23 12:32:39 -0700383 /**
384 * Convert the value by escaping characters according to the NDN URI Scheme.
385 * This also adds "..." to a value with zero or more ".".
386 * @param value the buffer with the value to escape
387 * @return The escaped string.
388 */
389 static std::string
Jeff Thompson10ad12a2013-09-24 16:19:11 -0700390 toEscapedString(const std::vector<uint8_t>& value);
Jeff Thompson6653b0b2013-09-23 12:32:39 -0700391
Jeff Thompsonec39fbd2013-10-04 10:56:23 -0700392 //
393 // vector equivalent interface.
394 //
395
396 /**
397 * Get the number of components.
398 * @return The number of components.
399 */
400 size_t
401 size() const {
402 return getComponentCount();
403 }
404
405 /**
406 * Get the component at the given index.
407 * @param i The index of the component, starting from 0.
408 * @return The name component at the index.
409 */
410 const Component&
411 get(size_t i) const { return getComponent(i); }
412
413
414 const Component&
415 operator [] (int i) const
416 {
417 return get(i);
418 }
419
420 /**
421 * Append the component
422 * @param component The component of type T.
423 */
424 template<class T> void
425 push_back(const T &component)
426 {
427 append(component);
428 }
429
Jeff Thompson91737f52013-10-04 11:07:24 -0700430 /**
431 * Check if this name has the same component count and components as the given name.
432 * @param name The Name to check.
433 * @return true if the names are equal, otherwise false.
434 */
435 bool
436 operator == (const Name &name) const { return equals(name); }
437
438 /**
439 * Check if this name has the same component count and components as the given name.
440 * @param name The Name to check.
441 * @return true if the names are not equal, otherwise false.
442 */
443 bool
444 operator != (const Name &name) const { return !equals(name); }
445
Jeff Thompsonec39fbd2013-10-04 10:56:23 -0700446 //
447 // Iterator interface to name components.
448 //
449 typedef std::vector<Component>::iterator iterator;
450 typedef std::vector<Component>::const_iterator const_iterator;
451 typedef std::vector<Component>::reverse_iterator reverse_iterator;
452 typedef std::vector<Component>::const_reverse_iterator const_reverse_iterator;
453 typedef std::vector<Component>::reference reference;
454 typedef std::vector<Component>::const_reference const_reference;
455
456 typedef Component partial_type;
457
458 /**
459 * Begin iterator (const).
460 */
461 const_iterator
Jeff Thompson91737f52013-10-04 11:07:24 -0700462 begin() const { return components_.begin(); }
Jeff Thompsonec39fbd2013-10-04 10:56:23 -0700463
464 /**
465 * Begin iterator.
466 */
467 iterator
Jeff Thompson91737f52013-10-04 11:07:24 -0700468 begin() { return components_.begin(); }
Jeff Thompsonec39fbd2013-10-04 10:56:23 -0700469
470 /**
471 * End iterator (const).
472 */
473 const_iterator
Jeff Thompson91737f52013-10-04 11:07:24 -0700474 end() const { return components_.end(); }
Jeff Thompsonec39fbd2013-10-04 10:56:23 -0700475
476 /**
477 * End iterator.
478 */
479 iterator
Jeff Thompson91737f52013-10-04 11:07:24 -0700480 end() { return components_.end(); }
Jeff Thompsonec39fbd2013-10-04 10:56:23 -0700481
482 /**
483 * Reverse begin iterator (const).
484 */
485 const_reverse_iterator
Jeff Thompson91737f52013-10-04 11:07:24 -0700486 rbegin() const { return components_.rbegin(); }
Jeff Thompsonec39fbd2013-10-04 10:56:23 -0700487
488 /**
489 * Reverse begin iterator.
490 */
491 reverse_iterator
Jeff Thompson91737f52013-10-04 11:07:24 -0700492 rbegin() { return components_.rbegin(); }
Jeff Thompsonec39fbd2013-10-04 10:56:23 -0700493
494 /**
495 * Reverse end iterator (const).
496 */
497 const_reverse_iterator
Jeff Thompson91737f52013-10-04 11:07:24 -0700498 rend() const { return components_.rend(); }
Jeff Thompsonec39fbd2013-10-04 10:56:23 -0700499
500 /**
501 * Reverse end iterator.
502 */
503 reverse_iterator
Jeff Thompson91737f52013-10-04 11:07:24 -0700504 rend() { return components_.rend(); }
Jeff Thompsonec39fbd2013-10-04 10:56:23 -0700505
Jeff Thompson9c41dfe2013-06-27 12:10:25 -0700506private:
Jeff Thompson5a6b5ab2013-08-05 15:43:47 -0700507 std::vector<Component> components_;
Jeff Thompson9c41dfe2013-06-27 12:10:25 -0700508};
509
Jeff Thompson49e321a2013-10-04 17:35:59 -0700510inline std::ostream&
511operator << (std::ostream& os, const Name& name)
512{
513 os << name.toUri();
514 return os;
515}
516
Jeff Thompson9c41dfe2013-06-27 12:10:25 -0700517}
518
519#endif
520