Mako 9.0.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
96 {
97 release();
98 assign(incoming.m_buffer, incoming.m_bufferSize);
99 return *this;
100 }
101
102 void resize(size_t newSize)
103 {
104#ifdef SWIG
105 // > 32bit indexes are not currently supported for SWIG builds
106 if (newSize != (uint32) newSize)
107 {
109 }
110#endif
111 // Need to free?
112 if (!newSize && m_buffer)
113 {
114 release();
115 }
116 // Need to allocate?
117 else if (!m_buffer && newSize != 0)
118 {
119 m_buffer = (uint8 *) m_allocate(newSize);
120 if (!m_buffer)
121 {
123 }
124 }
125 // Need to resize?
126 else if (newSize != m_bufferSize)
127 {
128 uint8 *newBuffer = (uint8 *) m_reallocate(m_buffer, newSize);
129 if (!newBuffer)
130 {
132 }
133 m_buffer = newBuffer;
134 }
135 m_bufferSize = newSize;
136
137 }
138
139 void clear()
140 {
141 if (m_buffer && m_bufferSize)
142 {
143 memset(m_buffer, 0, m_bufferSize);
144 }
145 }
146
147private:
148
149 void init()
150 {
151 m_buffer = NULL;
152 m_bufferSize = 0;
153 m_allocate = malloc;
154 m_deallocate = free;
155 m_reallocate = realloc;
156 }
157
158 void assign(const uint8 *src, size_t size)
159 {
160 resize(size);
161 if (size)
162 {
163 memcpy(m_buffer, src, size);
164 }
165 }
166
167 void release()
168 {
169 if (m_buffer)
170 m_deallocate(m_buffer);
171 m_buffer = NULL;
172 m_bufferSize = 0;
173 }
174
175 uint8 *m_buffer;
176 size_t m_bufferSize;
177
178 typedef void *(*AllocatorFn)(size_t n);
179 typedef void (*DeallocatorFn)(void *p);
180 typedef void *(*ReallocatorFn)(void *p, size_t newSize);
181
182 AllocatorFn m_allocate;
183 DeallocatorFn m_deallocate;
184 ReallocatorFn m_reallocate;
185};
186
188
189#endif
190
CEDLSimpleBuffer(const CEDLSimpleBuffer &incoming)
Definition edlsimplebuffer.h:29
CEDLSimpleBuffer(const uint8 *src, size_t size)
Definition edlsimplebuffer.h:47
CEDLSimpleBuffer & operator=(const CEDLSimpleBuffer &incoming)
Definition edlsimplebuffer.h:95
~CEDLSimpleBuffer()
Definition edlsimplebuffer.h:65
void clear()
Definition edlsimplebuffer.h:139
const uint8 & operator[](size_t index) const
Definition edlsimplebuffer.h:86
void resize(size_t newSize)
Definition edlsimplebuffer.h:102
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:34
unsigned char uint8
Definition edltypes.h:32
@ 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