libqi-api  2.4.3.28
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
buffertypeinterface.hxx
Go to the documentation of this file.
1 #pragma once
2 /*
3 ** Copyright (C) 2013 Aldebaran Robotics
4 ** See COPYING for the license
5 */
6 
7 #ifndef _QITYPE_DETAILS_TYPEBUFFER_HXX_
8 #define _QITYPE_DETAILS_TYPEBUFFER_HXX_
9 
10 #include <qi/buffer.hpp>
11 
12 namespace qi
13 {
15  {
16  public:
17  virtual std::pair<char*, size_t> get(void *storage)
18  {
19  Buffer* b = (Buffer*)Methods::ptrFromStorage(&storage);
20  return std::make_pair(const_cast<char*>((const char*)b->data()), b->size());
21  }
22  virtual void set(void** storage, const char* ptr, size_t sz)
23  {
24  Buffer* b = (Buffer*)ptrFromStorage(storage);
25  b->clear();
26  b->write(ptr, sz);
27  }
30  };
31 
32 template<> class TypeImpl<Buffer>: public TypeBufferImpl {};
33 }
34 
35 #endif // _QITYPE_DETAILS_TYPEBUFFER_HXX_
virtual void * ptrFromStorage(void **)=0
bool write(const void *data, size_t size)
Write data in the buffer.
virtual void set(void **storage, const char *ptr, size_t sz)
Set the buffer of data (buffer is copied)
void * data()
Return a pointer to the raw data storage of this buffer.
void clear()
Erase content of buffer and remove sub-buffers whithout clearing them.
static void * ptrFromStorage(void **storage)
Definition: typeimpl.hxx:238
_QI_BOUNCE_TYPE_METHODS(Methods)
size_t size() const
Return the content size of this buffer not counting sub-buffers.
DefaultTypeImplMethods< Buffer, TypeByPointerPOD< Buffer > > Methods
Class to store buffer. <includename>qi/buffer.hpp</includename> .
Definition: buffer.hpp:76