Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 1 | .. _Name: |
| 2 | |
| 3 | Name Class |
| 4 | ========== |
| 5 | |
| 6 | A Name holds an array of Name.Component and represents an NDN name. |
| 7 | |
| 8 | :[C++]: |
| 9 | Namespace: ``ndn`` |
| 10 | |
| 11 | :[Python]: |
| 12 | Module: ``pyndn`` |
| 13 | |
Alexander Afanasyev | 06e798c | 2013-11-26 19:10:29 -0800 | [diff] [blame] | 14 | Name Constructors |
| 15 | ----------------- |
| 16 | |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 17 | Name Constructor (array of components) |
Alexander Afanasyev | 06e798c | 2013-11-26 19:10:29 -0800 | [diff] [blame] | 18 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 19 | |
| 20 | Create a new Name with the optional components. |
| 21 | |
| 22 | :[C++]: |
| 23 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 24 | .. code-block:: c++ |
| 25 | |
| 26 | Name( |
| 27 | [const std::vector<Name::Component>& components] |
| 28 | ); |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 29 | |
| 30 | :[JavaScript]: |
| 31 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 32 | .. code-block:: javascript |
| 33 | |
| 34 | var Name = function Name ( |
| 35 | [components // Array<Uint8Array>] |
| 36 | ) |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 37 | |
| 38 | :[Python]: |
| 39 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 40 | .. code-block:: python |
| 41 | |
| 42 | def __init__(self |
| 43 | [, components // Array<string>] |
| 44 | ) |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 45 | |
| 46 | :Parameters: |
| 47 | |
| 48 | - ``components`` |
Alexander Afanasyev | 06e798c | 2013-11-26 19:10:29 -0800 | [diff] [blame] | 49 | (optional) The array of :ref:`name components <Name.Component>`. |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 50 | |
| 51 | Name Constructor (from URI) |
Alexander Afanasyev | 06e798c | 2013-11-26 19:10:29 -0800 | [diff] [blame] | 52 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 53 | |
| 54 | Parse the uri according to the NDN URI Scheme and create the Name with the components. |
| 55 | |
| 56 | :[C++]: |
| 57 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 58 | .. code-block:: c++ |
| 59 | |
| 60 | Name( |
| 61 | const char* uri |
| 62 | ); |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 63 | |
| 64 | :[JavaScript]: |
| 65 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 66 | .. code-block:: javascript |
| 67 | |
| 68 | var Name = function Name ( |
| 69 | uri // string |
| 70 | ) |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 71 | |
| 72 | :Parameters: |
| 73 | |
| 74 | - ``uri`` |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 75 | The URI in NDN URI Scheme. |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 76 | |
| 77 | Name.toUri Method |
| 78 | ----------------- |
| 79 | |
| 80 | Return the escaped name string according to the NDN URI Scheme. |
| 81 | |
| 82 | :[C++]: |
| 83 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 84 | .. code-block:: c++ |
| 85 | |
| 86 | std::string toUri() const (); |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 87 | |
| 88 | :[JavaScript]: |
| 89 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 90 | .. code-block:: javascript |
| 91 | |
| 92 | // Returns string |
| 93 | Name.prototype.toUri = function(); |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 94 | |
| 95 | :Returns: |
| 96 | |
| 97 | The escaped name string according to the NDN URI Scheme. |
| 98 | |
| 99 | Name.size Method |
| 100 | ---------------- |
| 101 | |
| 102 | Get the number of components. |
| 103 | |
| 104 | :[C++]: |
| 105 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 106 | .. code-block:: c++ |
| 107 | |
| 108 | size_t getComponentCount() const; |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 109 | |
| 110 | :Returns: |
| 111 | |
| 112 | The number of components. |
| 113 | |
| 114 | Name.get Method |
| 115 | --------------- |
| 116 | |
| 117 | Get a Name Component by index number. |
| 118 | |
| 119 | :[C++]: |
| 120 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 121 | .. code-block:: c++ |
| 122 | |
| 123 | const Component& getComponent( |
| 124 | size_t i |
| 125 | ) const; |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 126 | |
| 127 | :Parameters: |
| 128 | |
| 129 | - ``i`` |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 130 | The index of the component to get, starting from 0. |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 131 | |
| 132 | :Returns: |
| 133 | |
| 134 | The Name.Component. |
| 135 | |
| 136 | Name.getPrefix Method |
| 137 | --------------------- |
| 138 | |
| 139 | Get a new Name with the first nComponents components of this Name. |
| 140 | |
| 141 | :[C++]: |
| 142 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 143 | .. code-block:: c++ |
| 144 | |
| 145 | Name getPrefix( |
| 146 | size_t nComponents |
| 147 | ) const; |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 148 | |
| 149 | :[JavaScript]: |
| 150 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 151 | .. code-block:: javascript |
| 152 | |
| 153 | // Returns Name |
| 154 | Name.prototype.getPrefix = function( |
| 155 | nComponents // Number |
| 156 | ); |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 157 | |
| 158 | :Parameters: |
| 159 | |
| 160 | - nComponents |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 161 | The number of prefix components. If larger than the number of components in this name, return a copy of this Name. |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 162 | |
| 163 | :Returns: |
| 164 | |
| 165 | A new Name. |
| 166 | |
| 167 | Name.getSubName Method |
| 168 | ---------------------- |
| 169 | |
| 170 | Get a new name, constructed as a subset of components. |
| 171 | |
| 172 | :[C++]: |
| 173 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 174 | .. code-block:: c++ |
| 175 | |
| 176 | Name getSubName( |
| 177 | size_t iStartComponent |
| 178 | [, size_t nComponents] |
| 179 | ) const; |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 180 | |
| 181 | :Parameters: |
| 182 | |
| 183 | - ``iStartComponent`` |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 184 | The index if the first component to get. |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 185 | |
| 186 | - ``nComponents`` |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 187 | (optional) The number of components starting at iStartComponent. If omitted, return components until the end of the name. |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 188 | |
| 189 | :Returns: |
| 190 | |
| 191 | A new Name. |
| 192 | |
| 193 | Name.match Method |
| 194 | ----------------- |
| 195 | |
| 196 | Check if the N components of this name are the same as the first N components of the given name. |
| 197 | |
| 198 | :[C++]: |
| 199 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 200 | .. code-block:: c++ |
| 201 | |
| 202 | bool match( |
| 203 | const Name& name |
| 204 | ) const; |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 205 | |
| 206 | :[JavaScript]: |
| 207 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 208 | .. code-block:: javascript |
| 209 | |
| 210 | // Returns boolean |
| 211 | Name.prototype.match = function( |
| 212 | name // Name |
| 213 | ); |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 214 | |
| 215 | :Parameters: |
| 216 | |
| 217 | - ``name`` |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 218 | The Name to check. |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 219 | |
| 220 | - ``nComponents`` |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 221 | The number of components starting at iStartComponent. If omitted, return components until the end of the name. |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 222 | |
| 223 | :Returns: |
| 224 | |
| 225 | true if this matches the given name, otherwise false. This always returns true if this name is empty. |
| 226 | |
Alexander Afanasyev | 06e798c | 2013-11-26 19:10:29 -0800 | [diff] [blame] | 227 | Name.append Methods |
| 228 | ------------------- |
| 229 | |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 230 | Name.append Method (copy byte array) |
Alexander Afanasyev | 06e798c | 2013-11-26 19:10:29 -0800 | [diff] [blame] | 231 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 232 | |
| 233 | Append a new component, copying from byte array. |
| 234 | |
| 235 | :[C++]: |
| 236 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 237 | .. code-block:: c++ |
| 238 | |
| 239 | Name& append( |
| 240 | const std::vector<uint8_t>& value |
| 241 | ); |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 242 | |
| 243 | :[JavaScript]: |
| 244 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 245 | .. code-block:: javascript |
| 246 | |
| 247 | // Returns this Name |
| 248 | Name.prototype.append = function( |
| 249 | value // Array<number>|ArrayBuffer|Uint8Array |
| 250 | ) |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 251 | |
| 252 | :Parameters: |
| 253 | |
| 254 | - ``value`` |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 255 | The component byte array to copy. |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 256 | |
| 257 | :Returns: |
| 258 | |
| 259 | This name so that you can chain calls to append. |
| 260 | |
| 261 | Name.append Method (from Blob) |
Alexander Afanasyev | 06e798c | 2013-11-26 19:10:29 -0800 | [diff] [blame] | 262 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 263 | |
| 264 | Append a new component, taking another pointer to the byte array in the Blob. |
| 265 | |
| 266 | :[C++]: |
| 267 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 268 | .. code-block:: c++ |
| 269 | |
| 270 | Name& append( |
| 271 | const Blob& value |
| 272 | ); |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 273 | |
| 274 | :Parameters: |
| 275 | |
| 276 | - ``value`` |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 277 | The Blob with the pointer to the byte array. |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 278 | |
| 279 | :Returns: |
| 280 | |
| 281 | This name so that you can chain calls to append. |
| 282 | |
| 283 | Name.append Method (from Component) |
Alexander Afanasyev | 06e798c | 2013-11-26 19:10:29 -0800 | [diff] [blame] | 284 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 285 | |
| 286 | Append the component to this name. |
| 287 | |
| 288 | :[C++]: |
| 289 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 290 | .. code-block:: c++ |
| 291 | |
| 292 | Name& append( |
| 293 | const Name::Component& value |
| 294 | ); |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 295 | |
| 296 | :Parameters: |
| 297 | |
| 298 | - ``value`` |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 299 | The Name.Component to append. |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 300 | |
| 301 | :Returns: |
| 302 | |
| 303 | This name so that you can chain calls to append. |
| 304 | |
| 305 | Name.append Method (from Name) |
Alexander Afanasyev | 06e798c | 2013-11-26 19:10:29 -0800 | [diff] [blame] | 306 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 307 | |
| 308 | Append the components of the given name to this name. |
| 309 | |
| 310 | :[C++]: |
| 311 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 312 | .. code-block:: c++ |
| 313 | |
| 314 | Name& append( |
| 315 | const Name& name |
| 316 | ); |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 317 | |
| 318 | :[JavaScript]: |
| 319 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 320 | .. code-block:: javascript |
| 321 | |
| 322 | // Returns this Name |
| 323 | Name.prototype.append = function( |
| 324 | value // Name |
| 325 | ) |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 326 | |
| 327 | :Parameters: |
| 328 | |
| 329 | - ``name`` |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 330 | The Name with components to append. |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 331 | |
| 332 | :Returns: |
| 333 | |
| 334 | This name so that you can chain calls to append. |
| 335 | |
| 336 | Name.appendSegment Method |
| 337 | ------------------------- |
| 338 | |
| 339 | Append a component with the encoded segment number. |
| 340 | |
| 341 | :[C++]: |
| 342 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 343 | .. code-block:: c++ |
| 344 | |
| 345 | Name& appendSegment( |
| 346 | uint64_t segment |
| 347 | ); |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 348 | |
| 349 | :[JavaScript]: |
| 350 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 351 | .. code-block:: javascript |
| 352 | |
| 353 | // Returns this Name |
| 354 | Name.prototype.appendSegment = function( |
| 355 | segment // Number |
| 356 | ) |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 357 | |
| 358 | :Parameters: |
| 359 | |
| 360 | - ``segment`` |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 361 | The integer segment number to be encoded. |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 362 | |
| 363 | :Returns: |
| 364 | |
| 365 | This name so that you can chain calls to append. |
| 366 | |
| 367 | Name.appendVersion Method |
| 368 | ------------------------- |
| 369 | |
| 370 | Append a component with the encoded version number. Note that this encodes the exact value of version without converting from a time representation. |
| 371 | |
| 372 | :[C++]: |
| 373 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 374 | .. code-block:: c++ |
| 375 | |
| 376 | Name& appendVersion( |
| 377 | uint64_t version |
| 378 | ); |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 379 | |
| 380 | :Parameters: |
| 381 | |
| 382 | - ``version`` |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 383 | The version number to be encoded. |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 384 | |
| 385 | :Returns: |
| 386 | |
| 387 | This name so that you can chain calls to append. |
| 388 | |
| 389 | Other Name getter and setter methods |
| 390 | ------------------------------------ |
| 391 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 392 | :[JavaScript]: |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 393 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 394 | .. code-block:: javascript |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 395 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 396 | // Returns a new Name |
| 397 | Name.prototype.cut = function( |
| 398 | minusComponents // number |
| 399 | ) |
| 400 | |
| 401 | // Returns number |
| 402 | Name.prototype.indexOfFileName = function() |
| 403 | |
| 404 | // Returns Boolean |
| 405 | Name.prototype.equalsName = function( |
| 406 | name // Name |
| 407 | ) |