blob: 962bfe5ba1d8ede05c8cfaf9e77f188c64be5220 [file] [log] [blame]
Jeff Thompsonfa306642013-06-17 15:06:57 -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_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
19namespace ndn {
20
21/**
22 * @brief Class implementing abstractions to work with NDN Data packets
23 */
24class Data
25{
26public:
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 */
Jeff Thompson29310402013-06-19 13:32:26 -070064 inline ptr_lib::shared_ptr<const Signature>
Jeff Thompsonfa306642013-06-17 15:06:57 -070065 getSignature () const;
66
67 /**
68 * @brief Get smart pointer to signature object
69 */
Jeff Thompson29310402013-06-19 13:32:26 -070070 inline ptr_lib::shared_ptr<Signature>
Jeff Thompsonfa306642013-06-17 15:06:57 -070071 getSignature ();
72
73 /**
74 * @brief Set signature object
75 * @param signature smart pointer to a signature object
76 */
77 inline void
Jeff Thompson29310402013-06-19 13:32:26 -070078 setSignature (ptr_lib::shared_ptr<Signature> sigature);
Jeff Thompsonfa306642013-06-17 15:06:57 -070079
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
127private:
128 Name m_name;
Jeff Thompson29310402013-06-19 13:32:26 -0700129 ptr_lib::shared_ptr<Signature> m_signature; // signature with its parameters "binds" name and content
Jeff Thompsonfa306642013-06-17 15:06:57 -0700130 Content m_content;
131
Jeff Thompson29310402013-06-19 13:32:26 -0700132 ptr_lib::shared_ptr<SignedBlob> m_wire;
Jeff Thompsonfa306642013-06-17 15:06:57 -0700133};
134
135inline Data &
136Data::setName (const Name &name)
137{
138 m_name = name;
139 return *this;
140}
141
142inline const Name &
143Data::getName () const
144{
145 return m_name;
146}
147
148inline Name &
149Data::getName ()
150{
151 return m_name;
152}
153
Jeff Thompson29310402013-06-19 13:32:26 -0700154inline ptr_lib::shared_ptr<const Signature>
Jeff Thompsonfa306642013-06-17 15:06:57 -0700155Data::getSignature () const
156{
157 return m_signature;
158}
159
Jeff Thompson29310402013-06-19 13:32:26 -0700160inline ptr_lib::shared_ptr<Signature>
Jeff Thompsonfa306642013-06-17 15:06:57 -0700161Data::getSignature ()
162{
163 return m_signature;
164}
165
166inline void
Jeff Thompson29310402013-06-19 13:32:26 -0700167Data::setSignature (ptr_lib::shared_ptr<Signature> signature)
Jeff Thompsonfa306642013-06-17 15:06:57 -0700168{
169 m_signature = signature;
170}
171
172inline const Content &
173Data::getContent () const
174{
175 return m_content;
176}
177
178inline Content &
179Data::getContent ()
180{
181 return m_content;
182}
183
184inline void
185Data::setContent (const Content &content)
186{
187 m_content = content;
188}
189
190inline const Blob &
191Data::content () const
192{
193 return getContent ().getContent ();
194}
195
196inline Blob &
197Data::content ()
198{
199 return getContent ().getContent ();
200}
201
202} // namespace ndn
203
204#endif // NDN_DATA_H