libqi-api  2.4.3.28
 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 
104  bool write(const void *data, size_t size);
105 
113  size_t addSubBuffer(const Buffer& buffer);
119  bool hasSubBuffer(size_t offset) const;
126  const Buffer& subBuffer(size_t offset) const;
127 
128 
134  size_t size() const;
135 
141  size_t totalSize() const;
142 
148  const std::vector<std::pair<size_t, Buffer> >& subBuffers() const;
149 
156  void* reserve(size_t size);
160  void clear();
161 
162 
167  void* data();
172  const void* data() const;
173 
183  const void* read(size_t offset = 0, size_t length = 0) const;
184 
195  size_t read(void* buffer, size_t offset = 0, size_t length = 0) const;
196 
197  private:
198  friend class BufferReader;
199  // CS4251
200  boost::shared_ptr<BufferPrivate> _p;
201  };
202 
211  {
212  public:
217  explicit BufferReader(const Buffer& buf);
219  ~BufferReader();
220 
227  size_t read(void *data, size_t length);
228 
229 
235  void *read(size_t offset);
241  bool seek(size_t offset);
249  void *peek(size_t offset) const;
250 
251 
256  bool hasSubBuffer() const;
262  const Buffer& subBuffer();
267  size_t position() const;
268 
269  private:
270  Buffer _buffer;
271  size_t _cursor;
272  size_t _subCursor; // position in sub-buffers
273  };
274 
275  namespace detail {
276  QI_API void printBuffer(std::ostream& stream, const Buffer& buffer);
277  }
278 
279 }
280 
281 #ifdef _MSC_VER
282 # pragma warning( pop )
283 #endif
284 
285 #endif // _QI_BUFFER_HPP_
void printBuffer(std::ostream &stream, const Buffer &buffer)
#define QI_API
Definition: api.hpp:34
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:210
Class to store buffer. <includename>qi/buffer.hpp</includename> .
Definition: buffer.hpp:76