blob: 2f8d118f8e769dc137be768a797dd10f653a7e50 [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -07002/**
Alexander Afanasyevc169a812014-05-20 20:37:29 -04003 * Copyright (c) 2013-2014 Regents of the University of California.
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -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 Afanasyevee8bb1e2014-05-02 17:39:54 -070020 */
21
22#ifndef NDN_DETAIL_INTEREST_FILTER_RECORD_HPP
23#define NDN_DETAIL_INTEREST_FILTER_RECORD_HPP
24
25#include "../common.hpp"
26#include "../name.hpp"
27#include "../interest.hpp"
28
29namespace ndn {
30
31class InterestFilterRecord : noncopyable
32{
33public:
34 typedef function<void (const InterestFilter&, const Interest&)> OnInterest;
35
36 InterestFilterRecord(const InterestFilter& filter, const OnInterest& onInterest)
37 : m_filter(filter)
38 , m_onInterest(onInterest)
39 {
40 }
41
42 /**
43 * @brief Check if Interest name matches the filter
44 * @param name Interest Name
45 */
46 bool
47 doesMatch(const Name& name) const
48 {
49 return m_filter.doesMatch(name);
50 }
51
52 void
53 operator()(const Interest& interest) const
54 {
55 m_onInterest(m_filter, interest);
56 }
57
58 const InterestFilter&
59 getFilter() const
60 {
61 return m_filter;
62 }
63
64private:
65 InterestFilter m_filter;
66 OnInterest m_onInterest;
67};
68
69
70/**
71 * @brief Opaque class representing ID of the Interest filter
72 */
73class InterestFilterId;
74
75/**
76 * @brief Functor to match InterestFilterId
77 */
78class MatchInterestFilterId
79{
80public:
81 explicit
82 MatchInterestFilterId(const InterestFilterId* interestFilterId)
83 : m_id(interestFilterId)
84 {
85 }
86
87 bool
Alexander Afanasyev984ad192014-05-02 19:11:15 -070088 operator()(const shared_ptr<InterestFilterRecord>& interestFilterId) const
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -070089 {
90 return (reinterpret_cast<const InterestFilterId*>(interestFilterId.get()) == m_id);
91 }
92private:
93 const InterestFilterId* m_id;
94};
95
96} // namespace ndn
97
98#endif // NDN_DETAIL_INTEREST_FILTER_RECORD_HPP