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