blob: fcdcbb365f63eeb6b4a1ae3c611b23db86f848db [file] [log] [blame]
Alexander Afanasyev92136012013-07-16 20:36:30 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2013, Regents of the University of California
4 * Alexander Afanasyev
5 *
6 * BSD license, See the LICENSE file for more information
7 *
8 * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
9 */
10
11#ifndef NDN_EXCLUDE_H
12#define NDN_EXCLUDE_H
13
Alexander Afanasyevabb493a2013-07-19 15:31:33 -070014#include <ns3/simple-ref-count.h>
Alexander Afanasyev92136012013-07-16 20:36:30 -070015
Alexander Afanasyevabb493a2013-07-19 15:31:33 -070016#include "name-component.h"
Alexander Afanasyev92136012013-07-16 20:36:30 -070017#include <map>
18
19NDN_NAMESPACE_BEGIN
20
21/**
Alexander Afanasyev79206512013-07-27 16:49:12 -070022 * @ingroup ndn-cxx
Alexander Afanasyev92136012013-07-16 20:36:30 -070023 * @brief Class to represent Exclude component in NDN interests
24 */
Alexander Afanasyevabb493a2013-07-19 15:31:33 -070025class Exclude : public SimpleRefCount<Exclude>
Alexander Afanasyev92136012013-07-16 20:36:30 -070026{
27public:
28 typedef std::map< name::Component, bool /*any*/, std::greater<name::Component> > exclude_type;
29
30 typedef exclude_type::iterator iterator;
31 typedef exclude_type::const_iterator const_iterator;
32 typedef exclude_type::reverse_iterator reverse_iterator;
33 typedef exclude_type::const_reverse_iterator const_reverse_iterator;
34
35 /**
36 * @brief Default constructor an empty exclude
37 */
38 Exclude ();
39
Alexander Afanasyevabb493a2013-07-19 15:31:33 -070040 // no need for explicit copy constructor
41
Alexander Afanasyev92136012013-07-16 20:36:30 -070042 /**
43 * @brief Check if name component is excluded
44 * @param comp Name component to check against exclude filter
45 */
46 bool
47 isExcluded (const name::Component &comp) const;
48
49 /**
50 * @brief Exclude specific name component
51 * @param comp component to exclude
52 * @returns *this to allow chaining
53 */
54 Exclude &
55 excludeOne (const name::Component &comp);
56
57 /**
58 * @brief Exclude components from range [from, to]
59 * @param from first element of the range
60 * @param to last element of the range
61 * @returns *this to allow chaining
62 */
63 Exclude &
64 excludeRange (const name::Component &from, const name::Component &to);
65
66 /**
67 * @brief Exclude all components from range [/, to]
68 * @param to last element of the range
69 * @returns *this to allow chaining
70 */
71 inline Exclude &
72 excludeBefore (const name::Component &to);
73
74 /**
75 * @brief Exclude all components from range [from, +Inf]
76 * @param to last element of the range
77 * @returns *this to allow chaining
78 */
79 Exclude &
80 excludeAfter (const name::Component &from);
81
82 /**
83 * @brief Method to directly append exclude element
84 * @param name excluded name component
85 * @param any flag indicating if there is a postfix ANY component after the name
86 *
87 * This method is used during conversion from wire format of exclude filter
88 *
89 * If there is an error with ranges (e.g., order of components is wrong) an exception is thrown
90 */
91 void
92 appendExclude (const name::Component &name, bool any);
93
94 /**
95 * @brief Get number of exclude terms
96 */
97 inline size_t
98 size () const;
99
100 /**
101 * @brief Get begin iterator of the exclude terms
102 */
103 inline const_iterator
104 begin () const;
105
106 /**
107 * @brief Get end iterator of the exclude terms
108 */
109 inline const_iterator
110 end () const;
111
112 /**
113 * @brief Get begin iterator of the exclude terms
114 */
115 inline const_reverse_iterator
116 rbegin () const;
117
118 /**
119 * @brief Get end iterator of the exclude terms
120 */
121 inline const_reverse_iterator
122 rend () const;
123
124private:
125 Exclude &
126 excludeRange (iterator fromLowerBound, iterator toLowerBound);
127
128private:
129 exclude_type m_exclude;
130};
131
132std::ostream&
133operator << (std::ostream &os, const Exclude &name);
134
135inline Exclude &
136Exclude::excludeBefore (const name::Component &to)
137{
138 return excludeRange (name::Component (), to);
139}
140
141inline size_t
142Exclude::size () const
143{
144 return m_exclude.size ();
145}
146
147inline Exclude::const_iterator
148Exclude::begin () const
149{
150 return m_exclude.begin ();
151}
152
153inline Exclude::const_iterator
154Exclude::end () const
155{
156 return m_exclude.end ();
157}
158
159inline Exclude::const_reverse_iterator
160Exclude::rbegin () const
161{
162 return m_exclude.rbegin ();
163}
164
165inline Exclude::const_reverse_iterator
166Exclude::rend () const
167{
168 return m_exclude.rend ();
169}
170
171NDN_NAMESPACE_END
172
173#endif // NDN_EXCLUDE_H