Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [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 | /** |
Junxiao Shi | a6452ac | 2015-01-23 11:21:06 -0700 | [diff] [blame] | 3 | * Copyright (c) 2013-2015 Regents of the University of California. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 6 | * |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 20 | * |
| 21 | * @author Jeff Thompson <jefft0@remap.ucla.edu> |
| 22 | * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html> |
| 23 | * @author Zhenkai Zhu <http://irl.cs.ucla.edu/~zhenkai/> |
Jeff Thompson | 9c41dfe | 2013-06-27 12:10:25 -0700 | [diff] [blame] | 24 | */ |
| 25 | |
| 26 | #ifndef NDN_NAME_HPP |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 27 | #define NDN_NAME_HPP |
Jeff Thompson | 9c41dfe | 2013-06-27 12:10:25 -0700 | [diff] [blame] | 28 | |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 29 | #include "common.hpp" |
| 30 | #include "name-component.hpp" |
Jeff Thompson | 25b4e61 | 2013-10-10 16:03:24 -0700 | [diff] [blame] | 31 | |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 32 | #include <boost/iterator/reverse_iterator.hpp> |
| 33 | |
Jeff Thompson | 9c41dfe | 2013-06-27 12:10:25 -0700 | [diff] [blame] | 34 | namespace ndn { |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 35 | |
Jeff Thompson | c7d6550 | 2013-11-06 17:22:26 -0800 | [diff] [blame] | 36 | /** |
Alexander Afanasyev | c89efb4 | 2015-02-10 18:26:42 -0800 | [diff] [blame^] | 37 | * @brief A Name holds an array of name::Component and represents an NDN name |
Jeff Thompson | c7d6550 | 2013-11-06 17:22:26 -0800 | [diff] [blame] | 38 | */ |
Alexander Afanasyev | f73f063 | 2014-05-12 18:02:37 -0700 | [diff] [blame] | 39 | class Name : public enable_shared_from_this<Name> |
Alexander Afanasyev | 2a7f720 | 2014-04-23 14:25:29 -0700 | [diff] [blame] | 40 | { |
Jeff Thompson | 9c41dfe | 2013-06-27 12:10:25 -0700 | [diff] [blame] | 41 | public: |
Alexander Afanasyev | 2a7f720 | 2014-04-23 14:25:29 -0700 | [diff] [blame] | 42 | /// @brief Error that can be thrown from Name |
| 43 | class Error : public name::Component::Error |
| 44 | { |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame] | 45 | public: |
Alexander Afanasyev | 2a7f720 | 2014-04-23 14:25:29 -0700 | [diff] [blame] | 46 | explicit |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame] | 47 | Error(const std::string& what) |
Alexander Afanasyev | 2a7f720 | 2014-04-23 14:25:29 -0700 | [diff] [blame] | 48 | : name::Component::Error(what) |
| 49 | { |
| 50 | } |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame] | 51 | }; |
Alexander Afanasyev | af283d8 | 2014-01-03 13:23:34 -0800 | [diff] [blame] | 52 | |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 53 | typedef name::Component Component; |
| 54 | |
| 55 | typedef std::vector<Component> component_container; |
| 56 | |
| 57 | typedef Component value_type; |
| 58 | typedef void allocator_type; |
| 59 | typedef Component& reference; |
| 60 | typedef const Component const_reference; |
| 61 | typedef Component* pointer; |
| 62 | typedef const Component* const_pointer; |
| 63 | typedef Component* iterator; |
| 64 | typedef const Component* const_iterator; |
Alexander Afanasyev | 4b98e8c | 2014-03-22 19:10:19 -0700 | [diff] [blame] | 65 | |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 66 | typedef boost::reverse_iterator<iterator> reverse_iterator; |
| 67 | typedef boost::reverse_iterator<const_iterator> const_reverse_iterator; |
| 68 | |
| 69 | typedef component_container::difference_type difference_type; |
| 70 | typedef component_container::size_type size_type; |
Alexander Afanasyev | 4b98e8c | 2014-03-22 19:10:19 -0700 | [diff] [blame] | 71 | |
Jeff Thompson | 443398d | 2013-07-02 19:45:46 -0700 | [diff] [blame] | 72 | /** |
Alexander Afanasyev | c89efb4 | 2015-02-10 18:26:42 -0800 | [diff] [blame^] | 73 | * @brief Create a new Name with no components. |
Jeff Thompson | 443398d | 2013-07-02 19:45:46 -0700 | [diff] [blame] | 74 | */ |
Alexander Afanasyev | c89efb4 | 2015-02-10 18:26:42 -0800 | [diff] [blame^] | 75 | Name(); |
Alexander Afanasyev | 52eb20d | 2014-02-06 18:25:54 -0800 | [diff] [blame] | 76 | |
| 77 | /** |
| 78 | * @brief Create Name object from wire block |
| 79 | * |
| 80 | * This is a more efficient equivalent for |
| 81 | * @code |
| 82 | * Name name; |
| 83 | * name.wireDecode(wire); |
| 84 | * @endcode |
| 85 | */ |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 86 | explicit |
Alexander Afanasyev | c89efb4 | 2015-02-10 18:26:42 -0800 | [diff] [blame^] | 87 | Name(const Block& wire); |
Alexander Afanasyev | 4b98e8c | 2014-03-22 19:10:19 -0700 | [diff] [blame] | 88 | |
Jeff Thompson | 3f2175b | 2013-07-31 17:12:47 -0700 | [diff] [blame] | 89 | /** |
Alexander Afanasyev | c89efb4 | 2015-02-10 18:26:42 -0800 | [diff] [blame^] | 90 | * @brief Create name from @p uri (NDN URI scheme) |
| 91 | * @param uri The null-terminated URI string |
Jeff Thompson | 443398d | 2013-07-02 19:45:46 -0700 | [diff] [blame] | 92 | */ |
Alexander Afanasyev | c89efb4 | 2015-02-10 18:26:42 -0800 | [diff] [blame^] | 93 | Name(const char* uri); |
Alexander Afanasyev | 4b98e8c | 2014-03-22 19:10:19 -0700 | [diff] [blame] | 94 | |
Jeff Thompson | e5f839b | 2013-06-28 12:50:38 -0700 | [diff] [blame] | 95 | /** |
Alexander Afanasyev | c89efb4 | 2015-02-10 18:26:42 -0800 | [diff] [blame^] | 96 | * @brief Create name from @p uri (NDN URI scheme) |
| 97 | * @param uri The URI string |
Jeff Thompson | 3549ef3 | 2013-09-25 14:05:17 -0700 | [diff] [blame] | 98 | */ |
Alexander Afanasyev | c89efb4 | 2015-02-10 18:26:42 -0800 | [diff] [blame^] | 99 | Name(const std::string& uri); |
Jeff Thompson | ec39fbd | 2013-10-04 10:56:23 -0700 | [diff] [blame] | 100 | |
Alexander Afanasyev | 380420b | 2014-02-09 20:52:29 -0800 | [diff] [blame] | 101 | /** |
| 102 | * @brief Fast encoding or block size estimation |
| 103 | */ |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame] | 104 | template<encoding::Tag TAG> |
Wentao Shang | 7794921 | 2014-02-01 23:42:24 -0800 | [diff] [blame] | 105 | size_t |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame] | 106 | wireEncode(EncodingImpl<TAG>& block) const; |
Alexander Afanasyev | 4b98e8c | 2014-03-22 19:10:19 -0700 | [diff] [blame] | 107 | |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame] | 108 | const Block& |
Alexander Afanasyev | af283d8 | 2014-01-03 13:23:34 -0800 | [diff] [blame] | 109 | wireEncode() const; |
Alexander Afanasyev | 848c61a | 2014-01-03 13:52:04 -0800 | [diff] [blame] | 110 | |
| 111 | void |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame] | 112 | wireDecode(const Block& wire); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 113 | |
| 114 | /** |
| 115 | * @brief Check if already has wire |
| 116 | */ |
| 117 | bool |
| 118 | hasWire() const; |
Alexander Afanasyev | 4b98e8c | 2014-03-22 19:10:19 -0700 | [diff] [blame] | 119 | |
Jeff Thompson | b468c31 | 2013-07-01 17:50:14 -0700 | [diff] [blame] | 120 | /** |
Alexander Afanasyev | c89efb4 | 2015-02-10 18:26:42 -0800 | [diff] [blame^] | 121 | * @deprecated Use appropriate constructor |
Jeff Thompson | 67515bd | 2013-08-15 17:43:22 -0700 | [diff] [blame] | 122 | */ |
Alexander Afanasyev | c89efb4 | 2015-02-10 18:26:42 -0800 | [diff] [blame^] | 123 | DEPRECATED( |
Alexander Afanasyev | 4b98e8c | 2014-03-22 19:10:19 -0700 | [diff] [blame] | 124 | void |
Alexander Afanasyev | c89efb4 | 2015-02-10 18:26:42 -0800 | [diff] [blame^] | 125 | set(const char* uri)); |
Jeff Thompson | 67515bd | 2013-08-15 17:43:22 -0700 | [diff] [blame] | 126 | |
| 127 | /** |
Alexander Afanasyev | c89efb4 | 2015-02-10 18:26:42 -0800 | [diff] [blame^] | 128 | * @deprecated Use appropriate constructor |
Jeff Thompson | 7781b39 | 2013-12-17 11:45:59 -0800 | [diff] [blame] | 129 | */ |
Alexander Afanasyev | c89efb4 | 2015-02-10 18:26:42 -0800 | [diff] [blame^] | 130 | DEPRECATED( |
Alexander Afanasyev | 4b98e8c | 2014-03-22 19:10:19 -0700 | [diff] [blame] | 131 | void |
Alexander Afanasyev | c89efb4 | 2015-02-10 18:26:42 -0800 | [diff] [blame^] | 132 | set(const std::string& uri)); |
Alexander Afanasyev | 4b98e8c | 2014-03-22 19:10:19 -0700 | [diff] [blame] | 133 | |
Jeff Thompson | 7781b39 | 2013-12-17 11:45:59 -0800 | [diff] [blame] | 134 | /** |
Alexander Afanasyev | c89efb4 | 2015-02-10 18:26:42 -0800 | [diff] [blame^] | 135 | * @brief Append a new component, copying from value of length valueLength. |
Jeff Thompson | 26b0d79 | 2013-09-23 16:19:01 -0700 | [diff] [blame] | 136 | * @return This name so that you can chain calls to append. |
Jeff Thompson | e5f839b | 2013-06-28 12:50:38 -0700 | [diff] [blame] | 137 | */ |
Alexander Afanasyev | 4b98e8c | 2014-03-22 19:10:19 -0700 | [diff] [blame] | 138 | Name& |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame] | 139 | append(const uint8_t* value, size_t valueLength) |
Jeff Thompson | 0f74345 | 2013-09-12 14:23:18 -0700 | [diff] [blame] | 140 | { |
Alexander Afanasyev | 29e5c3d | 2014-02-11 00:01:10 -0800 | [diff] [blame] | 141 | m_nameBlock.push_back(Component(value, valueLength)); |
Jeff Thompson | 26b0d79 | 2013-09-23 16:19:01 -0700 | [diff] [blame] | 142 | return *this; |
Jeff Thompson | e5f839b | 2013-06-28 12:50:38 -0700 | [diff] [blame] | 143 | } |
Jeff Thompson | f72b1ac | 2013-08-16 16:44:41 -0700 | [diff] [blame] | 144 | |
Alexander Afanasyev | bf9671d | 2014-02-11 13:44:13 -0800 | [diff] [blame] | 145 | /** |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame] | 146 | * @brief Append a new component, copying from value frome the range [@p first, @p last) of bytes |
| 147 | * @param first Iterator pointing to the beginning of the buffer |
| 148 | * @param last Iterator pointing to the ending of the buffer |
| 149 | * @tparam Iterator iterator type satisfying at least InputIterator concept. Implementation |
| 150 | * is more optimal when the iterator type satisfies RandomAccessIterator concept. |
| 151 | * It is required that sizeof(std::iterator_traits<Iterator>::value_type) == 1. |
Alexander Afanasyev | bf9671d | 2014-02-11 13:44:13 -0800 | [diff] [blame] | 152 | * @return This name so that you can chain calls to append. |
| 153 | */ |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame] | 154 | template<class Iterator> |
Alexander Afanasyev | bf9671d | 2014-02-11 13:44:13 -0800 | [diff] [blame] | 155 | Name& |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame] | 156 | append(Iterator first, Iterator last) |
Alexander Afanasyev | bf9671d | 2014-02-11 13:44:13 -0800 | [diff] [blame] | 157 | { |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame] | 158 | m_nameBlock.push_back(Component(first, last)); |
Alexander Afanasyev | bf9671d | 2014-02-11 13:44:13 -0800 | [diff] [blame] | 159 | return *this; |
| 160 | } |
| 161 | |
Alexander Afanasyev | c89efb4 | 2015-02-10 18:26:42 -0800 | [diff] [blame^] | 162 | /** |
| 163 | * @brief Append component @p value |
| 164 | */ |
Alexander Afanasyev | 4b98e8c | 2014-03-22 19:10:19 -0700 | [diff] [blame] | 165 | Name& |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame] | 166 | append(const Component& value) |
Jeff Thompson | 21eb721 | 2013-09-26 09:05:40 -0700 | [diff] [blame] | 167 | { |
Alexander Afanasyev | 29e5c3d | 2014-02-11 00:01:10 -0800 | [diff] [blame] | 168 | m_nameBlock.push_back(value); |
Jeff Thompson | 21eb721 | 2013-09-26 09:05:40 -0700 | [diff] [blame] | 169 | return *this; |
| 170 | } |
Alexander Afanasyev | af283d8 | 2014-01-03 13:23:34 -0800 | [diff] [blame] | 171 | |
Alexander Afanasyev | 594cdb2 | 2014-01-03 15:11:33 -0800 | [diff] [blame] | 172 | /** |
| 173 | * @brief Append name component that represented as a string |
| 174 | * |
| 175 | * Note that this method is necessary to ensure correctness and unambiguity of |
| 176 | * ``append("string")`` operations (both Component and Name can be implicitly |
| 177 | * converted from string, each having different outcomes |
| 178 | */ |
Alexander Afanasyev | 4b98e8c | 2014-03-22 19:10:19 -0700 | [diff] [blame] | 179 | Name& |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame] | 180 | append(const char* value) |
Alexander Afanasyev | 594cdb2 | 2014-01-03 15:11:33 -0800 | [diff] [blame] | 181 | { |
Alexander Afanasyev | 29e5c3d | 2014-02-11 00:01:10 -0800 | [diff] [blame] | 182 | m_nameBlock.push_back(Component(value)); |
Alexander Afanasyev | 594cdb2 | 2014-01-03 15:11:33 -0800 | [diff] [blame] | 183 | return *this; |
| 184 | } |
Alexander Afanasyev | 4b98e8c | 2014-03-22 19:10:19 -0700 | [diff] [blame] | 185 | |
Alexander Afanasyev | af283d8 | 2014-01-03 13:23:34 -0800 | [diff] [blame] | 186 | Name& |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame] | 187 | append(const Block& value) |
Alexander Afanasyev | af283d8 | 2014-01-03 13:23:34 -0800 | [diff] [blame] | 188 | { |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 189 | if (value.type() == tlv::NameComponent) |
Alexander Afanasyev | 29e5c3d | 2014-02-11 00:01:10 -0800 | [diff] [blame] | 190 | m_nameBlock.push_back(value); |
Alexander Afanasyev | 380420b | 2014-02-09 20:52:29 -0800 | [diff] [blame] | 191 | else |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 192 | m_nameBlock.push_back(Block(tlv::NameComponent, value)); |
Alexander Afanasyev | 380420b | 2014-02-09 20:52:29 -0800 | [diff] [blame] | 193 | |
Alexander Afanasyev | af283d8 | 2014-01-03 13:23:34 -0800 | [diff] [blame] | 194 | return *this; |
| 195 | } |
Alexander Afanasyev | 4b98e8c | 2014-03-22 19:10:19 -0700 | [diff] [blame] | 196 | |
Jeff Thompson | e5f839b | 2013-06-28 12:50:38 -0700 | [diff] [blame] | 197 | /** |
Jeff Thompson | 26b0d79 | 2013-09-23 16:19:01 -0700 | [diff] [blame] | 198 | * Append the components of the given name to this name. |
| 199 | * @param name The Name with components to append. |
| 200 | * @return This name so that you can chain calls to append. |
Jeff Thompson | 0aa66f2 | 2013-09-23 13:02:13 -0700 | [diff] [blame] | 201 | */ |
Jeff Thompson | 26b0d79 | 2013-09-23 16:19:01 -0700 | [diff] [blame] | 202 | Name& |
| 203 | append(const Name& name); |
Alexander Afanasyev | 4b98e8c | 2014-03-22 19:10:19 -0700 | [diff] [blame] | 204 | |
Jeff Thompson | 0aa66f2 | 2013-09-23 13:02:13 -0700 | [diff] [blame] | 205 | /** |
Jeff Thompson | e5f839b | 2013-06-28 12:50:38 -0700 | [diff] [blame] | 206 | * Clear all the components. |
| 207 | */ |
Alexander Afanasyev | 4b98e8c | 2014-03-22 19:10:19 -0700 | [diff] [blame] | 208 | void |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 209 | clear() |
| 210 | { |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 211 | m_nameBlock = Block(tlv::Name); |
Jeff Thompson | e5f839b | 2013-06-28 12:50:38 -0700 | [diff] [blame] | 212 | } |
Alexander Afanasyev | 4b98e8c | 2014-03-22 19:10:19 -0700 | [diff] [blame] | 213 | |
Jeff Thompson | e5f839b | 2013-06-28 12:50:38 -0700 | [diff] [blame] | 214 | /** |
Jeff Thompson | d0159d7 | 2013-09-23 13:34:15 -0700 | [diff] [blame] | 215 | * Get a new name, constructed as a subset of components. |
| 216 | * @param iStartComponent The index if the first component to get. |
| 217 | * @param nComponents The number of components starting at iStartComponent. |
Junxiao Shi | a6452ac | 2015-01-23 11:21:06 -0700 | [diff] [blame] | 218 | * Use npos to get the sub Name until the end of this Name. |
Jeff Thompson | d0159d7 | 2013-09-23 13:34:15 -0700 | [diff] [blame] | 219 | * @return A new name. |
| 220 | */ |
| 221 | Name |
Junxiao Shi | a6452ac | 2015-01-23 11:21:06 -0700 | [diff] [blame] | 222 | getSubName(size_t iStartComponent, size_t nComponents = npos) const; |
Alexander Afanasyev | 4b98e8c | 2014-03-22 19:10:19 -0700 | [diff] [blame] | 223 | |
Jeff Thompson | d0159d7 | 2013-09-23 13:34:15 -0700 | [diff] [blame] | 224 | /** |
Alexander Afanasyev | 15f6731 | 2014-07-22 15:11:09 -0700 | [diff] [blame] | 225 | * @brief Return a new Name with the first nComponents components of this Name. |
| 226 | * |
| 227 | * @param nComponents The number of prefix components. If nComponents is -N then return |
| 228 | * the prefix up to name.size() - N. For example getPrefix(-1) |
| 229 | * returns the name without the final component. |
Jeff Thompson | d0159d7 | 2013-09-23 13:34:15 -0700 | [diff] [blame] | 230 | * @return A new Name. |
| 231 | */ |
| 232 | Name |
Alexander Afanasyev | 15f6731 | 2014-07-22 15:11:09 -0700 | [diff] [blame] | 233 | getPrefix(ssize_t nComponents) const |
Jeff Thompson | d0159d7 | 2013-09-23 13:34:15 -0700 | [diff] [blame] | 234 | { |
Jeff Thompson | eb0358f | 2013-12-17 10:59:53 -0800 | [diff] [blame] | 235 | if (nComponents < 0) |
Alexander Afanasyev | 29e5c3d | 2014-02-11 00:01:10 -0800 | [diff] [blame] | 236 | return getSubName(0, m_nameBlock.elements_size() + nComponents); |
Jeff Thompson | eb0358f | 2013-12-17 10:59:53 -0800 | [diff] [blame] | 237 | else |
| 238 | return getSubName(0, nComponents); |
Jeff Thompson | d0159d7 | 2013-09-23 13:34:15 -0700 | [diff] [blame] | 239 | } |
Alexander Afanasyev | 4b98e8c | 2014-03-22 19:10:19 -0700 | [diff] [blame] | 240 | |
Jeff Thompson | d0159d7 | 2013-09-23 13:34:15 -0700 | [diff] [blame] | 241 | /** |
Jeff Thompson | e606351 | 2013-07-01 15:11:28 -0700 | [diff] [blame] | 242 | * Encode this name as a URI. |
Jeff Thompson | 3f2175b | 2013-07-31 17:12:47 -0700 | [diff] [blame] | 243 | * @return The encoded URI. |
Jeff Thompson | e606351 | 2013-07-01 15:11:28 -0700 | [diff] [blame] | 244 | */ |
Alexander Afanasyev | 4b98e8c | 2014-03-22 19:10:19 -0700 | [diff] [blame] | 245 | std::string |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 246 | toUri() const; |
Jeff Thompson | d129ac1 | 2013-10-11 14:30:12 -0700 | [diff] [blame] | 247 | |
| 248 | /** |
Alexander Afanasyev | 4b98e8c | 2014-03-22 19:10:19 -0700 | [diff] [blame] | 249 | * @brief Append a component with the number encoded as nonNegativeInteger |
| 250 | * |
| 251 | * @see http://named-data.net/doc/ndn-tlv/tlv.html#non-negative-integer-encoding |
| 252 | * |
Steve DiBenedetto | c145d49 | 2014-03-11 16:35:45 -0600 | [diff] [blame] | 253 | * @param number The non-negative number |
| 254 | * @return This name so that you can chain calls to append. |
| 255 | */ |
| 256 | Name& |
Alexander Afanasyev | 15f6731 | 2014-07-22 15:11:09 -0700 | [diff] [blame] | 257 | appendNumber(uint64_t number); |
Steve DiBenedetto | c145d49 | 2014-03-11 16:35:45 -0600 | [diff] [blame] | 258 | |
Jeff Thompson | ec7789a | 2013-08-21 11:08:36 -0700 | [diff] [blame] | 259 | /** |
Alexander Afanasyev | 15f6731 | 2014-07-22 15:11:09 -0700 | [diff] [blame] | 260 | * @brief Create a component encoded as NameComponentWithMarker |
| 261 | * |
| 262 | * @see http://named-data.net/doc/tech-memos/naming-conventions.pdf |
| 263 | * |
| 264 | * @param marker 1-byte marker octet |
| 265 | * @param number The non-negative number |
Alexander Afanasyev | 4b98e8c | 2014-03-22 19:10:19 -0700 | [diff] [blame] | 266 | */ |
| 267 | Name& |
Alexander Afanasyev | 15f6731 | 2014-07-22 15:11:09 -0700 | [diff] [blame] | 268 | appendNumberWithMarker(uint8_t marker, uint64_t number); |
Alexander Afanasyev | 4b98e8c | 2014-03-22 19:10:19 -0700 | [diff] [blame] | 269 | |
| 270 | /** |
Alexander Afanasyev | 15f6731 | 2014-07-22 15:11:09 -0700 | [diff] [blame] | 271 | * @brief Append version using NDN naming conventions |
| 272 | * |
| 273 | * @see http://named-data.net/doc/tech-memos/naming-conventions.pdf |
| 274 | */ |
| 275 | Name& |
| 276 | appendVersion(uint64_t version); |
| 277 | |
| 278 | /** |
| 279 | * @brief Append version using NDN naming conventions based on current UNIX timestamp |
| 280 | * in milliseconds |
| 281 | * |
| 282 | * @see http://named-data.net/doc/tech-memos/naming-conventions.pdf |
Alexander Afanasyev | 4b98e8c | 2014-03-22 19:10:19 -0700 | [diff] [blame] | 283 | */ |
| 284 | Name& |
| 285 | appendVersion(); |
| 286 | |
| 287 | /** |
Alexander Afanasyev | 15f6731 | 2014-07-22 15:11:09 -0700 | [diff] [blame] | 288 | * @brief Append segment number (sequential) using NDN naming conventions |
| 289 | * |
| 290 | * @see http://named-data.net/doc/tech-memos/naming-conventions.pdf |
Alexander Afanasyev | 4b98e8c | 2014-03-22 19:10:19 -0700 | [diff] [blame] | 291 | */ |
| 292 | Name& |
Alexander Afanasyev | 15f6731 | 2014-07-22 15:11:09 -0700 | [diff] [blame] | 293 | appendSegment(uint64_t segmentNo); |
Alexander Afanasyev | 4b98e8c | 2014-03-22 19:10:19 -0700 | [diff] [blame] | 294 | |
| 295 | /** |
Alexander Afanasyev | 15f6731 | 2014-07-22 15:11:09 -0700 | [diff] [blame] | 296 | * @brief Append segment byte offset using NDN naming conventions |
| 297 | * |
| 298 | * @see http://named-data.net/doc/tech-memos/naming-conventions.pdf |
| 299 | */ |
| 300 | Name& |
| 301 | appendSegmentOffset(uint64_t offset); |
| 302 | |
| 303 | /** |
| 304 | * @brief Append timestamp using NDN naming conventions |
| 305 | * |
| 306 | * @see http://named-data.net/doc/tech-memos/naming-conventions.pdf |
| 307 | */ |
| 308 | Name& |
| 309 | appendTimestamp(const time::system_clock::TimePoint& timePoint = time::system_clock::now()); |
| 310 | |
| 311 | /** |
| 312 | * @brief Append sequence number using NDN naming conventions |
| 313 | * |
| 314 | * @see http://named-data.net/doc/tech-memos/naming-conventions.pdf |
| 315 | */ |
| 316 | Name& |
| 317 | appendSequenceNumber(uint64_t seqNo); |
| 318 | |
| 319 | /** |
Alexander Afanasyev | 6486d52 | 2014-10-23 14:14:11 -0700 | [diff] [blame] | 320 | * @brief Append ImplicitSha256Digest |
| 321 | */ |
| 322 | Name& |
| 323 | appendImplicitSha256Digest(const ConstBufferPtr& digest); |
| 324 | |
| 325 | /** |
| 326 | * @brief Append ImplicitSha256Digest |
| 327 | */ |
| 328 | Name& |
| 329 | appendImplicitSha256Digest(const uint8_t* digest, size_t digestSize); |
| 330 | |
| 331 | /** |
Alexander Afanasyev | 15f6731 | 2014-07-22 15:11:09 -0700 | [diff] [blame] | 332 | * @brief Get the successor of a name |
| 333 | * |
| 334 | * The successor of a name is defined as follows: |
| 335 | * |
| 336 | * N represents the set of NDN Names, and X,Y ∈ N. |
| 337 | * Operator < is defined by canonical order on N. |
| 338 | * Y is the successor of X, if (a) X < Y, and (b) ∄ Z ∈ N s.t. X < Z < Y. |
| 339 | * |
| 340 | * In plain words, successor of a name is the same name, but with its last component |
| 341 | * advanced to a next possible value. |
| 342 | * |
| 343 | * Examples: |
| 344 | * |
| 345 | * - successor for / is /%00 |
| 346 | * - successor for /%00%01/%01%02 is /%00%01/%01%03 |
| 347 | * - successor for /%00%01/%01%FF is /%00%01/%02%00 |
| 348 | * - successor for /%00%01/%FF%FF is /%00%01/%00%00%00 |
| 349 | * |
Shuo Chen | 5aa8c74 | 2014-06-22 15:00:02 +0800 | [diff] [blame] | 350 | * @return a new name |
| 351 | */ |
| 352 | Name |
| 353 | getSuccessor() const; |
| 354 | |
| 355 | /** |
Jeff Thompson | 3c2ab01 | 2013-10-02 14:18:16 -0700 | [diff] [blame] | 356 | * Check if this name has the same component count and components as the given name. |
| 357 | * @param name The Name to check. |
| 358 | * @return true if the names are equal, otherwise false. |
| 359 | */ |
| 360 | bool |
| 361 | equals(const Name& name) const; |
Alexander Afanasyev | 4b98e8c | 2014-03-22 19:10:19 -0700 | [diff] [blame] | 362 | |
Jeff Thompson | 3c2ab01 | 2013-10-02 14:18:16 -0700 | [diff] [blame] | 363 | /** |
Alexander Afanasyev | 15f6731 | 2014-07-22 15:11:09 -0700 | [diff] [blame] | 364 | * @brief Check if the N components of this name are the same as the first N components |
| 365 | * of the given name. |
| 366 | * |
Jeff Thompson | ec7789a | 2013-08-21 11:08:36 -0700 | [diff] [blame] | 367 | * @param name The Name to check. |
Alexander Afanasyev | 15f6731 | 2014-07-22 15:11:09 -0700 | [diff] [blame] | 368 | * @return true if this matches the given name, otherwise false. This always returns |
| 369 | * true if this name is empty. |
Jeff Thompson | ec7789a | 2013-08-21 11:08:36 -0700 | [diff] [blame] | 370 | */ |
Alexander Afanasyev | 4b98e8c | 2014-03-22 19:10:19 -0700 | [diff] [blame] | 371 | bool |
Alexander Afanasyev | af283d8 | 2014-01-03 13:23:34 -0800 | [diff] [blame] | 372 | isPrefixOf(const Name& name) const; |
| 373 | |
Jeff Thompson | ec39fbd | 2013-10-04 10:56:23 -0700 | [diff] [blame] | 374 | // |
| 375 | // vector equivalent interface. |
| 376 | // |
Alexander Afanasyev | af283d8 | 2014-01-03 13:23:34 -0800 | [diff] [blame] | 377 | |
| 378 | /** |
| 379 | * @brief Check if name is emtpy |
| 380 | */ |
| 381 | bool |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 382 | empty() const |
| 383 | { |
| 384 | return m_nameBlock.elements().empty(); |
| 385 | } |
Alexander Afanasyev | 4b98e8c | 2014-03-22 19:10:19 -0700 | [diff] [blame] | 386 | |
Jeff Thompson | ec39fbd | 2013-10-04 10:56:23 -0700 | [diff] [blame] | 387 | /** |
| 388 | * Get the number of components. |
| 389 | * @return The number of components. |
| 390 | */ |
Alexander Afanasyev | 4b98e8c | 2014-03-22 19:10:19 -0700 | [diff] [blame] | 391 | size_t |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 392 | size() const |
| 393 | { |
| 394 | return m_nameBlock.elements_size(); |
| 395 | } |
Jeff Thompson | ec39fbd | 2013-10-04 10:56:23 -0700 | [diff] [blame] | 396 | |
| 397 | /** |
| 398 | * Get the component at the given index. |
| 399 | * @param i The index of the component, starting from 0. |
| 400 | * @return The name component at the index. |
| 401 | */ |
Alexander Afanasyev | 4b98e8c | 2014-03-22 19:10:19 -0700 | [diff] [blame] | 402 | const Component& |
Alexander Afanasyev | 8f9aa8bed | 2013-12-30 15:58:57 -0800 | [diff] [blame] | 403 | get(ssize_t i) const |
| 404 | { |
| 405 | if (i >= 0) |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 406 | return reinterpret_cast<const Component&>(m_nameBlock.elements()[i]); |
Alexander Afanasyev | 8f9aa8bed | 2013-12-30 15:58:57 -0800 | [diff] [blame] | 407 | else |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 408 | return reinterpret_cast<const Component&>(m_nameBlock.elements()[size() + i]); |
| 409 | } |
| 410 | |
| 411 | const Component& |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame] | 412 | operator[](ssize_t i) const |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 413 | { |
| 414 | return get(i); |
Alexander Afanasyev | 8f9aa8bed | 2013-12-30 15:58:57 -0800 | [diff] [blame] | 415 | } |
Alexander Afanasyev | c234429 | 2014-03-02 00:08:00 +0000 | [diff] [blame] | 416 | |
| 417 | /** |
| 418 | * @brief Get component at the specified index |
| 419 | * |
| 420 | * Unlike get() and operator[] methods, at() checks for out of bounds |
| 421 | * and will throw Name::Error when it happens |
| 422 | * |
| 423 | * @throws Name::Error if index out of bounds |
| 424 | */ |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 425 | const Component& |
| 426 | at(ssize_t i) const |
| 427 | { |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame] | 428 | if ((i >= 0 && static_cast<size_t>(i) >= size()) || |
| 429 | (i < 0 && static_cast<size_t>(-i) > size())) |
Alexander Afanasyev | c234429 | 2014-03-02 00:08:00 +0000 | [diff] [blame] | 430 | throw Error("Requested component does not exist (out of bounds)"); |
| 431 | |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 432 | return get(i); |
| 433 | } |
| 434 | |
Jeff Thompson | afc45a9 | 2014-01-15 12:42:45 -0800 | [diff] [blame] | 435 | /** |
Alexander Afanasyev | 4b98e8c | 2014-03-22 19:10:19 -0700 | [diff] [blame] | 436 | * @brief Compare this to the other Name using NDN canonical ordering. |
Jeff Thompson | afc45a9 | 2014-01-15 12:42:45 -0800 | [diff] [blame] | 437 | * |
Alexander Afanasyev | 4b98e8c | 2014-03-22 19:10:19 -0700 | [diff] [blame] | 438 | * If the first components of each name are not equal, this returns -1 if the first comes |
| 439 | * before the second using the NDN canonical ordering for name components, or 1 if it |
| 440 | * comes after. If they are equal, this compares the second components of each name, etc. |
| 441 | * If both names are the same up to the size of the shorter name, this returns -1 if the |
| 442 | * first name is shorter than the second or 1 if it is longer. For example, if you |
| 443 | * std::sort gives: /a/b/d /a/b/cc /c /c/a /bb . This is intuitive because all names with |
| 444 | * the prefix /a are next to each other. But it may be also be counter-intuitive because |
| 445 | * /c comes before /bb according to NDN canonical ordering since it is shorter. @param |
Junxiao Shi | a6452ac | 2015-01-23 11:21:06 -0700 | [diff] [blame] | 446 | * other The other Name to compare with. |
| 447 | * |
| 448 | * @retval 0 if they compare equal |
| 449 | * @retval -1 if *this comes before other in the canonical ordering |
| 450 | * @retval 1 if *this comes after other in the canonical ordering |
Alexander Afanasyev | 4b98e8c | 2014-03-22 19:10:19 -0700 | [diff] [blame] | 451 | * |
| 452 | * @see http://named-data.net/doc/ndn-tlv/name.html#canonical-order |
Jeff Thompson | afc45a9 | 2014-01-15 12:42:45 -0800 | [diff] [blame] | 453 | */ |
| 454 | int |
Junxiao Shi | a6452ac | 2015-01-23 11:21:06 -0700 | [diff] [blame] | 455 | compare(const Name& other) const |
| 456 | { |
| 457 | return this->compare(0, npos, other); |
| 458 | } |
| 459 | |
| 460 | /** \brief compares [pos1, pos1+count1) components in this Name |
| 461 | * to [pos2, pos2+count2) components in \p other |
| 462 | * |
| 463 | * This is equivalent to this->getSubName(pos1, count1).compare(other.getSubName(pos2, count2)); |
| 464 | */ |
| 465 | int |
| 466 | compare(size_t pos1, size_t count1, |
| 467 | const Name& other, size_t pos2 = 0, size_t count2 = npos) const; |
Jeff Thompson | ec39fbd | 2013-10-04 10:56:23 -0700 | [diff] [blame] | 468 | |
Jeff Thompson | ec39fbd | 2013-10-04 10:56:23 -0700 | [diff] [blame] | 469 | /** |
| 470 | * Append the component |
| 471 | * @param component The component of type T. |
| 472 | */ |
| 473 | template<class T> void |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame] | 474 | push_back(const T& component) |
Jeff Thompson | ec39fbd | 2013-10-04 10:56:23 -0700 | [diff] [blame] | 475 | { |
| 476 | append(component); |
| 477 | } |
Alexander Afanasyev | 4b98e8c | 2014-03-22 19:10:19 -0700 | [diff] [blame] | 478 | |
Jeff Thompson | 91737f5 | 2013-10-04 11:07:24 -0700 | [diff] [blame] | 479 | /** |
| 480 | * Check if this name has the same component count and components as the given name. |
| 481 | * @param name The Name to check. |
| 482 | * @return true if the names are equal, otherwise false. |
| 483 | */ |
| 484 | bool |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 485 | operator==(const Name& name) const |
| 486 | { |
| 487 | return equals(name); |
| 488 | } |
Jeff Thompson | 91737f5 | 2013-10-04 11:07:24 -0700 | [diff] [blame] | 489 | |
| 490 | /** |
| 491 | * Check if this name has the same component count and components as the given name. |
| 492 | * @param name The Name to check. |
| 493 | * @return true if the names are not equal, otherwise false. |
| 494 | */ |
| 495 | bool |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 496 | operator!=(const Name& name) const |
| 497 | { |
| 498 | return !equals(name); |
| 499 | } |
Alexander Afanasyev | 4b98e8c | 2014-03-22 19:10:19 -0700 | [diff] [blame] | 500 | |
Jeff Thompson | 82568ad | 2013-12-17 15:17:40 -0800 | [diff] [blame] | 501 | /** |
Jeff Thompson | afc45a9 | 2014-01-15 12:42:45 -0800 | [diff] [blame] | 502 | * Return true if this is less than or equal to the other Name in the NDN canonical ordering. |
| 503 | * @param other The other Name to compare with. |
| 504 | * |
Alexander Afanasyev | 4b98e8c | 2014-03-22 19:10:19 -0700 | [diff] [blame] | 505 | * @see http://named-data.net/doc/ndn-tlv/name.html#canonical-order |
Jeff Thompson | 82568ad | 2013-12-17 15:17:40 -0800 | [diff] [blame] | 506 | */ |
Jeff Thompson | afc45a9 | 2014-01-15 12:42:45 -0800 | [diff] [blame] | 507 | bool |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 508 | operator<=(const Name& other) const |
| 509 | { |
| 510 | return compare(other) <= 0; |
| 511 | } |
Jeff Thompson | afc45a9 | 2014-01-15 12:42:45 -0800 | [diff] [blame] | 512 | |
| 513 | /** |
| 514 | * Return true if this is less than the other Name in the NDN canonical ordering. |
| 515 | * @param other The other Name to compare with. |
| 516 | * |
Alexander Afanasyev | 4b98e8c | 2014-03-22 19:10:19 -0700 | [diff] [blame] | 517 | * @see http://named-data.net/doc/ndn-tlv/name.html#canonical-order |
Jeff Thompson | afc45a9 | 2014-01-15 12:42:45 -0800 | [diff] [blame] | 518 | */ |
| 519 | bool |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 520 | operator<(const Name& other) const |
| 521 | { |
| 522 | return compare(other) < 0; |
| 523 | } |
Jeff Thompson | afc45a9 | 2014-01-15 12:42:45 -0800 | [diff] [blame] | 524 | |
| 525 | /** |
| 526 | * Return true if this is less than or equal to the other Name in the NDN canonical ordering. |
| 527 | * @param other The other Name to compare with. |
| 528 | * |
Alexander Afanasyev | 4b98e8c | 2014-03-22 19:10:19 -0700 | [diff] [blame] | 529 | * @see http://named-data.net/doc/ndn-tlv/name.html#canonical-order |
Jeff Thompson | afc45a9 | 2014-01-15 12:42:45 -0800 | [diff] [blame] | 530 | */ |
| 531 | bool |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 532 | operator>=(const Name& other) const |
| 533 | { |
| 534 | return compare(other) >= 0; |
| 535 | } |
Jeff Thompson | afc45a9 | 2014-01-15 12:42:45 -0800 | [diff] [blame] | 536 | |
| 537 | /** |
| 538 | * Return true if this is greater than the other Name in the NDN canonical ordering. |
| 539 | * @param other The other Name to compare with. |
| 540 | * |
Alexander Afanasyev | 4b98e8c | 2014-03-22 19:10:19 -0700 | [diff] [blame] | 541 | * @see http://named-data.net/doc/ndn-tlv/name.html#canonical-order |
Jeff Thompson | afc45a9 | 2014-01-15 12:42:45 -0800 | [diff] [blame] | 542 | */ |
| 543 | bool |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 544 | operator>(const Name& other) const |
| 545 | { |
| 546 | return compare(other) > 0; |
| 547 | } |
Alexander Afanasyev | 4b98e8c | 2014-03-22 19:10:19 -0700 | [diff] [blame] | 548 | |
Jeff Thompson | ec39fbd | 2013-10-04 10:56:23 -0700 | [diff] [blame] | 549 | // |
| 550 | // Iterator interface to name components. |
| 551 | // |
Jeff Thompson | ec39fbd | 2013-10-04 10:56:23 -0700 | [diff] [blame] | 552 | |
| 553 | /** |
| 554 | * Begin iterator (const). |
| 555 | */ |
| 556 | const_iterator |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 557 | begin() const |
| 558 | { |
| 559 | return reinterpret_cast<const_iterator>(&*m_nameBlock.elements().begin()); |
| 560 | } |
Jeff Thompson | ec39fbd | 2013-10-04 10:56:23 -0700 | [diff] [blame] | 561 | |
| 562 | /** |
Jeff Thompson | ec39fbd | 2013-10-04 10:56:23 -0700 | [diff] [blame] | 563 | * End iterator (const). |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 564 | * |
| 565 | * @todo Check if this crash when there are no elements in the buffer |
Jeff Thompson | ec39fbd | 2013-10-04 10:56:23 -0700 | [diff] [blame] | 566 | */ |
| 567 | const_iterator |
Alexander Afanasyev | 29e5c3d | 2014-02-11 00:01:10 -0800 | [diff] [blame] | 568 | end() const |
| 569 | { |
| 570 | return reinterpret_cast<const_iterator>(&*m_nameBlock.elements().end()); |
| 571 | } |
Jeff Thompson | ec39fbd | 2013-10-04 10:56:23 -0700 | [diff] [blame] | 572 | |
| 573 | /** |
Jeff Thompson | ec39fbd | 2013-10-04 10:56:23 -0700 | [diff] [blame] | 574 | * Reverse begin iterator (const). |
| 575 | */ |
| 576 | const_reverse_iterator |
Alexander Afanasyev | 29e5c3d | 2014-02-11 00:01:10 -0800 | [diff] [blame] | 577 | rbegin() const |
| 578 | { |
| 579 | return const_reverse_iterator(end()); |
| 580 | } |
Jeff Thompson | ec39fbd | 2013-10-04 10:56:23 -0700 | [diff] [blame] | 581 | |
| 582 | /** |
| 583 | * Reverse end iterator (const). |
| 584 | */ |
| 585 | const_reverse_iterator |
Alexander Afanasyev | 29e5c3d | 2014-02-11 00:01:10 -0800 | [diff] [blame] | 586 | rend() const |
| 587 | { |
| 588 | return const_reverse_iterator(begin()); |
| 589 | } |
Jeff Thompson | ec39fbd | 2013-10-04 10:56:23 -0700 | [diff] [blame] | 590 | |
Alexander Afanasyev | c89efb4 | 2015-02-10 18:26:42 -0800 | [diff] [blame^] | 591 | private: |
| 592 | void |
| 593 | construct(const char* uri); |
| 594 | |
Junxiao Shi | a6452ac | 2015-01-23 11:21:06 -0700 | [diff] [blame] | 595 | public: |
| 596 | /** \brief indicates "until the end" in getSubName and compare |
| 597 | */ |
| 598 | static const size_t npos; |
| 599 | |
Jeff Thompson | 9c41dfe | 2013-06-27 12:10:25 -0700 | [diff] [blame] | 600 | private: |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 601 | mutable Block m_nameBlock; |
Alexander Afanasyev | af283d8 | 2014-01-03 13:23:34 -0800 | [diff] [blame] | 602 | }; |
| 603 | |
Alexander Afanasyev | 15f6731 | 2014-07-22 15:11:09 -0700 | [diff] [blame] | 604 | std::ostream& |
| 605 | operator<<(std::ostream& os, const Name& name); |
Alexander Afanasyev | 4b98e8c | 2014-03-22 19:10:19 -0700 | [diff] [blame] | 606 | |
Alexander Afanasyev | 15f6731 | 2014-07-22 15:11:09 -0700 | [diff] [blame] | 607 | std::istream& |
| 608 | operator>>(std::istream& is, Name& name); |
Alexander Afanasyev | 52eb20d | 2014-02-06 18:25:54 -0800 | [diff] [blame] | 609 | |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 610 | inline bool |
| 611 | Name::hasWire() const |
Alexander Afanasyev | 52eb20d | 2014-02-06 18:25:54 -0800 | [diff] [blame] | 612 | { |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 613 | return m_nameBlock.hasWire(); |
Alexander Afanasyev | 52eb20d | 2014-02-06 18:25:54 -0800 | [diff] [blame] | 614 | } |
| 615 | |
Alexander Afanasyev | 95e8c2f | 2014-02-06 17:29:30 -0800 | [diff] [blame] | 616 | } // namespace ndn |
Jeff Thompson | 9c41dfe | 2013-06-27 12:10:25 -0700 | [diff] [blame] | 617 | |
Yingdi Yu | 90e2358 | 2014-11-06 14:21:04 -0800 | [diff] [blame] | 618 | namespace std { |
| 619 | template<> |
| 620 | struct hash<ndn::Name> |
| 621 | { |
| 622 | size_t |
| 623 | operator()(const ndn::Name& name) const; |
| 624 | }; |
| 625 | |
| 626 | } // namespace std |
| 627 | |
Jeff Thompson | 9c41dfe | 2013-06-27 12:10:25 -0700 | [diff] [blame] | 628 | #endif |