libqi-api  release-2.5.3-2016-11-18
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
buffer.hpp
Go to the documentation of this file.
1 #pragma once
2 /*
3 ** Copyright (C) 2012 Aldebaran Robotics
4 ** See COPYING for the license
5 */
6 
7 #ifndef _QI_BUFFER_HPP_
8 # define _QI_BUFFER_HPP_
9 
10 # include <qi/api.hpp>
11 # include <qi/types.hpp>
12 # include <boost/shared_ptr.hpp>
13 # include <vector>
14 # include <cstddef>
15 
16 #ifdef _MSC_VER
17 # pragma warning( push )
18 # pragma warning( disable: 4251 )
19 #endif
20 
21 namespace qi
22 {
23  class BufferPrivate;
24 
76  class QI_API Buffer
77  {
78  public:
80  Buffer();
81 
89  Buffer(const Buffer& buffer);
96  Buffer& operator = (const Buffer& buffer);
97 
103  Buffer(Buffer&& buffer);
104 
110  Buffer& operator = (Buffer&& buffer);
111 
118  bool write(const void *data, size_t size);
119 
127  size_t addSubBuffer(const Buffer& buffer);
133  bool hasSubBuffer(size_t offset) const;
140  const Buffer& subBuffer(size_t offset) const;
141 
142 
148  size_t size() const;
149 
155  size_t totalSize() const;
156 
162  const std::vector<std::pair<size_t, Buffer> >& subBuffers() const;
163 
170  void* reserve(size_t size);
174  void clear();
175 
176 
181  void* data();
186  const void* data() const;
187 
197  const void* read(size_t offset = 0, size_t length = 0) const;
198 
209  size_t read(void* buffer, size_t offset = 0, size_t length = 0) const;
210 
211  private:
212  friend class BufferReader;
213  // CS4251
214  boost::shared_ptr<BufferPrivate> _p;
215  };
216 
225  {
226  public:
231  explicit BufferReader(const Buffer& buf);
233  ~BufferReader();
234 
241  size_t read(void *data, size_t length);
242 
243 
249  void *read(size_t offset);
255  bool seek(size_t offset);
263  void *peek(size_t offset) const;
264 
265 
270  bool hasSubBuffer() const;
276  const Buffer& subBuffer();
281  size_t position() const;
282 
283  private:
284  Buffer _buffer;
285  size_t _cursor;
286  size_t _subCursor; // position in sub-buffers
287  };
288 
289  namespace detail {
290  QI_API void printBuffer(std::ostream& stream, const Buffer& buffer);
291  }
292 
293 }
294 
295 #ifdef _MSC_VER
296 # pragma warning( pop )
297 #endif
298 
299 #endif // _QI_BUFFER_HPP_
void printBuffer(std::ostream &stream, const Buffer &buffer)
#define QI_API
Definition: api.hpp:33
dll import/export and compiler message
Class to read const buffer. <includename>qi/buffer.hpp</includename> This class is intendeed to rea...
Definition: buffer.hpp:224
Class to store buffer. <includename>qi/buffer.hpp</includename> .
Definition: buffer.hpp:76