Rumba C++ SDK
Buffer.h
Go to the documentation of this file.
1 /*
2 
3  *
4  ***
5  *****
6  ********************* Mercenaries Engineering SARL
7  ***************** Copyright (C) 2018
8  *************
9  ********* http://www.mercenaries-engineering.com
10  ***********
11  **** ****
12  ** **
13 
14 */
15 #pragma once
16 
17 #include "Value.h"
18 #include "Impl.h"
19 
20  namespace maquina
21  {
23 
39  template<typename T>
40  class BufferConst : public Value
41  {
42  public:
43  typedef T value_type;
44  typedef T& reference;
45  typedef const T& const_reference;
46  typedef T* iterator;
47  typedef const T* const_iterator;
48 
50  BufferConst();
51 
53 
54  BufferConst(const Value &v);
55 
57  BufferConst(const gsl::span<const T> &content);
58 
60  bool empty() const;
61 
63  size_t size() const;
64 
66 
67  gsl::span<const value_type> read() const;
68 
70 
72  size_t i
73  ) const;
74 
76  const_iterator begin() const;
77 
79  const_iterator end() const;
80 
82  BufferConst(const std::shared_ptr<Impl> &impl) { _impl=impl; }
83 
86  };
87 
89 
105  template<typename T>
106  class Buffer : public BufferConst<T>
107  {
108  public:
109  typedef T value_type;
110  typedef T& reference;
111  typedef const T& const_reference;
112  typedef T* iterator;
113  typedef const T* const_iterator;
114 
116  Buffer();
117 
119 
120  Buffer(const Value &v);
121 
123  Buffer(
124  size_t size
125  );
126 
128 
129  void resize(
130  size_t size,
131  const T &d = T()
132  );
133 
135 
136  void grow(
137  size_t size
138  );
139 
141 
142  gsl::span<value_type> write();
143 
145 
147  size_t i
148  );
149 
151  iterator begin();
152 
154  iterator end();
155 
157  Buffer(const std::shared_ptr<Impl> &impl) : BufferConst<T>(impl) {}
158  };
159 
160  template<typename T>
162  {
163  return a.duplicate()._impl;
164  }
165 
181 
182 #ifndef kernel_EXPORTS
197 #endif // kernel_EXPORTS
198 
199  typedef Buffer<int32_t> BufferInt32;
200  typedef Buffer<uint8_t> BufferUInt8;
201  typedef Buffer<uint32_t> BufferUInt32;
202  typedef Buffer<float> BufferFloat;
203  typedef Buffer<double> BufferDouble;
204  typedef Buffer<Imath::V2f> BufferV2f;
205  typedef Buffer<Imath::V3f> BufferV3f;
206  typedef Buffer<Imath::V4f> BufferV4f;
207  typedef Buffer<Imath::V2i> BufferV2i;
208  typedef Buffer<Imath::V3i> BufferV3i;
209  typedef Buffer<Imath::V4i> BufferV4i;
210  typedef Buffer<Imath::M33f> BufferM33f;
211  typedef Buffer<Imath::M44f> BufferM44f;
212  typedef Buffer<Imath::Box3f> BufferBox3f;
213 
214 #ifndef kernel_EXPORTS
226  MAQUINA_EXTERN_TEMPLATE class MAQUINA_EXPORT Buffer<Imath::M33f>;
227  MAQUINA_EXTERN_TEMPLATE class MAQUINA_EXPORT Buffer<Imath::M44f>;
228  MAQUINA_EXTERN_TEMPLATE class MAQUINA_EXPORT Buffer<Imath::Box3f>;
229 #endif // kernel_EXPORTS
230  }
BufferConst< float > BufferConstFloat
Definition: Buffer.h:170
BufferConst< uint32_t > BufferConstUInt32
Definition: Buffer.h:169
BufferConst< Imath::V4i > BufferConstV4i
Definition: Buffer.h:177
iterator begin()
Return the beginning iterator.
const T * const_iterator
Definition: Buffer.h:47
const_iterator end() const
Return the ending iterator.
Definition: ImathFrame.h:42
T * iterator
Definition: Buffer.h:112
static const BufferConst< T > default_value
The default value.
Definition: Buffer.h:85
A readonly buffer for basic types like floats, integers, Imath::V3f, Imath::M44f..
Definition: Buffer.h:40
Buffer< T > duplicate(const BufferConst< T > &a)
Definition: Buffer.h:161
const T & const_reference
Definition: Buffer.h:111
BufferConst< Imath::Box3f > BufferConstBox3f
Definition: Buffer.h:180
BufferConst< Imath::M44f > BufferConstM44f
Definition: Buffer.h:179
This version of the SDK is unstable, i-e, it may change with no warning.
Definition: AddCurveAction.h:20
void grow(size_t size)
Grow the buffer in order for it to be large enough for this size.
bool empty() const
Returns true if the buffer is empty.
BufferConst< Imath::V4f > BufferConstV4f
Definition: Buffer.h:174
const T * const_iterator
Definition: Buffer.h:113
BufferConst< Imath::V3f > BufferConstV3f
Definition: Buffer.h:173
gsl::span< value_type > write()
Return a writable accessor on the buffer data.
T value_type
Definition: Buffer.h:43
#define MAQUINA_EXPORT
Definition: Export.h:31
iterator end()
Return the ending iterator.
BufferConst< Imath::V2i > BufferConstV2i
Definition: Buffer.h:175
void resize(size_t size, const T &d=T())
Resize the buffer.
BufferConst< uint8_t > BufferConstUInt8
Definition: Buffer.h:168
const T & const_reference
Definition: Buffer.h:45
BufferConst< int32_t > BufferConstInt32
Definition: Buffer.h:167
size_t size() const
Return the number of element in the buffer.
A writable buffer for basic types like floats, integers, Imath::V3f, Imath::M44f..
Definition: Buffer.h:106
const_iterator begin() const
Return the beginning iterator.
BufferConst()
Construct an empty buffer.
#define MAQUINA_EXTERN_TEMPLATE
Definition: Export.h:25
reference operator[](size_t i)
Returns the i-th array element.
BufferConst< double > BufferConstDouble
Definition: Buffer.h:171
T & reference
Definition: Buffer.h:110
BufferConst< Imath::V2f > BufferConstV2f
Definition: Buffer.h:172
T * iterator
Definition: Buffer.h:46
const_reference operator[](size_t i) const
Returns the i-th array element.
BufferConst< Imath::M33f > BufferConstM33f
Definition: Buffer.h:178
T value_type
Definition: Buffer.h:109
Definition: ImathBox.h:67
gsl::span< const value_type > read() const
Return the readable data.
Buffer()
Construct an empty buffer.
Vec2< float > V2f
Definition: ImathVec.h:688
Value duplicate() const
Duplicate the value.
T & reference
Definition: Buffer.h:44
BufferConst< Imath::V3i > BufferConstV3i
Definition: Buffer.h:176
Base class of all Rumba values.
Definition: Value.h:34