blob: 6db99ac91e22bf4fc3e7bd4cd9d56659beafae1c [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 Afanasyevc169a812014-05-20 20:37:29 -04003 * Copyright (c) 2013-2014 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
Junxiao Shib332e782014-03-31 14:23:46 -070049 /** @deprecated Selectors().setX(...).setY(...)
50 */
Alexander Afanasyev9c578182014-05-14 17:28:28 -070051 DEPRECATED(
Junxiao Shib332e782014-03-31 14:23:46 -070052 Selectors(int minSuffixComponents, int maxSuffixComponents,
Alexander Afanasyevc348f832014-02-17 16:35:17 -080053 const Exclude& exclude,
54 int childSelector,
Junxiao Shic2b8d242014-11-04 08:35:29 -070055 bool mustBeFresh));
Junxiao Shib332e782014-03-31 14:23:46 -070056
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070057 /**
58 * @brief Create from wire encoding
59 */
Junxiao Shic2b8d242014-11-04 08:35:29 -070060 explicit
61 Selectors(const Block& wire);
Alexander Afanasyevc348f832014-02-17 16:35:17 -080062
63 bool
64 empty() const;
Junxiao Shib332e782014-03-31 14:23:46 -070065
Alexander Afanasyevc348f832014-02-17 16:35:17 -080066 /**
67 * @brief Fast encoding or block size estimation
68 */
69 template<bool T>
70 size_t
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -070071 wireEncode(EncodingImpl<T>& block) const;
Junxiao Shib332e782014-03-31 14:23:46 -070072
Alexander Afanasyevc348f832014-02-17 16:35:17 -080073 /**
74 * @brief Encode to a wire format
75 */
76 const Block&
77 wireEncode() const;
78
79 /**
80 * @brief Decode the input from wire format
81 */
Junxiao Shib332e782014-03-31 14:23:46 -070082 void
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -070083 wireDecode(const Block& wire);
Alexander Afanasyevc348f832014-02-17 16:35:17 -080084
Junxiao Shic2b8d242014-11-04 08:35:29 -070085public: // getters & setters
Junxiao Shib332e782014-03-31 14:23:46 -070086 int
Alexander Afanasyevc348f832014-02-17 16:35:17 -080087 getMinSuffixComponents() const
88 {
89 return m_minSuffixComponents;
90 }
Junxiao Shib332e782014-03-31 14:23:46 -070091
92 Selectors&
Junxiao Shic2b8d242014-11-04 08:35:29 -070093 setMinSuffixComponents(int minSuffixComponents);
Junxiao Shib332e782014-03-31 14:23:46 -070094
95 int
Alexander Afanasyevc348f832014-02-17 16:35:17 -080096 getMaxSuffixComponents() const
97 {
98 return m_maxSuffixComponents;
99 }
100
Junxiao Shib332e782014-03-31 14:23:46 -0700101 Selectors&
Junxiao Shic2b8d242014-11-04 08:35:29 -0700102 setMaxSuffixComponents(int maxSuffixComponents);
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800103
Junxiao Shib332e782014-03-31 14:23:46 -0700104 const KeyLocator&
105 getPublisherPublicKeyLocator() const
106 {
107 return m_publisherPublicKeyLocator;
108 }
109
110 Selectors&
Junxiao Shic2b8d242014-11-04 08:35:29 -0700111 setPublisherPublicKeyLocator(const KeyLocator& keyLocator);
Junxiao Shib332e782014-03-31 14:23:46 -0700112
113 const Exclude&
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800114 getExclude() const
115 {
116 return m_exclude;
117 }
118
Junxiao Shib332e782014-03-31 14:23:46 -0700119 Selectors&
Junxiao Shic2b8d242014-11-04 08:35:29 -0700120 setExclude(const Exclude& exclude);
Junxiao Shib332e782014-03-31 14:23:46 -0700121
122 int
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800123 getChildSelector() const
124 {
125 return m_childSelector;
126 }
127
Junxiao Shib332e782014-03-31 14:23:46 -0700128 Selectors&
Junxiao Shic2b8d242014-11-04 08:35:29 -0700129 setChildSelector(int childSelector);
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800130
Junxiao Shib332e782014-03-31 14:23:46 -0700131 int
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800132 getMustBeFresh() const
133 {
134 return m_mustBeFresh;
135 }
136
Junxiao Shib332e782014-03-31 14:23:46 -0700137 Selectors&
Junxiao Shic2b8d242014-11-04 08:35:29 -0700138 setMustBeFresh(bool mustBeFresh);
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800139
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700140public: // EqualityComparable concept
141 bool
Junxiao Shic2b8d242014-11-04 08:35:29 -0700142 operator==(const Selectors& other) const;
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700143
144 bool
145 operator!=(const Selectors& other) const
146 {
Junxiao Shic2b8d242014-11-04 08:35:29 -0700147 return !this->operator==(other);
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700148 }
149
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800150private:
151 int m_minSuffixComponents;
Junxiao Shib332e782014-03-31 14:23:46 -0700152 int m_maxSuffixComponents;
153 KeyLocator m_publisherPublicKeyLocator;
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800154 Exclude m_exclude;
155 int m_childSelector;
156 bool m_mustBeFresh;
157
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700158 mutable Block m_wire;
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800159};
160
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800161} // namespace ndn
162
163#endif // NDN_SELECTORS_HPP