blob: 5a80185c22e2c8d4b95bd052384750ad28ad67dc [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/*
Eric Newberryb555b002017-05-17 00:30:44 -07003 * Copyright (c) 2013-2017 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:
42 explicit
43 Error(const std::string& what)
44 : tlv::Error(what)
45 {
46 }
47 };
48
49 Selectors();
Alexander Afanasyevc348f832014-02-17 16:35:17 -080050
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070051 /**
52 * @brief Create from wire encoding
53 */
Junxiao Shic2b8d242014-11-04 08:35:29 -070054 explicit
55 Selectors(const Block& wire);
Alexander Afanasyevc348f832014-02-17 16:35:17 -080056
57 bool
58 empty() const;
Junxiao Shib332e782014-03-31 14:23:46 -070059
Alexander Afanasyevc348f832014-02-17 16:35:17 -080060 /**
61 * @brief Fast encoding or block size estimation
62 */
Alexander Afanasyev74633892015-02-08 18:08:46 -080063 template<encoding::Tag TAG>
Alexander Afanasyevc348f832014-02-17 16:35:17 -080064 size_t
Alexander Afanasyevd5c48e02015-06-24 11:58:14 -070065 wireEncode(EncodingImpl<TAG>& encoder) const;
Junxiao Shib332e782014-03-31 14:23:46 -070066
Alexander Afanasyevc348f832014-02-17 16:35:17 -080067 /**
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 Shib332e782014-03-31 14:23:46 -070076 void
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -070077 wireDecode(const Block& wire);
Alexander Afanasyevc348f832014-02-17 16:35:17 -080078
Junxiao Shic2b8d242014-11-04 08:35:29 -070079public: // getters & setters
Junxiao Shib332e782014-03-31 14:23:46 -070080 int
Alexander Afanasyevc348f832014-02-17 16:35:17 -080081 getMinSuffixComponents() const
82 {
83 return m_minSuffixComponents;
84 }
Junxiao Shib332e782014-03-31 14:23:46 -070085
86 Selectors&
Junxiao Shic2b8d242014-11-04 08:35:29 -070087 setMinSuffixComponents(int minSuffixComponents);
Junxiao Shib332e782014-03-31 14:23:46 -070088
89 int
Alexander Afanasyevc348f832014-02-17 16:35:17 -080090 getMaxSuffixComponents() const
91 {
92 return m_maxSuffixComponents;
93 }
94
Junxiao Shib332e782014-03-31 14:23:46 -070095 Selectors&
Junxiao Shic2b8d242014-11-04 08:35:29 -070096 setMaxSuffixComponents(int maxSuffixComponents);
Alexander Afanasyevc348f832014-02-17 16:35:17 -080097
Junxiao Shib332e782014-03-31 14:23:46 -070098 const KeyLocator&
99 getPublisherPublicKeyLocator() const
100 {
101 return m_publisherPublicKeyLocator;
102 }
103
104 Selectors&
Junxiao Shic2b8d242014-11-04 08:35:29 -0700105 setPublisherPublicKeyLocator(const KeyLocator& keyLocator);
Junxiao Shib332e782014-03-31 14:23:46 -0700106
107 const Exclude&
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800108 getExclude() const
109 {
110 return m_exclude;
111 }
112
Junxiao Shib332e782014-03-31 14:23:46 -0700113 Selectors&
Junxiao Shic2b8d242014-11-04 08:35:29 -0700114 setExclude(const Exclude& exclude);
Junxiao Shib332e782014-03-31 14:23:46 -0700115
116 int
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800117 getChildSelector() const
118 {
119 return m_childSelector;
120 }
121
Eric Newberryb555b002017-05-17 00:30:44 -0700122 /**
123 * @brief set ChildSelector
124 * @throw std::invalid_argument ChildSelector not 0 or 1
125 */
Junxiao Shib332e782014-03-31 14:23:46 -0700126 Selectors&
Junxiao Shic2b8d242014-11-04 08:35:29 -0700127 setChildSelector(int childSelector);
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800128
Junxiao Shib332e782014-03-31 14:23:46 -0700129 int
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800130 getMustBeFresh() const
131 {
132 return m_mustBeFresh;
133 }
134
Junxiao Shib332e782014-03-31 14:23:46 -0700135 Selectors&
Junxiao Shic2b8d242014-11-04 08:35:29 -0700136 setMustBeFresh(bool mustBeFresh);
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800137
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700138public: // EqualityComparable concept
139 bool
Junxiao Shic2b8d242014-11-04 08:35:29 -0700140 operator==(const Selectors& other) const;
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700141
142 bool
143 operator!=(const Selectors& other) const
144 {
Junxiao Shic2b8d242014-11-04 08:35:29 -0700145 return !this->operator==(other);
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700146 }
147
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800148private:
149 int m_minSuffixComponents;
Junxiao Shib332e782014-03-31 14:23:46 -0700150 int m_maxSuffixComponents;
151 KeyLocator m_publisherPublicKeyLocator;
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800152 Exclude m_exclude;
153 int m_childSelector;
154 bool m_mustBeFresh;
155
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700156 mutable Block m_wire;
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800157};
158
Davide Pesavento88a0d812017-08-19 21:31:42 -0400159NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(Selectors);
160
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800161} // namespace ndn
162
163#endif // NDN_SELECTORS_HPP