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