NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
buffer.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
24 #ifndef NDN_ENCODING_BUFFER_HPP
25 #define NDN_ENCODING_BUFFER_HPP
26 
27 #include "../common.hpp"
28 
29 #include <vector>
30 
31 namespace ndn {
32 
33 class Buffer;
34 typedef shared_ptr<const Buffer> ConstBufferPtr;
35 typedef shared_ptr<Buffer> BufferPtr;
36 
44 class Buffer : public std::vector<uint8_t>
45 {
46 public:
49  Buffer();
50 
54  explicit
55  Buffer(size_t size);
56 
61  Buffer(const void* buf, size_t length);
62 
68  template <class InputIterator>
69  Buffer(InputIterator first, InputIterator last)
70  : std::vector<uint8_t>(first, last)
71  {
72  }
73 
76  uint8_t*
77  get()
78  {
79  return &front();
80  }
81 
86  uint8_t*
87  buf()
88  {
89  return &front();
90  }
91 
95  template<class T>
96  T*
97  get()
98  {
99  return reinterpret_cast<T*>(&front());
100  }
101 
106  const uint8_t*
107  buf() const
108  {
109  return &front();
110  }
111 
114  const uint8_t*
115  get() const
116  {
117  return &front();
118  }
119 
123  template<class T>
124  const T*
125  get() const
126  {
127  return reinterpret_cast<const T*>(&front());
128  }
129 };
130 
131 } // namespace ndn
132 
133 #endif // NDN_ENCODING_BUFFER_HPP
Copyright (c) 2011-2015 Regents of the University of California.
const uint8_t * buf() const
Definition: buffer.hpp:107
Buffer()
Creates an empty buffer.
Definition: buffer.cpp:38
shared_ptr< Buffer > BufferPtr
Definition: buffer.hpp:35
STL namespace.
uint8_t * buf()
Definition: buffer.hpp:87
Buffer(InputIterator first, InputIterator last)
Create a buffer by copying contents of the range [first, last)
Definition: buffer.hpp:69
shared_ptr< const Buffer > ConstBufferPtr
Definition: buffer.hpp:33
Class representing a general-use automatically managed/resized buffer.
Definition: buffer.hpp:44