blob: 62b4b065218e6b46d570356ecbbcb60e3596ba51 [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Alexander Afanasyevc348f832014-02-17 16:35:17 -08002/**
Alexander Afanasyev74633892015-02-08 18:08:46 -08003 * Copyright (c) 2013-2015 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
Alexander Afanasyevc348f832014-02-17 16:35:17 -080031/**
32 * @brief Abstraction implementing Interest selectors
33 */
34class Selectors
35{
Junxiao Shib332e782014-03-31 14:23:46 -070036public:
Junxiao Shic2b8d242014-11-04 08:35:29 -070037 class Error : public tlv::Error
Alexander Afanasyevc348f832014-02-17 16:35:17 -080038 {
Junxiao Shic2b8d242014-11-04 08:35:29 -070039 public:
40 explicit
41 Error(const std::string& what)
42 : tlv::Error(what)
43 {
44 }
45 };
46
47 Selectors();
Alexander Afanasyevc348f832014-02-17 16:35:17 -080048
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070049 /**
50 * @brief Create from wire encoding
51 */
Junxiao Shic2b8d242014-11-04 08:35:29 -070052 explicit
53 Selectors(const Block& wire);
Alexander Afanasyevc348f832014-02-17 16:35:17 -080054
55 bool
56 empty() const;
Junxiao Shib332e782014-03-31 14:23:46 -070057
Alexander Afanasyevc348f832014-02-17 16:35:17 -080058 /**
59 * @brief Fast encoding or block size estimation
60 */
Alexander Afanasyev74633892015-02-08 18:08:46 -080061 template<encoding::Tag TAG>
Alexander Afanasyevc348f832014-02-17 16:35:17 -080062 size_t
Alexander Afanasyev74633892015-02-08 18:08:46 -080063 wireEncode(EncodingImpl<TAG>& block) const;
Junxiao Shib332e782014-03-31 14:23:46 -070064
Alexander Afanasyevc348f832014-02-17 16:35:17 -080065 /**
66 * @brief Encode to a wire format
67 */
68 const Block&
69 wireEncode() const;
70
71 /**
72 * @brief Decode the input from wire format
73 */
Junxiao Shib332e782014-03-31 14:23:46 -070074 void
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -070075 wireDecode(const Block& wire);
Alexander Afanasyevc348f832014-02-17 16:35:17 -080076
Junxiao Shic2b8d242014-11-04 08:35:29 -070077public: // getters & setters
Junxiao Shib332e782014-03-31 14:23:46 -070078 int
Alexander Afanasyevc348f832014-02-17 16:35:17 -080079 getMinSuffixComponents() const
80 {
81 return m_minSuffixComponents;
82 }
Junxiao Shib332e782014-03-31 14:23:46 -070083
84 Selectors&
Junxiao Shic2b8d242014-11-04 08:35:29 -070085 setMinSuffixComponents(int minSuffixComponents);
Junxiao Shib332e782014-03-31 14:23:46 -070086
87 int
Alexander Afanasyevc348f832014-02-17 16:35:17 -080088 getMaxSuffixComponents() const
89 {
90 return m_maxSuffixComponents;
91 }
92
Junxiao Shib332e782014-03-31 14:23:46 -070093 Selectors&
Junxiao Shic2b8d242014-11-04 08:35:29 -070094 setMaxSuffixComponents(int maxSuffixComponents);
Alexander Afanasyevc348f832014-02-17 16:35:17 -080095
Junxiao Shib332e782014-03-31 14:23:46 -070096 const KeyLocator&
97 getPublisherPublicKeyLocator() const
98 {
99 return m_publisherPublicKeyLocator;
100 }
101
102 Selectors&
Junxiao Shic2b8d242014-11-04 08:35:29 -0700103 setPublisherPublicKeyLocator(const KeyLocator& keyLocator);
Junxiao Shib332e782014-03-31 14:23:46 -0700104
105 const Exclude&
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800106 getExclude() const
107 {
108 return m_exclude;
109 }
110
Junxiao Shib332e782014-03-31 14:23:46 -0700111 Selectors&
Junxiao Shic2b8d242014-11-04 08:35:29 -0700112 setExclude(const Exclude& exclude);
Junxiao Shib332e782014-03-31 14:23:46 -0700113
114 int
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800115 getChildSelector() const
116 {
117 return m_childSelector;
118 }
119
Junxiao Shib332e782014-03-31 14:23:46 -0700120 Selectors&
Junxiao Shic2b8d242014-11-04 08:35:29 -0700121 setChildSelector(int childSelector);
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800122
Junxiao Shib332e782014-03-31 14:23:46 -0700123 int
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800124 getMustBeFresh() const
125 {
126 return m_mustBeFresh;
127 }
128
Junxiao Shib332e782014-03-31 14:23:46 -0700129 Selectors&
Junxiao Shic2b8d242014-11-04 08:35:29 -0700130 setMustBeFresh(bool mustBeFresh);
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800131
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700132public: // EqualityComparable concept
133 bool
Junxiao Shic2b8d242014-11-04 08:35:29 -0700134 operator==(const Selectors& other) const;
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700135
136 bool
137 operator!=(const Selectors& other) const
138 {
Junxiao Shic2b8d242014-11-04 08:35:29 -0700139 return !this->operator==(other);
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700140 }
141
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800142private:
143 int m_minSuffixComponents;
Junxiao Shib332e782014-03-31 14:23:46 -0700144 int m_maxSuffixComponents;
145 KeyLocator m_publisherPublicKeyLocator;
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800146 Exclude m_exclude;
147 int m_childSelector;
148 bool m_mustBeFresh;
149
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700150 mutable Block m_wire;
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800151};
152
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800153} // namespace ndn
154
155#endif // NDN_SELECTORS_HPP