NS-3 based Named Data Networking (NDN) simulator
ndnSIM: NDN, CCN, CCNx, content centric networks
API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
name-component.h
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_NAME_COMPONENT_H
12 #define NDN_NAME_COMPONENT_H
13 
14 #include "blob.h"
15 
16 NDN_NAMESPACE_BEGIN
17 
18 namespace name {
19 
28 class Component : public Blob
29 {
30 public:
34  Component ();
35 
40  Component (const std::string &uri);
41 
47  Component (std::string::const_iterator begin, std::string::const_iterator end);
48 
54  Component (const void *buf, size_t length);
55 
64  int
65  compare (const Component &other) const;
66 
72  inline bool
73  operator <= (const Component &other) const;
74 
80  inline bool
81  operator < (const Component &other) const;
82 
88  inline bool
89  operator >= (const Component &other) const;
90 
96  inline bool
97  operator > (const Component &other) const;
98 
100  // Component construction helpers //
102 
108  Component &
109  fromUri (const std::string &uri);
110 
117  Component &
118  fromUri (std::string::const_iterator begin, std::string::const_iterator end);
119 
132  Component &
133  fromNumber (uint64_t number);
134 
152  Component &
153  fromNumberWithMarker (uint64_t number, unsigned char marker);
154 
156  // helpers
158 
164  std::string
165  toBlob () const;
166 
171  void
172  toBlob (std::ostream &os) const;
173 
179  std::string
180  toUri () const;
181 
186  void
187  toUri (std::ostream &os) const;
188 
193  uint64_t
194  toNumber () const;
195 
203  uint64_t
204  toNumberWithMarker (unsigned char marker) const;
205 
211  inline uint64_t
212  toSeqNum () const;
213 
219  inline uint64_t
220  toControlNum () const;
221 
227  inline uint64_t
228  toBlkId () const;
229 
235  inline uint64_t
236  toVersion () const;
237 };
238 
239 bool
240 Component::operator <= (const Component &other) const
241 {
242  return (compare (other) <= 0);
243 }
244 
245 bool
246 Component::operator < (const Component &other) const
247 {
248  return (compare (other) < 0);
249 }
250 
251 bool
252 Component::operator >= (const Component &other) const
253 {
254  return (compare (other) >= 0);
255 }
256 
257 bool
258 Component::operator > (const Component &other) const
259 {
260  return (compare (other) > 0);
261 }
262 
263 inline uint64_t
264 Component::toSeqNum () const
265 {
266  return toNumberWithMarker (0x00);
267 }
268 
269 inline uint64_t
270 Component::toControlNum () const
271 {
272  return toNumberWithMarker (0xC1);
273 }
274 
275 inline uint64_t
276 Component::toBlkId () const
277 {
278  return toNumberWithMarker (0xFB);
279 }
280 
281 inline uint64_t
282 Component::toVersion () const
283 {
284  return toNumberWithMarker (0xFD);
285 }
286 
290 inline std::ostream&
291 operator <<(std::ostream &os, const Component &name)
292 {
293  name.toUri (os);
294  return os;
295 }
296 
297 } // name
298 
299 NDN_NAMESPACE_END
300 
301 #endif // NDN_NAME_COMPONENT_H
std::string toUri() const
Convert binary blob name component to std::string, escaping all non-printable characters in URI forma...
Class representing a general-use binary blob.
Definition: blob.h:26
Class to representing binary blob of NDN name component.