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_DATA_H |
| 12 | #define NDN_DATA_H |
| 13 | |
| 14 | #include "ndn-cpp/fields/name.h" |
| 15 | #include "ndn-cpp/fields/content.h" |
| 16 | #include "ndn-cpp/fields/signature.h" |
| 17 | #include "ndn-cpp/fields/signed-blob.h" |
| 18 | |
| 19 | namespace ndn { |
| 20 | |
| 21 | /** |
| 22 | * @brief Class implementing abstractions to work with NDN Data packets |
| 23 | */ |
| 24 | class Data |
| 25 | { |
| 26 | public: |
| 27 | /** |
| 28 | * @brief Create an empty Data with empty payload |
| 29 | **/ |
| 30 | Data (); |
| 31 | |
| 32 | /** |
| 33 | * @brief Destructor |
| 34 | */ |
| 35 | ~Data (); |
| 36 | |
| 37 | /** |
| 38 | * @brief Set data packet name |
| 39 | * @param name name of the data packet |
| 40 | * @return reference to self (to allow method chaining) |
| 41 | * |
| 42 | * In some cases, a direct access to and manipulation of name using getName is more efficient |
| 43 | */ |
| 44 | inline Data & |
| 45 | setName (const Name &name); |
| 46 | |
| 47 | /** |
| 48 | * @brief Get data packet name (const reference) |
| 49 | * @returns name of the data packet |
| 50 | */ |
| 51 | inline const Name & |
| 52 | getName () const; |
| 53 | |
| 54 | /** |
| 55 | * @brief Get data packet name (reference) |
| 56 | * @returns name of the data packet |
| 57 | */ |
| 58 | inline Name & |
| 59 | getName (); |
| 60 | |
| 61 | /** |
| 62 | * @brief Get const smart pointer to signature object |
| 63 | */ |
| 64 | inline Ptr<const Signature> |
| 65 | getSignature () const; |
| 66 | |
| 67 | /** |
| 68 | * @brief Get smart pointer to signature object |
| 69 | */ |
| 70 | inline Ptr<Signature> |
| 71 | getSignature (); |
| 72 | |
| 73 | /** |
| 74 | * @brief Set signature object |
| 75 | * @param signature smart pointer to a signature object |
| 76 | */ |
| 77 | inline void |
| 78 | setSignature (Ptr<Signature> sigature); |
| 79 | |
| 80 | /** |
| 81 | * @brief Get const reference to content object (content info + actual content) |
| 82 | */ |
| 83 | inline const Content & |
| 84 | getContent () const; |
| 85 | |
| 86 | /** |
| 87 | * @brief Get reference to content object (content info + actual content) |
| 88 | */ |
| 89 | inline Content & |
| 90 | getContent (); |
| 91 | |
| 92 | /** |
| 93 | * @brief Set content object (content info + actual content) |
| 94 | * @param content reference to a content object |
| 95 | * |
| 96 | * More efficient way (that avoids copying): |
| 97 | * @code |
| 98 | * Content content (...); |
| 99 | * getContent ().swap (content); |
| 100 | * @endcode |
| 101 | */ |
| 102 | inline void |
| 103 | setContent (const Content &content); |
| 104 | |
| 105 | /** |
| 106 | * @brief A helper method to directly access actual content data (const reference) |
| 107 | * |
| 108 | * This method is equivalent to |
| 109 | * @code |
| 110 | * getContent ().getContent () |
| 111 | * @endcode |
| 112 | */ |
| 113 | inline const Blob & |
| 114 | content () const; |
| 115 | |
| 116 | /** |
| 117 | * @brief A helper method to directly access actual content data (reference) |
| 118 | * |
| 119 | * This method is equivalent to |
| 120 | * @code |
| 121 | * getContent ().getContent () |
| 122 | * @endcode |
| 123 | */ |
| 124 | inline Blob & |
| 125 | content (); |
| 126 | |
| 127 | private: |
| 128 | Name m_name; |
| 129 | Ptr<Signature> m_signature; // signature with its parameters "binds" name and content |
| 130 | Content m_content; |
| 131 | |
| 132 | Ptr<SignedBlob> m_wire; |
| 133 | }; |
| 134 | |
| 135 | inline Data & |
| 136 | Data::setName (const Name &name) |
| 137 | { |
| 138 | m_name = name; |
| 139 | return *this; |
| 140 | } |
| 141 | |
| 142 | inline const Name & |
| 143 | Data::getName () const |
| 144 | { |
| 145 | return m_name; |
| 146 | } |
| 147 | |
| 148 | inline Name & |
| 149 | Data::getName () |
| 150 | { |
| 151 | return m_name; |
| 152 | } |
| 153 | |
| 154 | inline Ptr<const Signature> |
| 155 | Data::getSignature () const |
| 156 | { |
| 157 | return m_signature; |
| 158 | } |
| 159 | |
| 160 | inline Ptr<Signature> |
| 161 | Data::getSignature () |
| 162 | { |
| 163 | return m_signature; |
| 164 | } |
| 165 | |
| 166 | inline void |
| 167 | Data::setSignature (Ptr<Signature> signature) |
| 168 | { |
| 169 | m_signature = signature; |
| 170 | } |
| 171 | |
| 172 | inline const Content & |
| 173 | Data::getContent () const |
| 174 | { |
| 175 | return m_content; |
| 176 | } |
| 177 | |
| 178 | inline Content & |
| 179 | Data::getContent () |
| 180 | { |
| 181 | return m_content; |
| 182 | } |
| 183 | |
| 184 | inline void |
| 185 | Data::setContent (const Content &content) |
| 186 | { |
| 187 | m_content = content; |
| 188 | } |
| 189 | |
| 190 | inline const Blob & |
| 191 | Data::content () const |
| 192 | { |
| 193 | return getContent ().getContent (); |
| 194 | } |
| 195 | |
| 196 | inline Blob & |
| 197 | Data::content () |
| 198 | { |
| 199 | return getContent ().getContent (); |
| 200 | } |
| 201 | |
| 202 | } // namespace ndn |
| 203 | |
| 204 | #endif // NDN_DATA_H |