NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
interest-filter.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #include "interest-filter.hpp"
23 
25 
26 namespace ndn {
27 
28 InterestFilter::InterestFilter(const Name& prefix, const std::string& regexFilter)
29  : m_prefix(prefix)
30  , m_regexFilter(ndn::make_shared<RegexPatternListMatcher>(regexFilter,
31  shared_ptr<RegexBackrefManager>()))
32 {
33 }
34 
35 bool
37 {
38  if (name.size() < m_prefix.size())
39  return false;
40 
41  if (hasRegexFilter()) {
42  // perform prefix match and regular expression match for the remaining components
43  bool isMatch = m_prefix.isPrefixOf(name);
44 
45  if (!isMatch)
46  return false;
47 
48  return m_regexFilter->match(name, m_prefix.size(), name.size() - m_prefix.size());
49  }
50  else {
51  // perform just prefix match
52 
53  return m_prefix.isPrefixOf(name);
54  }
55 }
56 
57 std::ostream&
58 operator<<(std::ostream& os, const InterestFilter& filter)
59 {
60  os << filter.getPrefix();
61  if (filter.hasRegexFilter()) {
62  os << "?regex=" << filter.getRegexFilter();
63  }
64  return os;
65 }
66 
67 } // namespace ndn
Copyright (c) 2011-2015 Regents of the University of California.
const Name & getPrefix() const
std::ostream & operator<<(std::ostream &os, const Data &data)
Definition: data.cpp:320
bool doesMatch(const Name &name) const
Check if specified name matches the filter.
const RegexPatternListMatcher & getRegexFilter() const
Name abstraction to represent an absolute name.
Definition: name.hpp:46
bool isPrefixOf(const Name &name) const
Check if the N components of this name are the same as the first N components of the given name...
Definition: name.cpp:320
bool hasRegexFilter() const
size_t size() const
Get the number of components.
Definition: name.hpp:408
InterestFilter(const Name &prefix)
Create an Interest filter to match Interests by prefix.