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