Alexander Afanasyev | 9213601 | 2013-07-16 20:36:30 -0700 | [diff] [blame] | 1 | /* -*- 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 Afanasyev | abb493a | 2013-07-19 15:31:33 -0700 | [diff] [blame] | 14 | #include <ns3/simple-ref-count.h> |
Alexander Afanasyev | 9213601 | 2013-07-16 20:36:30 -0700 | [diff] [blame] | 15 | |
Alexander Afanasyev | abb493a | 2013-07-19 15:31:33 -0700 | [diff] [blame] | 16 | #include "name-component.h" |
Alexander Afanasyev | 9213601 | 2013-07-16 20:36:30 -0700 | [diff] [blame] | 17 | #include <map> |
| 18 | |
| 19 | NDN_NAMESPACE_BEGIN |
| 20 | |
| 21 | /** |
Alexander Afanasyev | 7920651 | 2013-07-27 16:49:12 -0700 | [diff] [blame] | 22 | * @ingroup ndn-cxx |
Alexander Afanasyev | 9213601 | 2013-07-16 20:36:30 -0700 | [diff] [blame] | 23 | * @brief Class to represent Exclude component in NDN interests |
| 24 | */ |
Alexander Afanasyev | abb493a | 2013-07-19 15:31:33 -0700 | [diff] [blame] | 25 | class Exclude : public SimpleRefCount<Exclude> |
Alexander Afanasyev | 9213601 | 2013-07-16 20:36:30 -0700 | [diff] [blame] | 26 | { |
| 27 | public: |
| 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 Afanasyev | abb493a | 2013-07-19 15:31:33 -0700 | [diff] [blame] | 40 | // no need for explicit copy constructor |
| 41 | |
Alexander Afanasyev | 9213601 | 2013-07-16 20:36:30 -0700 | [diff] [blame] | 42 | /** |
| 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 | |
| 124 | private: |
| 125 | Exclude & |
| 126 | excludeRange (iterator fromLowerBound, iterator toLowerBound); |
| 127 | |
| 128 | private: |
| 129 | exclude_type m_exclude; |
| 130 | }; |
| 131 | |
| 132 | std::ostream& |
| 133 | operator << (std::ostream &os, const Exclude &name); |
| 134 | |
| 135 | inline Exclude & |
| 136 | Exclude::excludeBefore (const name::Component &to) |
| 137 | { |
| 138 | return excludeRange (name::Component (), to); |
| 139 | } |
| 140 | |
| 141 | inline size_t |
| 142 | Exclude::size () const |
| 143 | { |
| 144 | return m_exclude.size (); |
| 145 | } |
| 146 | |
| 147 | inline Exclude::const_iterator |
| 148 | Exclude::begin () const |
| 149 | { |
| 150 | return m_exclude.begin (); |
| 151 | } |
| 152 | |
| 153 | inline Exclude::const_iterator |
| 154 | Exclude::end () const |
| 155 | { |
| 156 | return m_exclude.end (); |
| 157 | } |
| 158 | |
| 159 | inline Exclude::const_reverse_iterator |
| 160 | Exclude::rbegin () const |
| 161 | { |
| 162 | return m_exclude.rbegin (); |
| 163 | } |
| 164 | |
| 165 | inline Exclude::const_reverse_iterator |
| 166 | Exclude::rend () const |
| 167 | { |
| 168 | return m_exclude.rend (); |
| 169 | } |
| 170 | |
| 171 | NDN_NAMESPACE_END |
| 172 | |
| 173 | #endif // NDN_EXCLUDE_H |