Barracuda Application Server C/C++ Reference
NO
DynBuffer.h
1/*
2 * ____ _________ __ _
3 * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____
4 * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/
5 * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__
6 * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/
7 * /____/
8 *
9 * Barracuda Embedded Web-Server
10 ****************************************************************************
11 * HEADER
12 *
13 * $Id: DynBuffer.h 4915 2021-12-01 18:26:55Z wini $
14 *
15 * COPYRIGHT: Real Time Logic LLC, 2005-2008
16 *
17 * This software is copyrighted by and is the sole property of Real
18 * Time Logic LLC. All rights, title, ownership, or other interests in
19 * the software remain the property of Real Time Logic LLC. This
20 * software may only be used in accordance with the terms and
21 * conditions stipulated in the corresponding license agreement under
22 * which the software has been supplied. Any unauthorized use,
23 * duplication, transmission, distribution, or disclosure of this
24 * software is expressly forbidden.
25 *
26 * This Copyright notice may not be removed or modified without prior
27 * written consent of Real Time Logic LLC.
28 *
29 * Real Time Logic LLC. reserves the right to modify this software
30 * without notice.
31 *
32 * http://www.realtimelogic.com
33 ****************************************************************************
34 *
35 */
36
37#ifndef _DynBuffer_h
38#define _DynBuffer_h
39
40#include <HttpServer.h>
41#include <BaServerLib.h>
42
43/*
44 eCode:
45 -1: No allocator
46 -2: Malloc failed.
47 -3: Need to realloc buffer, but no realloc provided.
48 -4: Realloc failed.
49 -5: Buffer too large.
50*/
51struct DynBuffer;
52typedef void (*DynBuffer_OnAllocError)(struct DynBuffer* o, int eCode);
53
57typedef struct DynBuffer
58#ifdef __cplusplus
59: public BufPrint
60{
61 DynBuffer() {}
62
70 DynBuffer(int startSize, int expandSize, AllocatorIntf* alloc=0,
71 DynBuffer_OnAllocError onAllocError=0);
72
75 ~DynBuffer();
76
78 void release();
79
85 char* getBuf();
86
88 U32 getBufSize();
89
102 int getECode();
103
110 int expand(int sizeNeeded);
111
116 char* getCurPtr();
117
132 void incrementCursor(int nBytes);
133
136 static const char* ecode2str(int eCode);
137#else
138{
139 BufPrint super; /* inherits from BufPrint */
140#if 0
141}
142#endif
143#endif
144
145 AllocatorIntf* alloc;
146 DynBuffer_OnAllocError onAllocError;
147 int startSize;
148 int expandSize;
149} DynBuffer;
150
151#ifdef __cplusplus
152extern "C" {
153#endif
154BA_API void DynBuffer_constructor(DynBuffer* o, int startSize, int expandSize,
155 AllocatorIntf* alloc,
156 DynBuffer_OnAllocError onAllocError);
157#define DynBuffer_destructor(o) DynBuffer_release(o)
158BA_API void DynBuffer_release(DynBuffer* o);
159BA_API char* DynBuffer_getBuf(DynBuffer* o);
160#define DynBuffer_getBufSize(o) BufPrint_getBufSize((BufPrint*)(o))
161#define DynBuffer_getCurPtr(o) (((BufPrint*)(o))->buf+((BufPrint*)(o))->cursor)
162#define DynBuffer_incrementCursor(o,nBytes) ((BufPrint*)(o))->cursor+=nBytes
163#define DynBuffer_getECode(o) ((o)->expandSize < 0 ? (o)->expandSize : 0)
164BA_API int DynBuffer_expand(DynBuffer* o, int sizeNeeded);
165BA_API const char* DynBuffer_ecode2str(int eCode);
166#ifdef __cplusplus
167}
168
169inline DynBuffer::DynBuffer(
170 int startSize, int expandSize, AllocatorIntf* alloc,
171 DynBuffer_OnAllocError onAllocError) {
172 DynBuffer_constructor(this, startSize, expandSize, alloc, onAllocError); }
174 DynBuffer_destructor(this); }
175inline void DynBuffer::release() {
176 DynBuffer_release(this); }
177inline char* DynBuffer::getBuf() {
178 return DynBuffer_getBuf(this); }
180 return DynBuffer_getBufSize(this); }
182 return DynBuffer_getECode(this); }
183inline int DynBuffer::expand(int sizeNeeded) {
184 return DynBuffer_expand(this, sizeNeeded); }
185inline char* DynBuffer::getCurPtr() {
186 return DynBuffer_getCurPtr(this); }
187inline void DynBuffer::incrementCursor(int nBytes) {
188 DynBuffer_incrementCursor(this, nBytes); }
189inline const char* DynBuffer::ecode2str(int eCode) {
190 return DynBuffer_ecode2str(eCode); }
191#endif
192
193#endif
Memory allocation and deallocation Interface class.
Definition: AllocatorIntf.h:83
The BufPrint class, which implements an ANSI compatible printf method, is a base class used by severa...
Definition: BufPrint.h:122
A dynamic buffer.
Definition: DynBuffer.h:60
void release()
terminate the internal dynamic buffer by calling free
Definition: DynBuffer.h:175
~DynBuffer()
destructor.
Definition: DynBuffer.h:173
int getECode()
Returns the error code if memory allocation failed.
Definition: DynBuffer.h:181
U32 getBufSize()
Returns current size of internal formatted data.
Definition: DynBuffer.h:179
char * getBuf()
Returns a pointer to the internal buffer.
Definition: DynBuffer.h:177
int expand(int sizeNeeded)
force buffer to expand.
Definition: DynBuffer.h:183
void incrementCursor(int nBytes)
Increments the internal cursor position.
Definition: DynBuffer.h:187
char * getCurPtr()
Return a pointer to the internal cursor position in the internal dynamic buffer.
Definition: DynBuffer.h:185
static const char * ecode2str(int eCode)
Convert error code to string.
Definition: DynBuffer.h:189