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