blob: 8315f349e4950a2950640a0a5879117e1d624fa3 [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/**
22 * @brief Class to represent Exclude component in NDN interests
23 */
Alexander Afanasyevabb493a2013-07-19 15:31:33 -070024class Exclude : public SimpleRefCount<Exclude>
Alexander Afanasyev92136012013-07-16 20:36:30 -070025{
26public:
27 typedef std::map< name::Component, bool /*any*/, std::greater<name::Component> > exclude_type;
28
29 typedef exclude_type::iterator iterator;
30 typedef exclude_type::const_iterator const_iterator;
31 typedef exclude_type::reverse_iterator reverse_iterator;
32 typedef exclude_type::const_reverse_iterator const_reverse_iterator;
33
34 /**
35 * @brief Default constructor an empty exclude
36 */
37 Exclude ();
38
Alexander Afanasyevabb493a2013-07-19 15:31:33 -070039 // no need for explicit copy constructor
40
Alexander Afanasyev92136012013-07-16 20:36:30 -070041 /**
42 * @brief Check if name component is excluded
43 * @param comp Name component to check against exclude filter
44 */
45 bool
46 isExcluded (const name::Component &comp) const;
47
48 /**
49 * @brief Exclude specific name component
50 * @param comp component to exclude
51 * @returns *this to allow chaining
52 */
53 Exclude &
54 excludeOne (const name::Component &comp);
55
56 /**
57 * @brief Exclude components from range [from, to]
58 * @param from first element of the range
59 * @param to last element of the range
60 * @returns *this to allow chaining
61 */
62 Exclude &
63 excludeRange (const name::Component &from, const name::Component &to);
64
65 /**
66 * @brief Exclude all components from range [/, to]
67 * @param to last element of the range
68 * @returns *this to allow chaining
69 */
70 inline Exclude &
71 excludeBefore (const name::Component &to);
72
73 /**
74 * @brief Exclude all components from range [from, +Inf]
75 * @param to last element of the range
76 * @returns *this to allow chaining
77 */
78 Exclude &
79 excludeAfter (const name::Component &from);
80
81 /**
82 * @brief Method to directly append exclude element
83 * @param name excluded name component
84 * @param any flag indicating if there is a postfix ANY component after the name
85 *
86 * This method is used during conversion from wire format of exclude filter
87 *
88 * If there is an error with ranges (e.g., order of components is wrong) an exception is thrown
89 */
90 void
91 appendExclude (const name::Component &name, bool any);
92
93 /**
94 * @brief Get number of exclude terms
95 */
96 inline size_t
97 size () const;
98
99 /**
100 * @brief Get begin iterator of the exclude terms
101 */
102 inline const_iterator
103 begin () const;
104
105 /**
106 * @brief Get end iterator of the exclude terms
107 */
108 inline const_iterator
109 end () const;
110
111 /**
112 * @brief Get begin iterator of the exclude terms
113 */
114 inline const_reverse_iterator
115 rbegin () const;
116
117 /**
118 * @brief Get end iterator of the exclude terms
119 */
120 inline const_reverse_iterator
121 rend () const;
122
123private:
124 Exclude &
125 excludeRange (iterator fromLowerBound, iterator toLowerBound);
126
127private:
128 exclude_type m_exclude;
129};
130
131std::ostream&
132operator << (std::ostream &os, const Exclude &name);
133
134inline Exclude &
135Exclude::excludeBefore (const name::Component &to)
136{
137 return excludeRange (name::Component (), to);
138}
139
140inline size_t
141Exclude::size () const
142{
143 return m_exclude.size ();
144}
145
146inline Exclude::const_iterator
147Exclude::begin () const
148{
149 return m_exclude.begin ();
150}
151
152inline Exclude::const_iterator
153Exclude::end () const
154{
155 return m_exclude.end ();
156}
157
158inline Exclude::const_reverse_iterator
159Exclude::rbegin () const
160{
161 return m_exclude.rbegin ();
162}
163
164inline Exclude::const_reverse_iterator
165Exclude::rend () const
166{
167 return m_exclude.rend ();
168}
169
170NDN_NAMESPACE_END
171
172#endif // NDN_EXCLUDE_H