interest-filter.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2022 Regents of the University of California.
4  *
5  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6  *
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.
20  */
21 
22 #ifndef NDN_CXX_INTEREST_FILTER_HPP
23 #define NDN_CXX_INTEREST_FILTER_HPP
24 
25 #include "ndn-cxx/name.hpp"
26 
27 namespace ndn {
28 
29 class RegexPatternListMatcher;
30 
37 {
38 public:
39  class Error : public std::runtime_error
40  {
41  public:
42  using std::runtime_error::runtime_error;
43  };
44 
52  InterestFilter(const Name& prefix);
53 
62  InterestFilter(const char* prefixUri);
63 
72  InterestFilter(const std::string& prefixUri);
73 
92  InterestFilter(const Name& prefix, const std::string& regexFilter);
93 
99  operator const Name&() const;
100 
104  bool
105  doesMatch(const Name& name) const;
106 
107  const Name&
108  getPrefix() const
109  {
110  return m_prefix;
111  }
112 
113  bool
115  {
116  return m_regexFilter != nullptr;
117  }
118 
121  {
122  return *m_regexFilter;
123  }
124 
128  NDN_CXX_NODISCARD bool
129  allowsLoopback() const noexcept
130  {
131  return m_allowsLoopback;
132  }
133 
141  allowLoopback(bool wantLoopback) noexcept
142  {
143  m_allowsLoopback = wantLoopback;
144  return *this;
145  }
146 
147 private:
148  Name m_prefix;
149  shared_ptr<RegexPatternListMatcher> m_regexFilter;
150  bool m_allowsLoopback = true;
151 };
152 
153 std::ostream&
154 operator<<(std::ostream& os, const InterestFilter& filter);
155 
156 } // namespace ndn
157 
158 #endif // NDN_CXX_INTEREST_FILTER_HPP
#define NDN_CXX_NODISCARD
Definition: backports.hpp:68
Declares the set of Interests a producer can serve.
const Name & getPrefix() const
bool hasRegexFilter() const
bool allowsLoopback() const noexcept
Get whether Interest loopback is allowed.
InterestFilter(const Name &prefix)
Construct an InterestFilter to match Interests by prefix.
bool doesMatch(const Name &name) const
Check if specified Interest name matches the filter.
const RegexPatternListMatcher & getRegexFilter() const
InterestFilter & allowLoopback(bool wantLoopback) noexcept
Set whether Interest loopback is allowed.
Represents an absolute name.
Definition: name.hpp:44
Definition: data.cpp:25
std::ostream & operator<<(std::ostream &os, const Data &data)
Definition: data.cpp:374