blob: e3cb6e4f46ce0224faec063b8eed7a6fbf5391ff [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento88a0d812017-08-19 21:31:42 -04002/*
Junxiao Shi8d3f8342018-04-04 12:46:37 +00003 * Copyright (c) 2013-2018 Regents of the University of California.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07006 *
Alexander Afanasyevc169a812014-05-20 20:37:29 -04007 * 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 Afanasyevc348f832014-02-17 16:35:17 -080020 */
21
22#ifndef NDN_SELECTORS_HPP
23#define NDN_SELECTORS_HPP
24
25#include "common.hpp"
Junxiao Shib332e782014-03-31 14:23:46 -070026#include "key-locator.hpp"
Alexander Afanasyevc348f832014-02-17 16:35:17 -080027#include "exclude.hpp"
Alexander Afanasyevc348f832014-02-17 16:35:17 -080028
29namespace ndn {
Junxiao Shib332e782014-03-31 14:23:46 -070030
Eric Newberryb555b002017-05-17 00:30:44 -070031const int DEFAULT_CHILD_SELECTOR = 0;
32
Alexander Afanasyevc348f832014-02-17 16:35:17 -080033/**
34 * @brief Abstraction implementing Interest selectors
35 */
36class Selectors
37{
Junxiao Shib332e782014-03-31 14:23:46 -070038public:
Junxiao Shic2b8d242014-11-04 08:35:29 -070039 class Error : public tlv::Error
Alexander Afanasyevc348f832014-02-17 16:35:17 -080040 {
Junxiao Shic2b8d242014-11-04 08:35:29 -070041 public:
Junxiao Shi68b53852018-07-25 13:56:38 -060042 using tlv::Error::Error;
Junxiao Shic2b8d242014-11-04 08:35:29 -070043 };
44
45 Selectors();
Alexander Afanasyevc348f832014-02-17 16:35:17 -080046
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070047 /**
48 * @brief Create from wire encoding
49 */
Junxiao Shic2b8d242014-11-04 08:35:29 -070050 explicit
51 Selectors(const Block& wire);
Alexander Afanasyevc348f832014-02-17 16:35:17 -080052
53 bool
54 empty() const;
Junxiao Shib332e782014-03-31 14:23:46 -070055
Alexander Afanasyevc348f832014-02-17 16:35:17 -080056 /**
57 * @brief Fast encoding or block size estimation
58 */
Alexander Afanasyev74633892015-02-08 18:08:46 -080059 template<encoding::Tag TAG>
Alexander Afanasyevc348f832014-02-17 16:35:17 -080060 size_t
Alexander Afanasyevd5c48e02015-06-24 11:58:14 -070061 wireEncode(EncodingImpl<TAG>& encoder) const;
Junxiao Shib332e782014-03-31 14:23:46 -070062
Alexander Afanasyevc348f832014-02-17 16:35:17 -080063 /**
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 Shib332e782014-03-31 14:23:46 -070072 void
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -070073 wireDecode(const Block& wire);
Alexander Afanasyevc348f832014-02-17 16:35:17 -080074
Junxiao Shic2b8d242014-11-04 08:35:29 -070075public: // getters & setters
Junxiao Shib332e782014-03-31 14:23:46 -070076 int
Alexander Afanasyevc348f832014-02-17 16:35:17 -080077 getMinSuffixComponents() const
78 {
79 return m_minSuffixComponents;
80 }
Junxiao Shib332e782014-03-31 14:23:46 -070081
82 Selectors&
Junxiao Shic2b8d242014-11-04 08:35:29 -070083 setMinSuffixComponents(int minSuffixComponents);
Junxiao Shib332e782014-03-31 14:23:46 -070084
85 int
Alexander Afanasyevc348f832014-02-17 16:35:17 -080086 getMaxSuffixComponents() const
87 {
88 return m_maxSuffixComponents;
89 }
90
Junxiao Shib332e782014-03-31 14:23:46 -070091 Selectors&
Junxiao Shic2b8d242014-11-04 08:35:29 -070092 setMaxSuffixComponents(int maxSuffixComponents);
Alexander Afanasyevc348f832014-02-17 16:35:17 -080093
Junxiao Shib332e782014-03-31 14:23:46 -070094 const KeyLocator&
95 getPublisherPublicKeyLocator() const
96 {
97 return m_publisherPublicKeyLocator;
98 }
99
100 Selectors&
Junxiao Shic2b8d242014-11-04 08:35:29 -0700101 setPublisherPublicKeyLocator(const KeyLocator& keyLocator);
Junxiao Shib332e782014-03-31 14:23:46 -0700102
103 const Exclude&
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800104 getExclude() const
105 {
106 return m_exclude;
107 }
108
Junxiao Shib332e782014-03-31 14:23:46 -0700109 Selectors&
Junxiao Shic2b8d242014-11-04 08:35:29 -0700110 setExclude(const Exclude& exclude);
Junxiao Shib332e782014-03-31 14:23:46 -0700111
112 int
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800113 getChildSelector() const
114 {
115 return m_childSelector;
116 }
117
Eric Newberryb555b002017-05-17 00:30:44 -0700118 /**
119 * @brief set ChildSelector
120 * @throw std::invalid_argument ChildSelector not 0 or 1
121 */
Junxiao Shib332e782014-03-31 14:23:46 -0700122 Selectors&
Junxiao Shic2b8d242014-11-04 08:35:29 -0700123 setChildSelector(int childSelector);
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800124
Junxiao Shi8d3f8342018-04-04 12:46:37 +0000125 bool
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800126 getMustBeFresh() const
127 {
128 return m_mustBeFresh;
129 }
130
Junxiao Shib332e782014-03-31 14:23:46 -0700131 Selectors&
Junxiao Shic2b8d242014-11-04 08:35:29 -0700132 setMustBeFresh(bool mustBeFresh);
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800133
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700134public: // EqualityComparable concept
135 bool
Junxiao Shic2b8d242014-11-04 08:35:29 -0700136 operator==(const Selectors& other) const;
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700137
138 bool
139 operator!=(const Selectors& other) const
140 {
Junxiao Shic2b8d242014-11-04 08:35:29 -0700141 return !this->operator==(other);
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700142 }
143
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800144private:
145 int m_minSuffixComponents;
Junxiao Shib332e782014-03-31 14:23:46 -0700146 int m_maxSuffixComponents;
147 KeyLocator m_publisherPublicKeyLocator;
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800148 Exclude m_exclude;
149 int m_childSelector;
150 bool m_mustBeFresh;
151
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700152 mutable Block m_wire;
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800153};
154
Davide Pesavento88a0d812017-08-19 21:31:42 -0400155NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(Selectors);
156
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800157} // namespace ndn
158
159#endif // NDN_SELECTORS_HPP