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