AGX Dynamics 2.42.3.0
Loading...
Searching...
No Matches
BinaryOutputView.h
Go to the documentation of this file.
1/*
2Copyright 2007-2025. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17#pragma once
18
19#include <agxSensor/export.h>
20
21#include <agx/agx.h>
22
23namespace agxSensor
24{
28 template<typename T>
30 {
31 public:
32 using value_type = T;
33
34 struct iterator
35 {
36 using difference_type = std::ptrdiff_t;
37 using value_type = T;
38 using pointer = T*;
39 using reference = T&;
40 using iterator_category = std::random_access_iterator_tag;
41 };
42
43 public:
47 inline BinaryOutputView() = default;
48
55 BinaryOutputView( const void* buffer, size_t size );
56
60 size_t size() const;
61
65 bool empty() const;
66
70 const T* begin() const;
71
75 const T* end() const;
76
82 const T& operator[]( size_t localIndex ) const;
83
85
86 private:
87 const T* m_buffer = nullptr;
88 size_t m_size = 0u;
89
91 };
92
97 {
98 public:
102 size_t size() const;
103
107 size_t elementSize() const;
108
112 bool empty() const;
113
119 void resize( size_t size, size_t elementSize );
120
124 void* rwPtr();
125
129 const void* rwPtr() const;
130
134 template<typename T>
135 const T* ptr() const;
136
143 template<typename T>
144 BinaryOutputView<T> view( size_t startIndex = 0u,
145 size_t numElements = agx::InvalidIndex ) const;
146
148
149 public:
152
153 BinaryOutputBuffer(const BinaryOutputBuffer&) = delete;
154
155 private:
156 char* m_buffer;
157 size_t m_size;
158 size_t m_elementSize;
159
161 };
162
163 template<typename T>
164 inline BinaryOutputView<T>::BinaryOutputView( const void* buffer, size_t size )
165 : m_buffer( (const T*)buffer )
166 , m_size( size )
167 {
168 }
169
170 template<typename T>
171 inline size_t BinaryOutputView<T>::size() const
172 {
173 return m_size;
174 }
175
176 template<typename T>
177 inline bool BinaryOutputView<T>::empty() const
178 {
179 return m_size == 0u;
180 }
181
182 template<typename T>
183 inline const T* BinaryOutputView<T>::begin() const
184 {
185 return m_buffer;
186 }
187
188 template<typename T>
189 inline const T* BinaryOutputView<T>::end() const
190 {
191 return m_buffer + m_size;
192 }
193
194 template<typename T>
195 inline const T& BinaryOutputView<T>::operator[]( size_t localIndex ) const
196 {
197 return m_buffer[ localIndex ];
198 }
199
200 inline size_t BinaryOutputBuffer::size() const
201 {
202 return m_size;
203 }
204
206 {
207 return m_elementSize;
208 }
209
210 inline bool BinaryOutputBuffer::empty() const
211 {
212 return m_size == 0u;
213 }
214
215 inline void BinaryOutputBuffer::resize( size_t size, size_t elementSize )
216 {
217 delete[] m_buffer;
218
219 if ( size > 0 && elementSize > 0 )
220 m_buffer = new char[ size * elementSize ];
221 else
222 m_buffer = nullptr;
223
224 m_size = size;
225 m_elementSize = elementSize;
226 }
227
229 {
230 return m_buffer;
231 }
232
233 inline const void* BinaryOutputBuffer::rwPtr() const
234 {
235 return m_buffer;
236 }
237
238 template<typename T>
239 inline const T* BinaryOutputBuffer::ptr() const
240 {
241 agxAssert1( sizeof( T ) == m_elementSize, "ptrAs<T> type size mismatch." );
242 return (const T*)m_buffer;
243 }
244
245 template<typename T>
246 inline BinaryOutputView<T> BinaryOutputBuffer::view( size_t startIndex, /*= 0u*/
247 size_t numElements /*= agx::InvalidIndex*/ ) const
248 {
249 if ( m_buffer == nullptr )
250 return {};
251
252 if ( startIndex >= m_size )
253 return {};
254
255 if ( numElements == agx::InvalidIndex )
256 numElements = m_size > startIndex ? m_size - startIndex : 0u;
257
258 return { &(this->template ptr<T>()[ startIndex ]), numElements };
259 }
260
261 inline BinaryOutputBuffer::BinaryOutputBuffer()
262 : m_buffer( nullptr )
263 , m_size( 0u )
264 , m_elementSize( 0u )
265 {
266 }
267
268 inline BinaryOutputBuffer::~BinaryOutputBuffer()
269 {
270 delete[] m_buffer;
271 }
272
273}
#define AGXSENSOR_EXPORT
#define m_size
Definition: agx/Vector.h:429
Buffer used for sensor output of a wide range of output element types.
BinaryOutputView< T > view(size_t startIndex=0u, size_t numElements=agx::InvalidIndex) const
Create a view into a section of the buffer.
void resize(size_t size, size_t elementSize)
Resize the buffer to fit the given number of elements of the given size.
View for reading sections of a binary packed buffer of the specified template parameter type.
BinaryOutputView()=default
Constructs a default empty binary output view.
const T & operator[](size_t localIndex) const
Random read access of value at the specified index.
#define agxAssert1(expr, msg)
Definition: debug.h:144
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:89
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:88
The agxSensor namespace contains components to model real-time sensors connected to the physics of AG...
AGXCORE_EXPORT const InvalidIndexStruct InvalidIndex
std::random_access_iterator_tag iterator_category