Jeff Thompson | 25b4e61 | 2013-10-10 16:03:24 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
Jeff Thompson | 47eecfc | 2013-07-07 22:56:46 -0700 | [diff] [blame] | 2 | /** |
Jeff Thompson | 7687dc0 | 2013-09-13 11:54:07 -0700 | [diff] [blame] | 3 | * Copyright (C) 2013 Regents of the University of California. |
| 4 | * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
Jeff Thompson | ec39fbd | 2013-10-04 10:56:23 -0700 | [diff] [blame] | 5 | * @author: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 6 | * @author: Zhenkai Zhu <zhenkai@cs.ucla.edu> |
Jeff Thompson | 47eecfc | 2013-07-07 22:56:46 -0700 | [diff] [blame] | 7 | * See COPYING for copyright and distribution information. |
Jeff Thompson | 9c41dfe | 2013-06-27 12:10:25 -0700 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #ifndef NDN_NAME_HPP |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 11 | #define NDN_NAME_HPP |
Jeff Thompson | 9c41dfe | 2013-06-27 12:10:25 -0700 | [diff] [blame] | 12 | |
| 13 | #include <vector> |
Jeff Thompson | 443398d | 2013-07-02 19:45:46 -0700 | [diff] [blame] | 14 | #include <string> |
Jeff Thompson | 27b2bf9 | 2013-10-12 14:38:13 -0700 | [diff] [blame] | 15 | #include <string.h> |
Jeff Thompson | ec7789a | 2013-08-21 11:08:36 -0700 | [diff] [blame] | 16 | #include <sstream> |
Jeff Thompson | 995aba5 | 2013-09-12 12:04:52 -0700 | [diff] [blame] | 17 | #include "util/blob.hpp" |
Jeff Thompson | 9c41dfe | 2013-06-27 12:10:25 -0700 | [diff] [blame] | 18 | |
Jeff Thompson | 25b4e61 | 2013-10-10 16:03:24 -0700 | [diff] [blame] | 19 | struct ndn_NameComponent; |
| 20 | struct ndn_Name; |
| 21 | |
Jeff Thompson | 9c41dfe | 2013-06-27 12:10:25 -0700 | [diff] [blame] | 22 | namespace ndn { |
Jeff Thompson | 5a6b5ab | 2013-08-05 15:43:47 -0700 | [diff] [blame] | 23 | |
Jeff Thompson | c7d6550 | 2013-11-06 17:22:26 -0800 | [diff] [blame] | 24 | /** |
| 25 | * A Name holds an array of Name::Component and represents an NDN name. |
| 26 | */ |
Jeff Thompson | 9c41dfe | 2013-06-27 12:10:25 -0700 | [diff] [blame] | 27 | class Name { |
| 28 | public: |
Jeff Thompson | c1c12e4 | 2013-09-13 19:08:45 -0700 | [diff] [blame] | 29 | /** |
Jeff Thompson | c7d6550 | 2013-11-06 17:22:26 -0800 | [diff] [blame] | 30 | * A Name::Component holds a read-only name component value. |
Jeff Thompson | c1c12e4 | 2013-09-13 19:08:45 -0700 | [diff] [blame] | 31 | */ |
Jeff Thompson | 5a6b5ab | 2013-08-05 15:43:47 -0700 | [diff] [blame] | 32 | class Component { |
| 33 | public: |
| 34 | /** |
Jeff Thompson | 46411c9 | 2013-09-13 19:31:25 -0700 | [diff] [blame] | 35 | * Create a new Name::Component with a null value. |
Jeff Thompson | 5a6b5ab | 2013-08-05 15:43:47 -0700 | [diff] [blame] | 36 | */ |
| 37 | Component() |
| 38 | { |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Create a new Name::Component, copying the given value. |
| 43 | * @param value The value byte array. |
| 44 | */ |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame] | 45 | Component(const std::vector<uint8_t>& value) |
Jeff Thompson | 5a6b5ab | 2013-08-05 15:43:47 -0700 | [diff] [blame] | 46 | : value_(value) |
| 47 | { |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Create a new Name::Component, copying the given value. |
| 52 | * @param value Pointer to the value byte array. |
| 53 | * @param valueLen Length of value. |
| 54 | */ |
Jeff Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame] | 55 | Component(const uint8_t *value, size_t valueLen) |
Jeff Thompson | 995aba5 | 2013-09-12 12:04:52 -0700 | [diff] [blame] | 56 | : value_(value, valueLen) |
Jeff Thompson | 5a6b5ab | 2013-08-05 15:43:47 -0700 | [diff] [blame] | 57 | { |
| 58 | } |
Jeff Thompson | 0f74345 | 2013-09-12 14:23:18 -0700 | [diff] [blame] | 59 | |
| 60 | /** |
| 61 | * Create a new Name::Component, taking another pointer to the Blob value. |
| 62 | * @param value A blob with a pointer to an immutable array. The pointer is copied. |
| 63 | */ |
| 64 | Component(const Blob &value) |
| 65 | : value_(value) |
| 66 | { |
| 67 | } |
Jeff Thompson | 5a6b5ab | 2013-08-05 15:43:47 -0700 | [diff] [blame] | 68 | |
| 69 | /** |
| 70 | * Set the componentStruct to point to this component, without copying any memory. |
| 71 | * WARNING: The resulting pointer in componentStruct is invalid after a further use of this object which could reallocate memory. |
| 72 | * @param componentStruct The C ndn_NameComponent struct to receive the pointer. |
| 73 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 74 | void |
Jeff Thompson | 25b4e61 | 2013-10-10 16:03:24 -0700 | [diff] [blame] | 75 | get(struct ndn_NameComponent& componentStruct) const; |
Jeff Thompson | 5a6b5ab | 2013-08-05 15:43:47 -0700 | [diff] [blame] | 76 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 77 | const Blob& |
| 78 | getValue() const { return value_; } |
Jeff Thompson | 6653b0b | 2013-09-23 12:32:39 -0700 | [diff] [blame] | 79 | |
| 80 | /** |
| 81 | * Write this component value to result, escaping characters according to the NDN URI Scheme. |
| 82 | * This also adds "..." to a value with zero or more ".". |
Jeff Thompson | 6653b0b | 2013-09-23 12:32:39 -0700 | [diff] [blame] | 83 | * @param result the string stream to write to. |
| 84 | */ |
| 85 | void |
Jeff Thompson | d0159d7 | 2013-09-23 13:34:15 -0700 | [diff] [blame] | 86 | toEscapedString(std::ostringstream& result) const |
Jeff Thompson | 6653b0b | 2013-09-23 12:32:39 -0700 | [diff] [blame] | 87 | { |
| 88 | Name::toEscapedString(*value_, result); |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Convert this component value by escaping characters according to the NDN URI Scheme. |
| 93 | * This also adds "..." to a value with zero or more ".". |
| 94 | * @return The escaped string. |
| 95 | */ |
| 96 | std::string |
Jeff Thompson | d0159d7 | 2013-09-23 13:34:15 -0700 | [diff] [blame] | 97 | toEscapedString() const |
Jeff Thompson | 6653b0b | 2013-09-23 12:32:39 -0700 | [diff] [blame] | 98 | { |
| 99 | return Name::toEscapedString(*value_); |
| 100 | } |
Jeff Thompson | 9bdb3b2 | 2013-09-12 12:42:13 -0700 | [diff] [blame] | 101 | |
Jeff Thompson | 50b3791 | 2013-10-08 13:39:33 -0700 | [diff] [blame] | 102 | /** |
| 103 | * Interpret this name component as a network-ordered number and return an integer. |
| 104 | * @return The integer number. |
| 105 | */ |
| 106 | uint64_t |
Jeff Thompson | 25b4e61 | 2013-10-10 16:03:24 -0700 | [diff] [blame] | 107 | toNumber() const; |
Jeff Thompson | 27cae53 | 2013-10-08 12:52:41 -0700 | [diff] [blame] | 108 | |
Jeff Thompson | 50b3791 | 2013-10-08 13:39:33 -0700 | [diff] [blame] | 109 | /** |
| 110 | * Interpret this name component as a network-ordered number with a marker and return an integer. |
| 111 | * @param marker The required first byte of the component. |
| 112 | * @return The integer number. |
| 113 | * @throw runtime_error If the first byte of the component does not equal the marker. |
| 114 | */ |
| 115 | uint64_t |
| 116 | toNumberWithMarker(uint8_t marker) const; |
| 117 | |
| 118 | /** |
| 119 | * Interpret this name component as a segment number according to NDN name conventions (a network-ordered number |
| 120 | * where the first byte is the marker 0x00). |
| 121 | * @return The integer segment number. |
| 122 | * @throw runtime_error If the first byte of the component is not the expected marker. |
| 123 | */ |
| 124 | uint64_t |
| 125 | toSegment() const |
| 126 | { |
| 127 | return toNumberWithMarker(0x00); |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * @deprecated Use toSegment. |
| 132 | */ |
| 133 | uint64_t |
| 134 | toSeqNum() const |
| 135 | { |
| 136 | return toSegment(); |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * Interpret this name component as a version number according to NDN name conventions (a network-ordered number |
| 141 | * where the first byte is the marker 0xFD). Note that this returns the exact number from the component |
| 142 | * without converting it to a time representation. |
| 143 | * @return The integer segment number. |
| 144 | * @throw runtime_error If the first byte of the component is not the expected marker. |
| 145 | */ |
| 146 | uint64_t |
| 147 | toVersion() const |
| 148 | { |
| 149 | return toNumberWithMarker(0xFD); |
| 150 | } |
Jeff Thompson | 27cae53 | 2013-10-08 12:52:41 -0700 | [diff] [blame] | 151 | |
Jeff Thompson | c1c12e4 | 2013-09-13 19:08:45 -0700 | [diff] [blame] | 152 | /** |
Jeff Thompson | d129ac1 | 2013-10-11 14:30:12 -0700 | [diff] [blame] | 153 | * Create a component whose value is the network-ordered encoding of the number. |
| 154 | * Note: if the number is zero, the result is empty. |
| 155 | * @param number The number to be encoded. |
| 156 | * @return The component value. |
| 157 | */ |
| 158 | static Component |
| 159 | fromNumber(uint64_t number); |
Jeff Thompson | 8aac199 | 2013-08-12 17:26:02 -0700 | [diff] [blame] | 160 | |
| 161 | /** |
Jeff Thompson | d129ac1 | 2013-10-11 14:30:12 -0700 | [diff] [blame] | 162 | * Create a component whose value is the marker appended with the network-ordered encoding of the number. |
| 163 | * Note: if the number is zero, no bytes are used for the number - the result will have only the marker. |
| 164 | * @param number The number to be encoded. |
| 165 | * @param marker The marker to use as the first byte of the component. |
| 166 | * @return The component value. |
Jeff Thompson | 8aac199 | 2013-08-12 17:26:02 -0700 | [diff] [blame] | 167 | */ |
Jeff Thompson | d129ac1 | 2013-10-11 14:30:12 -0700 | [diff] [blame] | 168 | static Component |
| 169 | fromNumberWithMarker(uint64_t number, uint8_t marker); |
Jeff Thompson | a98000c | 2013-12-16 14:40:09 -0800 | [diff] [blame] | 170 | |
| 171 | /** |
| 172 | * Check if this is the same component as other. |
| 173 | * @param other The other Component to compare with. |
| 174 | * @return true if the components are equal, otherwise false. |
| 175 | */ |
| 176 | bool |
| 177 | equals(const Component& other) const |
| 178 | { |
| 179 | return *value_ == *other.value_; |
| 180 | } |
| 181 | |
| 182 | /** |
| 183 | * Check if this is the same component as other. |
| 184 | * @param other The other Component to compare with. |
| 185 | * @return true if the components are equal, otherwise false. |
| 186 | */ |
| 187 | bool |
| 188 | operator == (const Component& other) const { return equals(other); } |
| 189 | |
| 190 | /** |
| 191 | * Check if this is not the same component as other. |
| 192 | * @param other The other Component to compare with. |
| 193 | * @return true if the components are not equal, otherwise false. |
| 194 | */ |
| 195 | bool |
| 196 | operator != (const Component& other) const { return !equals(other); } |
| 197 | |
| 198 | /** |
| 199 | * Compare this to the other Component using NDN canonical ordering. |
| 200 | * @param other The other Component to compare with. |
| 201 | * @return 0 If they compare equal, -1 if *this comes before other in the canonical ordering, or |
| 202 | * 1 if *this comes after other in the canonical ordering. |
| 203 | * |
| 204 | * @see http://named-data.net/doc/0.2/technical/CanonicalOrder.html |
| 205 | */ |
| 206 | int |
| 207 | compare(const Component& other) const; |
Jeff Thompson | 5a6b5ab | 2013-08-05 15:43:47 -0700 | [diff] [blame] | 208 | |
Jeff Thompson | a98000c | 2013-12-16 14:40:09 -0800 | [diff] [blame] | 209 | /** |
| 210 | * Return true if this is less than or equal to the other Component in the NDN canonical ordering. |
| 211 | * @param other The other Component to compare with. |
| 212 | * |
| 213 | * @see http://named-data.net/doc/0.2/technical/CanonicalOrder.html |
| 214 | */ |
| 215 | bool |
| 216 | operator <= (const Component& other) const { return compare(other) <= 0; } |
| 217 | |
| 218 | /** |
| 219 | * Return true if this is less than the other Component in the NDN canonical ordering. |
| 220 | * @param other The other Component to compare with. |
| 221 | * |
| 222 | * @see http://named-data.net/doc/0.2/technical/CanonicalOrder.html |
| 223 | */ |
| 224 | bool |
| 225 | operator < (const Component& other) const { return compare(other) < 0; } |
| 226 | |
| 227 | /** |
| 228 | * Return true if this is less than or equal to the other Component in the NDN canonical ordering. |
| 229 | * @param other The other Component to compare with. |
| 230 | * |
| 231 | * @see http://named-data.net/doc/0.2/technical/CanonicalOrder.html |
| 232 | */ |
| 233 | bool |
| 234 | operator >= (const Component& other) const { return compare(other) >= 0; } |
| 235 | |
| 236 | /** |
| 237 | * Return true if this is greater than the other Component in the NDN canonical ordering. |
| 238 | * @param other The other Component to compare with. |
| 239 | * |
| 240 | * @see http://named-data.net/doc/0.2/technical/CanonicalOrder.html |
| 241 | */ |
| 242 | bool |
| 243 | operator > (const Component& other) const { return compare(other) > 0; } |
| 244 | |
Jeff Thompson | 5a6b5ab | 2013-08-05 15:43:47 -0700 | [diff] [blame] | 245 | private: |
Jeff Thompson | 995aba5 | 2013-09-12 12:04:52 -0700 | [diff] [blame] | 246 | Blob value_; |
Jeff Thompson | 5a6b5ab | 2013-08-05 15:43:47 -0700 | [diff] [blame] | 247 | }; |
| 248 | |
Jeff Thompson | 443398d | 2013-07-02 19:45:46 -0700 | [diff] [blame] | 249 | /** |
| 250 | * Create a new Name with no components. |
| 251 | */ |
Jeff Thompson | 016ed64 | 2013-07-02 14:39:06 -0700 | [diff] [blame] | 252 | Name() { |
| 253 | } |
Jeff Thompson | 443398d | 2013-07-02 19:45:46 -0700 | [diff] [blame] | 254 | |
| 255 | /** |
Jeff Thompson | 3f2175b | 2013-07-31 17:12:47 -0700 | [diff] [blame] | 256 | * Create a new Name, copying the name components. |
Jeff Thompson | 5a6b5ab | 2013-08-05 15:43:47 -0700 | [diff] [blame] | 257 | * @param components A vector of Component |
Jeff Thompson | 3f2175b | 2013-07-31 17:12:47 -0700 | [diff] [blame] | 258 | */ |
Jeff Thompson | 1656e6a | 2013-08-29 18:01:48 -0700 | [diff] [blame] | 259 | Name(const std::vector<Component>& components) |
Jeff Thompson | 3f2175b | 2013-07-31 17:12:47 -0700 | [diff] [blame] | 260 | : components_(components) |
| 261 | { |
| 262 | } |
| 263 | |
| 264 | /** |
Jeff Thompson | 443398d | 2013-07-02 19:45:46 -0700 | [diff] [blame] | 265 | * Parse the uri according to the NDN URI Scheme and create the name with the components. |
Jeff Thompson | 3f2175b | 2013-07-31 17:12:47 -0700 | [diff] [blame] | 266 | * @param uri The URI string. |
Jeff Thompson | 443398d | 2013-07-02 19:45:46 -0700 | [diff] [blame] | 267 | */ |
Jeff Thompson | 3549ef3 | 2013-09-25 14:05:17 -0700 | [diff] [blame] | 268 | Name(const char* uri) |
Jeff Thompson | 67515bd | 2013-08-15 17:43:22 -0700 | [diff] [blame] | 269 | { |
| 270 | set(uri); |
| 271 | } |
Jeff Thompson | 5a6b5ab | 2013-08-05 15:43:47 -0700 | [diff] [blame] | 272 | |
Jeff Thompson | e5f839b | 2013-06-28 12:50:38 -0700 | [diff] [blame] | 273 | /** |
Jeff Thompson | 3549ef3 | 2013-09-25 14:05:17 -0700 | [diff] [blame] | 274 | * Parse the uri according to the NDN URI Scheme and create the name with the components. |
| 275 | * @param uri The URI string. |
| 276 | */ |
| 277 | Name(const std::string& uri) |
| 278 | { |
| 279 | set(uri.c_str()); |
| 280 | } |
Jeff Thompson | ec39fbd | 2013-10-04 10:56:23 -0700 | [diff] [blame] | 281 | |
Jeff Thompson | 3549ef3 | 2013-09-25 14:05:17 -0700 | [diff] [blame] | 282 | /** |
Jeff Thompson | 016ed64 | 2013-07-02 14:39:06 -0700 | [diff] [blame] | 283 | * Set the nameStruct to point to the components in this name, without copying any memory. |
| 284 | * WARNING: The resulting pointers in nameStruct are invalid after a further use of this object which could reallocate memory. |
Jeff Thompson | 3f2175b | 2013-07-31 17:12:47 -0700 | [diff] [blame] | 285 | * @param nameStruct A C ndn_Name struct where the components array is already allocated. |
Jeff Thompson | 016ed64 | 2013-07-02 14:39:06 -0700 | [diff] [blame] | 286 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 287 | void |
| 288 | get(struct ndn_Name& nameStruct) const; |
Jeff Thompson | 016ed64 | 2013-07-02 14:39:06 -0700 | [diff] [blame] | 289 | |
| 290 | /** |
Jeff Thompson | 8b27e3a | 2013-07-03 18:19:53 -0700 | [diff] [blame] | 291 | * Clear this name, and set the components by copying from the name struct. |
Jeff Thompson | 3f2175b | 2013-07-31 17:12:47 -0700 | [diff] [blame] | 292 | * @param nameStruct A C ndn_Name struct |
Jeff Thompson | b468c31 | 2013-07-01 17:50:14 -0700 | [diff] [blame] | 293 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 294 | void |
| 295 | set(const struct ndn_Name& nameStruct); |
Jeff Thompson | b468c31 | 2013-07-01 17:50:14 -0700 | [diff] [blame] | 296 | |
| 297 | /** |
Jeff Thompson | 67515bd | 2013-08-15 17:43:22 -0700 | [diff] [blame] | 298 | * Parse the uri according to the NDN URI Scheme and set the name with the components. |
Jeff Thompson | 7781b39 | 2013-12-17 11:45:59 -0800 | [diff] [blame] | 299 | * @param uri The null-terminated URI string. |
Jeff Thompson | 67515bd | 2013-08-15 17:43:22 -0700 | [diff] [blame] | 300 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 301 | void |
| 302 | set(const char *uri); |
Jeff Thompson | 67515bd | 2013-08-15 17:43:22 -0700 | [diff] [blame] | 303 | |
| 304 | /** |
Jeff Thompson | 7781b39 | 2013-12-17 11:45:59 -0800 | [diff] [blame] | 305 | * Parse the uri according to the NDN URI Scheme and set the name with the components. |
| 306 | * @param uri The URI string. |
| 307 | */ |
| 308 | void |
| 309 | set(const std::string& uri) { set(uri.c_str()); } |
| 310 | |
| 311 | /** |
Jeff Thompson | 0aa66f2 | 2013-09-23 13:02:13 -0700 | [diff] [blame] | 312 | * Append a new component, copying from value of length valueLength. |
Jeff Thompson | 26b0d79 | 2013-09-23 16:19:01 -0700 | [diff] [blame] | 313 | * @return This name so that you can chain calls to append. |
Jeff Thompson | e5f839b | 2013-06-28 12:50:38 -0700 | [diff] [blame] | 314 | */ |
Jeff Thompson | 26b0d79 | 2013-09-23 16:19:01 -0700 | [diff] [blame] | 315 | Name& |
Jeff Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame] | 316 | append(const uint8_t *value, size_t valueLength) |
Jeff Thompson | 0f74345 | 2013-09-12 14:23:18 -0700 | [diff] [blame] | 317 | { |
Jeff Thompson | 5a6b5ab | 2013-08-05 15:43:47 -0700 | [diff] [blame] | 318 | components_.push_back(Component(value, valueLength)); |
Jeff Thompson | 26b0d79 | 2013-09-23 16:19:01 -0700 | [diff] [blame] | 319 | return *this; |
Jeff Thompson | e5f839b | 2013-06-28 12:50:38 -0700 | [diff] [blame] | 320 | } |
Jeff Thompson | f72b1ac | 2013-08-16 16:44:41 -0700 | [diff] [blame] | 321 | |
| 322 | /** |
Jeff Thompson | 0aa66f2 | 2013-09-23 13:02:13 -0700 | [diff] [blame] | 323 | * Append a new component, copying from value. |
Jeff Thompson | 26b0d79 | 2013-09-23 16:19:01 -0700 | [diff] [blame] | 324 | * @return This name so that you can chain calls to append. |
Jeff Thompson | f72b1ac | 2013-08-16 16:44:41 -0700 | [diff] [blame] | 325 | */ |
Jeff Thompson | 26b0d79 | 2013-09-23 16:19:01 -0700 | [diff] [blame] | 326 | Name& |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame] | 327 | append(const std::vector<uint8_t>& value) |
Jeff Thompson | 0f74345 | 2013-09-12 14:23:18 -0700 | [diff] [blame] | 328 | { |
| 329 | components_.push_back(value); |
Jeff Thompson | 26b0d79 | 2013-09-23 16:19:01 -0700 | [diff] [blame] | 330 | return *this; |
Jeff Thompson | 0f74345 | 2013-09-12 14:23:18 -0700 | [diff] [blame] | 331 | } |
| 332 | |
Jeff Thompson | 26b0d79 | 2013-09-23 16:19:01 -0700 | [diff] [blame] | 333 | Name& |
| 334 | append(const Blob &value) |
Jeff Thompson | 0f74345 | 2013-09-12 14:23:18 -0700 | [diff] [blame] | 335 | { |
Jeff Thompson | f72b1ac | 2013-08-16 16:44:41 -0700 | [diff] [blame] | 336 | components_.push_back(value); |
Jeff Thompson | 26b0d79 | 2013-09-23 16:19:01 -0700 | [diff] [blame] | 337 | return *this; |
Jeff Thompson | f72b1ac | 2013-08-16 16:44:41 -0700 | [diff] [blame] | 338 | } |
Jeff Thompson | e5f839b | 2013-06-28 12:50:38 -0700 | [diff] [blame] | 339 | |
Jeff Thompson | 21eb721 | 2013-09-26 09:05:40 -0700 | [diff] [blame] | 340 | Name& |
| 341 | append(const Component &value) |
| 342 | { |
| 343 | components_.push_back(value); |
| 344 | return *this; |
| 345 | } |
| 346 | |
Jeff Thompson | e5f839b | 2013-06-28 12:50:38 -0700 | [diff] [blame] | 347 | /** |
Jeff Thompson | 26b0d79 | 2013-09-23 16:19:01 -0700 | [diff] [blame] | 348 | * Append the components of the given name to this name. |
| 349 | * @param name The Name with components to append. |
| 350 | * @return This name so that you can chain calls to append. |
Jeff Thompson | 0aa66f2 | 2013-09-23 13:02:13 -0700 | [diff] [blame] | 351 | */ |
Jeff Thompson | 26b0d79 | 2013-09-23 16:19:01 -0700 | [diff] [blame] | 352 | Name& |
| 353 | append(const Name& name); |
| 354 | |
| 355 | /** |
| 356 | * @deprecated Use append. |
| 357 | */ |
| 358 | Name& |
Jeff Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame] | 359 | appendComponent(const uint8_t *value, size_t valueLength) |
Jeff Thompson | 0aa66f2 | 2013-09-23 13:02:13 -0700 | [diff] [blame] | 360 | { |
Jeff Thompson | 26b0d79 | 2013-09-23 16:19:01 -0700 | [diff] [blame] | 361 | return append(value, valueLength); |
Jeff Thompson | 0aa66f2 | 2013-09-23 13:02:13 -0700 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | /** |
Jeff Thompson | 26b0d79 | 2013-09-23 16:19:01 -0700 | [diff] [blame] | 365 | * @deprecated Use append. |
Jeff Thompson | 0aa66f2 | 2013-09-23 13:02:13 -0700 | [diff] [blame] | 366 | */ |
Jeff Thompson | 26b0d79 | 2013-09-23 16:19:01 -0700 | [diff] [blame] | 367 | Name& |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame] | 368 | appendComponent(const std::vector<uint8_t>& value) |
Jeff Thompson | 0aa66f2 | 2013-09-23 13:02:13 -0700 | [diff] [blame] | 369 | { |
Jeff Thompson | 26b0d79 | 2013-09-23 16:19:01 -0700 | [diff] [blame] | 370 | return append(value); |
Jeff Thompson | 0aa66f2 | 2013-09-23 13:02:13 -0700 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | /** |
Jeff Thompson | 26b0d79 | 2013-09-23 16:19:01 -0700 | [diff] [blame] | 374 | * @deprecated Use append. |
Jeff Thompson | 0aa66f2 | 2013-09-23 13:02:13 -0700 | [diff] [blame] | 375 | */ |
Jeff Thompson | 26b0d79 | 2013-09-23 16:19:01 -0700 | [diff] [blame] | 376 | Name& |
| 377 | appendComponent(const Blob &value) |
| 378 | { |
| 379 | return append(value); |
| 380 | } |
| 381 | |
| 382 | /** |
| 383 | * @deprecated Use append. |
| 384 | */ |
| 385 | Name& |
Jeff Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame] | 386 | addComponent(const uint8_t *value, size_t valueLength) |
Jeff Thompson | 26b0d79 | 2013-09-23 16:19:01 -0700 | [diff] [blame] | 387 | { |
| 388 | return append(value, valueLength); |
| 389 | } |
| 390 | |
| 391 | /** |
| 392 | * @deprecated Use append. |
| 393 | */ |
| 394 | Name& |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame] | 395 | addComponent(const std::vector<uint8_t>& value) |
Jeff Thompson | 26b0d79 | 2013-09-23 16:19:01 -0700 | [diff] [blame] | 396 | { |
| 397 | return append(value); |
| 398 | } |
| 399 | |
| 400 | /** |
| 401 | * @deprecated Use append. |
| 402 | */ |
| 403 | Name& |
Jeff Thompson | 0aa66f2 | 2013-09-23 13:02:13 -0700 | [diff] [blame] | 404 | addComponent(const Blob &value) |
| 405 | { |
Jeff Thompson | 26b0d79 | 2013-09-23 16:19:01 -0700 | [diff] [blame] | 406 | return append(value); |
Jeff Thompson | 0aa66f2 | 2013-09-23 13:02:13 -0700 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | /** |
Jeff Thompson | e5f839b | 2013-06-28 12:50:38 -0700 | [diff] [blame] | 410 | * Clear all the components. |
| 411 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 412 | void |
| 413 | clear() { |
Jeff Thompson | e5f839b | 2013-06-28 12:50:38 -0700 | [diff] [blame] | 414 | components_.clear(); |
| 415 | } |
| 416 | |
| 417 | /** |
Jeff Thompson | eba62eb | 2013-10-30 13:24:22 -0700 | [diff] [blame] | 418 | * @deprecated use size(). |
Jeff Thompson | e5f839b | 2013-06-28 12:50:38 -0700 | [diff] [blame] | 419 | */ |
Jeff Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame] | 420 | size_t |
Jeff Thompson | eba62eb | 2013-10-30 13:24:22 -0700 | [diff] [blame] | 421 | getComponentCount() const { return size(); } |
Jeff Thompson | e5f839b | 2013-06-28 12:50:38 -0700 | [diff] [blame] | 422 | |
Jeff Thompson | ec39fbd | 2013-10-04 10:56:23 -0700 | [diff] [blame] | 423 | /** |
Jeff Thompson | eba62eb | 2013-10-30 13:24:22 -0700 | [diff] [blame] | 424 | * @deprecated Use get(i). |
Jeff Thompson | ec39fbd | 2013-10-04 10:56:23 -0700 | [diff] [blame] | 425 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 426 | const Component& |
Jeff Thompson | eba62eb | 2013-10-30 13:24:22 -0700 | [diff] [blame] | 427 | getComponent(size_t i) const { return get(i); } |
Jeff Thompson | 443398d | 2013-07-02 19:45:46 -0700 | [diff] [blame] | 428 | |
Jeff Thompson | e606351 | 2013-07-01 15:11:28 -0700 | [diff] [blame] | 429 | /** |
Jeff Thompson | d0159d7 | 2013-09-23 13:34:15 -0700 | [diff] [blame] | 430 | * Get a new name, constructed as a subset of components. |
| 431 | * @param iStartComponent The index if the first component to get. |
| 432 | * @param nComponents The number of components starting at iStartComponent. |
| 433 | * @return A new name. |
| 434 | */ |
| 435 | Name |
| 436 | getSubName(size_t iStartComponent, size_t nComponents) const; |
| 437 | |
| 438 | /** |
| 439 | * Get a new name, constructed as a subset of components starting at iStartComponent until the end of the name. |
| 440 | * @param iStartComponent The index if the first component to get. |
| 441 | * @return A new name. |
| 442 | */ |
| 443 | Name |
| 444 | getSubName(size_t iStartComponent) const; |
| 445 | |
| 446 | /** |
| 447 | * Return a new Name with the first nComponents components of this Name. |
Jeff Thompson | eb0358f | 2013-12-17 10:59:53 -0800 | [diff] [blame] | 448 | * @param nComponents The number of prefix components. If nComponents is -N then return the prefix up |
| 449 | * to name.size() - N. For example getPrefix(-1) returns the name without the final component. |
Jeff Thompson | d0159d7 | 2013-09-23 13:34:15 -0700 | [diff] [blame] | 450 | * @return A new Name. |
| 451 | */ |
| 452 | Name |
Jeff Thompson | eb0358f | 2013-12-17 10:59:53 -0800 | [diff] [blame] | 453 | getPrefix(int nComponents) const |
Jeff Thompson | d0159d7 | 2013-09-23 13:34:15 -0700 | [diff] [blame] | 454 | { |
Jeff Thompson | eb0358f | 2013-12-17 10:59:53 -0800 | [diff] [blame] | 455 | if (nComponents < 0) |
| 456 | return getSubName(0, components_.size() + nComponents); |
| 457 | else |
| 458 | return getSubName(0, nComponents); |
Jeff Thompson | d0159d7 | 2013-09-23 13:34:15 -0700 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | /** |
Jeff Thompson | e606351 | 2013-07-01 15:11:28 -0700 | [diff] [blame] | 462 | * Encode this name as a URI. |
Jeff Thompson | 3f2175b | 2013-07-31 17:12:47 -0700 | [diff] [blame] | 463 | * @return The encoded URI. |
Jeff Thompson | e606351 | 2013-07-01 15:11:28 -0700 | [diff] [blame] | 464 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 465 | std::string |
| 466 | toUri() const; |
Jeff Thompson | e606351 | 2013-07-01 15:11:28 -0700 | [diff] [blame] | 467 | |
Jeff Thompson | 21844fc | 2013-08-08 14:52:51 -0700 | [diff] [blame] | 468 | /** |
| 469 | * @deprecated Use toUri(). |
| 470 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 471 | std::string |
| 472 | to_uri() const |
Jeff Thompson | 21844fc | 2013-08-08 14:52:51 -0700 | [diff] [blame] | 473 | { |
| 474 | return toUri(); |
| 475 | } |
Jeff Thompson | 26b0d79 | 2013-09-23 16:19:01 -0700 | [diff] [blame] | 476 | |
Jeff Thompson | 8aac199 | 2013-08-12 17:26:02 -0700 | [diff] [blame] | 477 | /** |
| 478 | * Append a component with the encoded segment number. |
| 479 | * @param segment The segment number. |
Jeff Thompson | 26b0d79 | 2013-09-23 16:19:01 -0700 | [diff] [blame] | 480 | * @return This name so that you can chain calls to append. |
| 481 | */ |
| 482 | Name& |
Jeff Thompson | d129ac1 | 2013-10-11 14:30:12 -0700 | [diff] [blame] | 483 | appendSegment(uint64_t segment) |
Jeff Thompson | 8aac199 | 2013-08-12 17:26:02 -0700 | [diff] [blame] | 484 | { |
Jeff Thompson | d129ac1 | 2013-10-11 14:30:12 -0700 | [diff] [blame] | 485 | components_.push_back(Component::fromNumberWithMarker(segment, 0x00)); |
| 486 | return *this; |
| 487 | } |
| 488 | |
| 489 | /** |
| 490 | * Append a component with the encoded version number. |
| 491 | * Note that this encodes the exact value of version without converting from a time representation. |
| 492 | * @param version The version number. |
| 493 | * @return This name so that you can chain calls to append. |
| 494 | */ |
| 495 | Name& |
| 496 | appendVersion(uint64_t version) |
| 497 | { |
| 498 | components_.push_back(Component::fromNumberWithMarker(version, 0xFD)); |
Jeff Thompson | 26b0d79 | 2013-09-23 16:19:01 -0700 | [diff] [blame] | 499 | return *this; |
Jeff Thompson | 8aac199 | 2013-08-12 17:26:02 -0700 | [diff] [blame] | 500 | } |
Jeff Thompson | cc35cd4 | 2013-08-20 12:23:14 -0700 | [diff] [blame] | 501 | |
Jeff Thompson | ec7789a | 2013-08-21 11:08:36 -0700 | [diff] [blame] | 502 | /** |
Jeff Thompson | 3c2ab01 | 2013-10-02 14:18:16 -0700 | [diff] [blame] | 503 | * Check if this name has the same component count and components as the given name. |
| 504 | * @param name The Name to check. |
| 505 | * @return true if the names are equal, otherwise false. |
| 506 | */ |
| 507 | bool |
| 508 | equals(const Name& name) const; |
| 509 | |
| 510 | /** |
Jeff Thompson | ec7789a | 2013-08-21 11:08:36 -0700 | [diff] [blame] | 511 | * Check if the N components of this name are the same as the first N components of the given name. |
| 512 | * @param name The Name to check. |
| 513 | * @return true if this matches the given name, otherwise false. This always returns true if this name is empty. |
| 514 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 515 | bool |
| 516 | match(const Name& name) const; |
Jeff Thompson | ec7789a | 2013-08-21 11:08:36 -0700 | [diff] [blame] | 517 | |
| 518 | /** |
Jeff Thompson | d8e53e6 | 2013-10-29 16:59:49 -0700 | [diff] [blame] | 519 | * Make a Blob value by decoding the escapedString between beginOffset and endOffset according to the NDN URI Scheme. |
Jeff Thompson | 0849359 | 2013-11-07 17:44:41 -0800 | [diff] [blame] | 520 | * If the escaped string is "", "." or ".." then return a Blob with a null pointer, |
| 521 | * which means the component should be skipped in a URI name. |
Jeff Thompson | d8e53e6 | 2013-10-29 16:59:49 -0700 | [diff] [blame] | 522 | * @param escapedString The escaped string. It does not need to be null-terminated because we only scan to endOffset. |
| 523 | * @param beginOffset The offset in escapedString of the beginning of the portion to decode. |
| 524 | * @param endOffset The offset in escapedString of the end of the portion to decode. |
| 525 | * @return The Blob value. If the escapedString is not a valid escaped component, then the Blob is a null pointer. |
| 526 | */ |
| 527 | static Blob |
| 528 | fromEscapedString(const char *escapedString, size_t beginOffset, size_t endOffset); |
| 529 | |
| 530 | /** |
| 531 | * Make a Blob value by decoding the escapedString according to the NDN URI Scheme. |
Jeff Thompson | 0849359 | 2013-11-07 17:44:41 -0800 | [diff] [blame] | 532 | * If the escaped string is "", "." or ".." then return a Blob with a null pointer, |
| 533 | * which means the component should be skipped in a URI name. |
Jeff Thompson | d8e53e6 | 2013-10-29 16:59:49 -0700 | [diff] [blame] | 534 | * @param escapedString The null-terminated escaped string. |
| 535 | * @return The Blob value. If the escapedString is not a valid escaped component, then the Blob is a null pointer. |
| 536 | */ |
| 537 | static Blob |
| 538 | fromEscapedString(const char *escapedString); |
| 539 | |
| 540 | /** |
Jeff Thompson | 7781b39 | 2013-12-17 11:45:59 -0800 | [diff] [blame] | 541 | * Make a Blob value by decoding the escapedString according to the NDN URI Scheme. |
| 542 | * If the escaped string is "", "." or ".." then return a Blob with a null pointer, |
| 543 | * which means the component should be skipped in a URI name. |
| 544 | * @param escapedString The escaped string. |
| 545 | * @return The Blob value. If the escapedString is not a valid escaped component, then the Blob is a null pointer. |
| 546 | */ |
| 547 | static Blob |
| 548 | fromEscapedString(const std::string& escapedString) { return fromEscapedString(escapedString.c_str()); } |
| 549 | |
| 550 | /** |
Jeff Thompson | ec7789a | 2013-08-21 11:08:36 -0700 | [diff] [blame] | 551 | * Write the value to result, escaping characters according to the NDN URI Scheme. |
| 552 | * This also adds "..." to a value with zero or more ".". |
| 553 | * @param value the buffer with the value to escape |
| 554 | * @param result the string stream to write to. |
| 555 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 556 | static void |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame] | 557 | toEscapedString(const std::vector<uint8_t>& value, std::ostringstream& result); |
Jeff Thompson | 21844fc | 2013-08-08 14:52:51 -0700 | [diff] [blame] | 558 | |
Jeff Thompson | 6653b0b | 2013-09-23 12:32:39 -0700 | [diff] [blame] | 559 | /** |
| 560 | * Convert the value by escaping characters according to the NDN URI Scheme. |
| 561 | * This also adds "..." to a value with zero or more ".". |
| 562 | * @param value the buffer with the value to escape |
| 563 | * @return The escaped string. |
| 564 | */ |
| 565 | static std::string |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame] | 566 | toEscapedString(const std::vector<uint8_t>& value); |
Jeff Thompson | 6653b0b | 2013-09-23 12:32:39 -0700 | [diff] [blame] | 567 | |
Jeff Thompson | ec39fbd | 2013-10-04 10:56:23 -0700 | [diff] [blame] | 568 | // |
| 569 | // vector equivalent interface. |
| 570 | // |
| 571 | |
| 572 | /** |
| 573 | * Get the number of components. |
| 574 | * @return The number of components. |
| 575 | */ |
| 576 | size_t |
Jeff Thompson | eba62eb | 2013-10-30 13:24:22 -0700 | [diff] [blame] | 577 | size() const { return components_.size(); } |
Jeff Thompson | ec39fbd | 2013-10-04 10:56:23 -0700 | [diff] [blame] | 578 | |
| 579 | /** |
| 580 | * Get the component at the given index. |
| 581 | * @param i The index of the component, starting from 0. |
| 582 | * @return The name component at the index. |
| 583 | */ |
| 584 | const Component& |
Alexander Afanasyev | 8f9aa8b | 2013-12-30 15:58:57 -0800 | [diff] [blame] | 585 | get(ssize_t i) const |
| 586 | { |
| 587 | if (i >= 0) |
| 588 | return components_[i]; |
| 589 | else |
| 590 | return components_[size() + i]; |
| 591 | } |
Jeff Thompson | ec39fbd | 2013-10-04 10:56:23 -0700 | [diff] [blame] | 592 | |
| 593 | |
| 594 | const Component& |
| 595 | operator [] (int i) const |
| 596 | { |
| 597 | return get(i); |
| 598 | } |
| 599 | |
| 600 | /** |
| 601 | * Append the component |
| 602 | * @param component The component of type T. |
| 603 | */ |
| 604 | template<class T> void |
| 605 | push_back(const T &component) |
| 606 | { |
| 607 | append(component); |
| 608 | } |
| 609 | |
Jeff Thompson | 91737f5 | 2013-10-04 11:07:24 -0700 | [diff] [blame] | 610 | /** |
| 611 | * Check if this name has the same component count and components as the given name. |
| 612 | * @param name The Name to check. |
| 613 | * @return true if the names are equal, otherwise false. |
| 614 | */ |
| 615 | bool |
| 616 | operator == (const Name &name) const { return equals(name); } |
| 617 | |
| 618 | /** |
| 619 | * Check if this name has the same component count and components as the given name. |
| 620 | * @param name The Name to check. |
| 621 | * @return true if the names are not equal, otherwise false. |
| 622 | */ |
| 623 | bool |
| 624 | operator != (const Name &name) const { return !equals(name); } |
| 625 | |
Jeff Thompson | 82568ad | 2013-12-17 15:17:40 -0800 | [diff] [blame] | 626 | /** |
| 627 | * Compare two names for "less than" using breadth first. If the first components of each name are not equal, |
| 628 | * this returns true if the first comes before the second using the NDN canonical ordering for name components. |
| 629 | * If they are equal, this compares the second components of each name, etc. If both names are the same up to |
| 630 | * the size of the shorter name, this returns true if the first name is shorter than the second. For example, if you |
| 631 | * use breadthFirstLess in std::sort, it gives: /a/b/d /a/b/cc /c /c/a /bb . This is intuitive because all names |
| 632 | * with the prefix /a are next to each other. But it may be also be counter-intuitive because /c comes before /bb |
| 633 | * according to NDN canonical ordering since it is shorter. Note: We don't define this directly as the Name |
| 634 | * less than operation because there are other valid ways to sort names. |
| 635 | * @param name1 The first name to compare. |
| 636 | * @param name2 The second name to compare. |
| 637 | * @return True if the first name is less than the second using breadth first comparison. |
| 638 | */ |
| 639 | static bool |
| 640 | breadthFirstLess(const Name& name1, const Name& name2); |
| 641 | |
| 642 | /** |
| 643 | * Name::BreadthFirstLess is a function object which calls breadthFirstLess, for use as the "less" operator in map, etc. |
| 644 | * For example, you can use Name as the key type in a map as follows: map<Name, int, Name::BreadthFirstLess>. |
| 645 | */ |
| 646 | struct BreadthFirstLess { |
| 647 | bool operator() (const Name& name1, const Name& name2) const { return breadthFirstLess(name1, name2); } |
| 648 | }; |
| 649 | |
Jeff Thompson | ec39fbd | 2013-10-04 10:56:23 -0700 | [diff] [blame] | 650 | // |
| 651 | // Iterator interface to name components. |
| 652 | // |
| 653 | typedef std::vector<Component>::iterator iterator; |
| 654 | typedef std::vector<Component>::const_iterator const_iterator; |
| 655 | typedef std::vector<Component>::reverse_iterator reverse_iterator; |
| 656 | typedef std::vector<Component>::const_reverse_iterator const_reverse_iterator; |
| 657 | typedef std::vector<Component>::reference reference; |
| 658 | typedef std::vector<Component>::const_reference const_reference; |
| 659 | |
| 660 | typedef Component partial_type; |
| 661 | |
| 662 | /** |
| 663 | * Begin iterator (const). |
| 664 | */ |
| 665 | const_iterator |
Jeff Thompson | 91737f5 | 2013-10-04 11:07:24 -0700 | [diff] [blame] | 666 | begin() const { return components_.begin(); } |
Jeff Thompson | ec39fbd | 2013-10-04 10:56:23 -0700 | [diff] [blame] | 667 | |
| 668 | /** |
| 669 | * Begin iterator. |
| 670 | */ |
| 671 | iterator |
Jeff Thompson | 91737f5 | 2013-10-04 11:07:24 -0700 | [diff] [blame] | 672 | begin() { return components_.begin(); } |
Jeff Thompson | ec39fbd | 2013-10-04 10:56:23 -0700 | [diff] [blame] | 673 | |
| 674 | /** |
| 675 | * End iterator (const). |
| 676 | */ |
| 677 | const_iterator |
Jeff Thompson | 91737f5 | 2013-10-04 11:07:24 -0700 | [diff] [blame] | 678 | end() const { return components_.end(); } |
Jeff Thompson | ec39fbd | 2013-10-04 10:56:23 -0700 | [diff] [blame] | 679 | |
| 680 | /** |
| 681 | * End iterator. |
| 682 | */ |
| 683 | iterator |
Jeff Thompson | 91737f5 | 2013-10-04 11:07:24 -0700 | [diff] [blame] | 684 | end() { return components_.end(); } |
Jeff Thompson | ec39fbd | 2013-10-04 10:56:23 -0700 | [diff] [blame] | 685 | |
| 686 | /** |
| 687 | * Reverse begin iterator (const). |
| 688 | */ |
| 689 | const_reverse_iterator |
Jeff Thompson | 91737f5 | 2013-10-04 11:07:24 -0700 | [diff] [blame] | 690 | rbegin() const { return components_.rbegin(); } |
Jeff Thompson | ec39fbd | 2013-10-04 10:56:23 -0700 | [diff] [blame] | 691 | |
| 692 | /** |
| 693 | * Reverse begin iterator. |
| 694 | */ |
| 695 | reverse_iterator |
Jeff Thompson | 91737f5 | 2013-10-04 11:07:24 -0700 | [diff] [blame] | 696 | rbegin() { return components_.rbegin(); } |
Jeff Thompson | ec39fbd | 2013-10-04 10:56:23 -0700 | [diff] [blame] | 697 | |
| 698 | /** |
| 699 | * Reverse end iterator (const). |
| 700 | */ |
| 701 | const_reverse_iterator |
Jeff Thompson | 91737f5 | 2013-10-04 11:07:24 -0700 | [diff] [blame] | 702 | rend() const { return components_.rend(); } |
Jeff Thompson | ec39fbd | 2013-10-04 10:56:23 -0700 | [diff] [blame] | 703 | |
| 704 | /** |
| 705 | * Reverse end iterator. |
| 706 | */ |
| 707 | reverse_iterator |
Jeff Thompson | 91737f5 | 2013-10-04 11:07:24 -0700 | [diff] [blame] | 708 | rend() { return components_.rend(); } |
Jeff Thompson | ec39fbd | 2013-10-04 10:56:23 -0700 | [diff] [blame] | 709 | |
Jeff Thompson | 9c41dfe | 2013-06-27 12:10:25 -0700 | [diff] [blame] | 710 | private: |
Jeff Thompson | 5a6b5ab | 2013-08-05 15:43:47 -0700 | [diff] [blame] | 711 | std::vector<Component> components_; |
Jeff Thompson | 9c41dfe | 2013-06-27 12:10:25 -0700 | [diff] [blame] | 712 | }; |
| 713 | |
Jeff Thompson | 49e321a | 2013-10-04 17:35:59 -0700 | [diff] [blame] | 714 | inline std::ostream& |
| 715 | operator << (std::ostream& os, const Name& name) |
| 716 | { |
| 717 | os << name.toUri(); |
| 718 | return os; |
| 719 | } |
| 720 | |
Jeff Thompson | 9c41dfe | 2013-06-27 12:10:25 -0700 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | #endif |
| 724 | |