Mako 9.1.0 API
MakoCore SDK API Documentation
Loading...
Searching...
No Matches
edlsimplebuffer.h
Go to the documentation of this file.
1/*
2 * edlsimplebuffer.h
3 *
4 * Copyright (C) 2009-2026 Hybrid Software Helix Ltd. All rights reserved.
5 */
6
13
14#ifndef edlsimplebuffer_h
15#define edlsimplebuffer_h
16
17#include <stdlib.h>
18#include <cstring>
19#include <edl/edltypes.h>
20#include <edl/edlnamespaces.h>
21#include <edl/edlerrors.h>
22
24
26{
27 public:
28 // Copy constructor
30 {
31 init();
32 assign(incoming.m_buffer, incoming.m_bufferSize);
33 }
34
35#ifdef SWIG
36#if SWIGJAVA
37 %apply char *BYTE { const uint8 *src};
38#endif
39#if SWIGCSHARP
40 %apply uint8_t INPUT[] { const uint8 *src};
41#endif
42#if SWIGPYTHON
43 %apply char INPUT[] {const uint8 *src}
44#endif
45#endif
46 // Allocate from a pre-existing block
47 CEDLSimpleBuffer(const uint8 *src, size_t size)
48 {
49 init();
50 assign(src, size);
51 }
52#ifdef SWIG
53 %clear const uint8 *src;
54#endif
55
56 // Allocate an empty block
57 CEDLSimpleBuffer(size_t size = 0, bool clearBuff = false)
58 {
59 init();
60 resize(size);
61 if (clearBuff)
62 clear();
63 }
64
66 {
67 release();
68 }
69
70 // Get size
71 size_t size() const
72 {
73 return m_bufferSize;
74 }
75
76 // Dereference via index
77 uint8& operator[](size_t index)
78 {
79 if (index >= m_bufferSize)
80 {
82 }
83 return m_buffer[index];
84 }
85
86 const uint8& operator[](size_t index) const
87 {
88 if (index >= m_bufferSize)
89 {
91 }
92 return m_buffer[index];
93 }
94
95 const uint8 *data() const
96 {
97 if (m_bufferSize == 0)
98 {
100 }
101 return m_buffer;
102 }
103
105 {
106 release();
107 assign(incoming.m_buffer, incoming.m_bufferSize);
108 return *this;
109 }
110
111 void resize(size_t newSize)
112 {
113#ifdef SWIG
114 // > 32bit indexes are not currently supported for SWIG builds
115 if (newSize != (uint32) newSize)
116 {
118 }
119#endif
120 // Need to free?
121 if (!newSize && m_buffer)
122 {
123 release();
124 }
125 // Need to allocate?
126 else if (!m_buffer && newSize != 0)
127 {
128 m_buffer = (uint8 *) m_allocate(newSize);
129 if (!m_buffer)
130 {
132 }
133 }
134 // Need to resize?
135 else if (newSize != m_bufferSize)
136 {
137 uint8 *newBuffer = (uint8 *) m_reallocate(m_buffer, newSize);
138 if (!newBuffer)
139 {
141 }
142 m_buffer = newBuffer;
143 }
144 m_bufferSize = newSize;
145
146 }
147
148 void clear()
149 {
150 if (m_buffer && m_bufferSize)
151 {
152 memset(m_buffer, 0, m_bufferSize);
153 }
154 }
155
156 void fill(uint8 val)
157 {
158 if (m_buffer && m_bufferSize)
159 {
160 memset(m_buffer, val, m_bufferSize);
161 }
162 }
163
164private:
165
166 void init()
167 {
168 m_buffer = NULL;
169 m_bufferSize = 0;
170 m_allocate = malloc;
171 m_deallocate = free;
172 m_reallocate = realloc;
173 }
174
175 void assign(const uint8 *src, size_t size)
176 {
177 resize(size);
178 if (size)
179 {
180 memcpy(m_buffer, src, size);
181 }
182 }
183
184 void release()
185 {
186 if (m_buffer)
187 m_deallocate(m_buffer);
188 m_buffer = NULL;
189 m_bufferSize = 0;
190 }
191
192 uint8 *m_buffer;
193 size_t m_bufferSize;
194
195 typedef void *(*AllocatorFn)(size_t n);
196 typedef void (*DeallocatorFn)(void *p);
197 typedef void *(*ReallocatorFn)(void *p, size_t newSize);
198
199 AllocatorFn m_allocate;
200 DeallocatorFn m_deallocate;
201 ReallocatorFn m_reallocate;
202};
203
205
206#endif
207
CEDLSimpleBuffer(const CEDLSimpleBuffer &incoming)
Definition edlsimplebuffer.h:29
void fill(uint8 val)
Definition edlsimplebuffer.h:156
const uint8 * data() const
Definition edlsimplebuffer.h:95
CEDLSimpleBuffer(const uint8 *src, size_t size)
Definition edlsimplebuffer.h:47
CEDLSimpleBuffer & operator=(const CEDLSimpleBuffer &incoming)
Definition edlsimplebuffer.h:104
~CEDLSimpleBuffer()
Definition edlsimplebuffer.h:65
void clear()
Definition edlsimplebuffer.h:148
const uint8 & operator[](size_t index) const
Definition edlsimplebuffer.h:86
void resize(size_t newSize)
Definition edlsimplebuffer.h:111
CEDLSimpleBuffer(size_t size=0, bool clearBuff=false)
Definition edlsimplebuffer.h:57
size_t size() const
Definition edlsimplebuffer.h:71
uint8 & operator[](size_t index)
Definition edlsimplebuffer.h:77
EDL_API void throwEDLError(uint32 errorcode)
Utility - Throw an IEDLError exception with the given error code.
EDL C++ namespace(s)
#define _END_EDL_DOM_NAMESPACE
Definition edlnamespaces.h:110
#define _BEGIN_EDL_DOM_NAMESPACE
Definition edlnamespaces.h:109
EDL "standard" types including known bit-length signed and unsigned integer type[def]s and definition...
unsigned int uint32
Definition edltypes.h:36
unsigned char uint8
Definition edltypes.h:34
@ EDL_ERR_OUTOFMEMORY
Out of memory.
Definition edlerrors.h:34
@ JM_ERR_RANGE_ERROR
An attempt was made to request or add an item from the API with an out-of-bounds index.
Definition edlerrors.h:57
@ EDL_ERR_BAD_ARGUMENTS
General error for bad arguments passed to an API function.
Definition edlerrors.h:44