Mako 8.2.0 API
MakoCore SDK API Documentation
Loading...
Searching...
No Matches
edlsimplebuffer.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2009-2025 Global Graphics Software Ltd. All rights reserved.
3 */
4
11
12#ifndef edlsimplebuffer_h
13#define edlsimplebuffer_h
14
15#include <stdlib.h>
16#include <cstring>
17#include <edl/edltypes.h>
18#include <edl/edlnamespaces.h>
19#include <edl/edlerrors.h>
20
22
24{
25 public:
26 // Copy constructor
28 {
29 init();
30 assign(incoming.m_buffer, incoming.m_bufferSize);
31 }
32
33#ifdef SWIG
34#if SWIGJAVA
35 %apply char *BYTE { const uint8 *src};
36#endif
37#if SWIGCSHARP
38 %apply uint8_t INPUT[] { const uint8 *src};
39#endif
40#endif
41 // Allocate from a pre-existing block
42 CEDLSimpleBuffer(const uint8 *src, size_t size)
43 {
44 init();
45 assign(src, size);
46 }
47#ifdef SWIG
48 %clear const uint8 *src;
49#endif
50
51 // Allocate an empty block
52 CEDLSimpleBuffer(size_t size = 0, bool clearBuff = false)
53 {
54 init();
55 resize(size);
56 if (clearBuff)
57 clear();
58 }
59
61 {
62 release();
63 }
64
65 // Get size
66 size_t size() const
67 {
68 return m_bufferSize;
69 }
70
71 // Dereference via index
72 uint8& operator[](size_t index)
73 {
74 if (index >= m_bufferSize)
75 {
77 }
78 return m_buffer[index];
79 }
80
81 const uint8& operator[](size_t index) const
82 {
83 if (index >= m_bufferSize)
84 {
86 }
87 return m_buffer[index];
88 }
89
91 {
92 release();
93 assign(incoming.m_buffer, incoming.m_bufferSize);
94 return *this;
95 }
96
97 void resize(size_t newSize)
98 {
99#ifdef SWIG
100 // > 32bit indexes are not currently supported for SWIG builds
101 if (newSize != (uint32) newSize)
102 {
104 }
105#endif
106 // Need to free?
107 if (!newSize && m_buffer)
108 {
109 release();
110 }
111 // Need to allocate?
112 else if (!m_buffer && newSize != 0)
113 {
114 m_buffer = (uint8 *) m_allocate(newSize);
115 if (!m_buffer)
116 {
118 }
119 }
120 // Need to resize?
121 else if (newSize != m_bufferSize)
122 {
123 uint8 *newBuffer = (uint8 *) m_reallocate(m_buffer, newSize);
124 if (!newBuffer)
125 {
127 }
128 m_buffer = newBuffer;
129 }
130 m_bufferSize = newSize;
131
132 }
133
134 void clear()
135 {
136 if (m_buffer && m_bufferSize)
137 {
138 memset(m_buffer, 0, m_bufferSize);
139 }
140 }
141
142private:
143
144 void init()
145 {
146 m_buffer = NULL;
147 m_bufferSize = 0;
148 m_allocate = malloc;
149 m_deallocate = free;
150 m_reallocate = realloc;
151 }
152
153 void assign(const uint8 *src, size_t size)
154 {
155 resize(size);
156 if (size)
157 {
158 memcpy(m_buffer, src, size);
159 }
160 }
161
162 void release()
163 {
164 if (m_buffer)
165 m_deallocate(m_buffer);
166 m_buffer = NULL;
167 m_bufferSize = 0;
168 }
169
170 uint8 *m_buffer;
171 size_t m_bufferSize;
172
173 typedef void *(*AllocatorFn)(size_t n);
174 typedef void (*DeallocatorFn)(void *p);
175 typedef void *(*ReallocatorFn)(void *p, size_t newSize);
176
177 AllocatorFn m_allocate;
178 DeallocatorFn m_deallocate;
179 ReallocatorFn m_reallocate;
180};
181
183
184#endif
185
CEDLSimpleBuffer(const CEDLSimpleBuffer &incoming)
Definition edlsimplebuffer.h:27
CEDLSimpleBuffer(const uint8 *src, size_t size)
Definition edlsimplebuffer.h:42
CEDLSimpleBuffer & operator=(const CEDLSimpleBuffer &incoming)
Definition edlsimplebuffer.h:90
~CEDLSimpleBuffer()
Definition edlsimplebuffer.h:60
void clear()
Definition edlsimplebuffer.h:134
const uint8 & operator[](size_t index) const
Definition edlsimplebuffer.h:81
void resize(size_t newSize)
Definition edlsimplebuffer.h:97
CEDLSimpleBuffer(size_t size=0, bool clearBuff=false)
Definition edlsimplebuffer.h:52
size_t size() const
Definition edlsimplebuffer.h:66
uint8 & operator[](size_t index)
Definition edlsimplebuffer.h:72
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:34
unsigned char uint8
Definition edltypes.h:32
@ EDL_ERR_OUTOFMEMORY
Out of memory.
Definition edlerrors.h:32
@ 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:54
@ EDL_ERR_BAD_ARGUMENTS
General error for bad arguments passed to an API function.
Definition edlerrors.h:42