Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 88a0d81 | 2017-08-19 21:31:42 -0400 | [diff] [blame^] | 2 | /* |
Eric Newberry | b555b00 | 2017-05-17 00:30:44 -0700 | [diff] [blame] | 3 | * Copyright (c) 2013-2017 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 | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | #ifndef NDN_SELECTORS_HPP |
| 23 | #define NDN_SELECTORS_HPP |
| 24 | |
| 25 | #include "common.hpp" |
Junxiao Shi | b332e78 | 2014-03-31 14:23:46 -0700 | [diff] [blame] | 26 | #include "key-locator.hpp" |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 27 | #include "exclude.hpp" |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 28 | |
| 29 | namespace ndn { |
Junxiao Shi | b332e78 | 2014-03-31 14:23:46 -0700 | [diff] [blame] | 30 | |
Eric Newberry | b555b00 | 2017-05-17 00:30:44 -0700 | [diff] [blame] | 31 | const int DEFAULT_CHILD_SELECTOR = 0; |
| 32 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 33 | /** |
| 34 | * @brief Abstraction implementing Interest selectors |
| 35 | */ |
| 36 | class Selectors |
| 37 | { |
Junxiao Shi | b332e78 | 2014-03-31 14:23:46 -0700 | [diff] [blame] | 38 | public: |
Junxiao Shi | c2b8d24 | 2014-11-04 08:35:29 -0700 | [diff] [blame] | 39 | class Error : public tlv::Error |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 40 | { |
Junxiao Shi | c2b8d24 | 2014-11-04 08:35:29 -0700 | [diff] [blame] | 41 | public: |
| 42 | explicit |
| 43 | Error(const std::string& what) |
| 44 | : tlv::Error(what) |
| 45 | { |
| 46 | } |
| 47 | }; |
| 48 | |
| 49 | Selectors(); |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 50 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 51 | /** |
| 52 | * @brief Create from wire encoding |
| 53 | */ |
Junxiao Shi | c2b8d24 | 2014-11-04 08:35:29 -0700 | [diff] [blame] | 54 | explicit |
| 55 | Selectors(const Block& wire); |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 56 | |
| 57 | bool |
| 58 | empty() const; |
Junxiao Shi | b332e78 | 2014-03-31 14:23:46 -0700 | [diff] [blame] | 59 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 60 | /** |
| 61 | * @brief Fast encoding or block size estimation |
| 62 | */ |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame] | 63 | template<encoding::Tag TAG> |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 64 | size_t |
Alexander Afanasyev | d5c48e0 | 2015-06-24 11:58:14 -0700 | [diff] [blame] | 65 | wireEncode(EncodingImpl<TAG>& encoder) const; |
Junxiao Shi | b332e78 | 2014-03-31 14:23:46 -0700 | [diff] [blame] | 66 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 67 | /** |
| 68 | * @brief Encode to a wire format |
| 69 | */ |
| 70 | const Block& |
| 71 | wireEncode() const; |
| 72 | |
| 73 | /** |
| 74 | * @brief Decode the input from wire format |
| 75 | */ |
Junxiao Shi | b332e78 | 2014-03-31 14:23:46 -0700 | [diff] [blame] | 76 | void |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 77 | wireDecode(const Block& wire); |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 78 | |
Junxiao Shi | c2b8d24 | 2014-11-04 08:35:29 -0700 | [diff] [blame] | 79 | public: // getters & setters |
Junxiao Shi | b332e78 | 2014-03-31 14:23:46 -0700 | [diff] [blame] | 80 | int |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 81 | getMinSuffixComponents() const |
| 82 | { |
| 83 | return m_minSuffixComponents; |
| 84 | } |
Junxiao Shi | b332e78 | 2014-03-31 14:23:46 -0700 | [diff] [blame] | 85 | |
| 86 | Selectors& |
Junxiao Shi | c2b8d24 | 2014-11-04 08:35:29 -0700 | [diff] [blame] | 87 | setMinSuffixComponents(int minSuffixComponents); |
Junxiao Shi | b332e78 | 2014-03-31 14:23:46 -0700 | [diff] [blame] | 88 | |
| 89 | int |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 90 | getMaxSuffixComponents() const |
| 91 | { |
| 92 | return m_maxSuffixComponents; |
| 93 | } |
| 94 | |
Junxiao Shi | b332e78 | 2014-03-31 14:23:46 -0700 | [diff] [blame] | 95 | Selectors& |
Junxiao Shi | c2b8d24 | 2014-11-04 08:35:29 -0700 | [diff] [blame] | 96 | setMaxSuffixComponents(int maxSuffixComponents); |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 97 | |
Junxiao Shi | b332e78 | 2014-03-31 14:23:46 -0700 | [diff] [blame] | 98 | const KeyLocator& |
| 99 | getPublisherPublicKeyLocator() const |
| 100 | { |
| 101 | return m_publisherPublicKeyLocator; |
| 102 | } |
| 103 | |
| 104 | Selectors& |
Junxiao Shi | c2b8d24 | 2014-11-04 08:35:29 -0700 | [diff] [blame] | 105 | setPublisherPublicKeyLocator(const KeyLocator& keyLocator); |
Junxiao Shi | b332e78 | 2014-03-31 14:23:46 -0700 | [diff] [blame] | 106 | |
| 107 | const Exclude& |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 108 | getExclude() const |
| 109 | { |
| 110 | return m_exclude; |
| 111 | } |
| 112 | |
Junxiao Shi | b332e78 | 2014-03-31 14:23:46 -0700 | [diff] [blame] | 113 | Selectors& |
Junxiao Shi | c2b8d24 | 2014-11-04 08:35:29 -0700 | [diff] [blame] | 114 | setExclude(const Exclude& exclude); |
Junxiao Shi | b332e78 | 2014-03-31 14:23:46 -0700 | [diff] [blame] | 115 | |
| 116 | int |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 117 | getChildSelector() const |
| 118 | { |
| 119 | return m_childSelector; |
| 120 | } |
| 121 | |
Eric Newberry | b555b00 | 2017-05-17 00:30:44 -0700 | [diff] [blame] | 122 | /** |
| 123 | * @brief set ChildSelector |
| 124 | * @throw std::invalid_argument ChildSelector not 0 or 1 |
| 125 | */ |
Junxiao Shi | b332e78 | 2014-03-31 14:23:46 -0700 | [diff] [blame] | 126 | Selectors& |
Junxiao Shi | c2b8d24 | 2014-11-04 08:35:29 -0700 | [diff] [blame] | 127 | setChildSelector(int childSelector); |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 128 | |
Junxiao Shi | b332e78 | 2014-03-31 14:23:46 -0700 | [diff] [blame] | 129 | int |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 130 | getMustBeFresh() const |
| 131 | { |
| 132 | return m_mustBeFresh; |
| 133 | } |
| 134 | |
Junxiao Shi | b332e78 | 2014-03-31 14:23:46 -0700 | [diff] [blame] | 135 | Selectors& |
Junxiao Shi | c2b8d24 | 2014-11-04 08:35:29 -0700 | [diff] [blame] | 136 | setMustBeFresh(bool mustBeFresh); |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 137 | |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 138 | public: // EqualityComparable concept |
| 139 | bool |
Junxiao Shi | c2b8d24 | 2014-11-04 08:35:29 -0700 | [diff] [blame] | 140 | operator==(const Selectors& other) const; |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 141 | |
| 142 | bool |
| 143 | operator!=(const Selectors& other) const |
| 144 | { |
Junxiao Shi | c2b8d24 | 2014-11-04 08:35:29 -0700 | [diff] [blame] | 145 | return !this->operator==(other); |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 146 | } |
| 147 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 148 | private: |
| 149 | int m_minSuffixComponents; |
Junxiao Shi | b332e78 | 2014-03-31 14:23:46 -0700 | [diff] [blame] | 150 | int m_maxSuffixComponents; |
| 151 | KeyLocator m_publisherPublicKeyLocator; |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 152 | Exclude m_exclude; |
| 153 | int m_childSelector; |
| 154 | bool m_mustBeFresh; |
| 155 | |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 156 | mutable Block m_wire; |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 157 | }; |
| 158 | |
Davide Pesavento | 88a0d81 | 2017-08-19 21:31:42 -0400 | [diff] [blame^] | 159 | NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(Selectors); |
| 160 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 161 | } // namespace ndn |
| 162 | |
| 163 | #endif // NDN_SELECTORS_HPP |