DCL 4.0
Loading...
Searching...
No Matches
BUFFER_T Struct Reference

#include <__STRING.h>

Public Member Functions

CHAR_Tdata ()
long addRef ()
long release ()

Static Public Member Functions

static void destroy (BUFFER_T *_buf)
static BUFFER_Tcreate (size_t _len)
static BUFFER_Tcreate_e (size_t _len)
static void extend (BUFFER_T *&_buf, size_t _len)
static void shrink (BUFFER_T *&_buf)
static void write (BUFFER_T *&_buf, const CHAR_T *_str, size_t _len)
static void write (BUFFER_T *&_buf, CHAR_T _ch)
static int vformat (BUFFER_T *&_buf, const CHAR_T *_format, va_list _arglist)

Public Attributes

volatile long __refCount
size_t __allocLength
size_t __dataLength

Detailed Description

Definition at line 30 of file __STRING.h.

Member Function Documentation

◆ addRef()

long BUFFER_T::addRef ( )

Definition at line 96 of file __STRING.cpp.

97{
98 long n = Thread::incrementAndGet(__refCount);
99 return n;
100}
void CharsetConvertException *size_t n
Definition SQLField.cpp:253
static long incrementAndGet(volatile long &_n)

◆ create()

BUFFER_T * BUFFER_T::create ( size_t _len)
static

Definition at line 142 of file __STRING.cpp.

143{
144 BUFFER_T* buf = (BUFFER_T*)
145 malloc(sizeof(BUFFER_T) + (sizeof(CHAR_T) * (_len + 1)));
146
147 if (buf) {
148 buf->__refCount = 1;
149 buf->__allocLength = _len;
150 buf->__dataLength = 0;
151 buf->data()[buf->__dataLength] = _T('\0');
152 }
153 /*
154 else {
155 throw BadAllocException
156 }
157 */
158 return buf;
159}
#define _T(s)
Definition __STRING.h:19
#define BUFFER_T
Definition __STRING.h:22
#define CHAR_T
Definition __STRING.h:20
ByteBuffer * buf

◆ create_e()

BUFFER_T * BUFFER_T::create_e ( size_t _len)
static

Definition at line 161 of file __STRING.cpp.

162{
164}
size_t __extended_length(size_t _allocLength)
Definition __STRING.cpp:113
static BUFFER_T * create(size_t _len)
Definition __STRING.cpp:142

◆ data()

CHAR_T * BUFFER_T::data ( )
inline

Definition at line 36 of file __STRING.h.

36{ return (CHAR_T*)(this + 1); }

◆ destroy()

void BUFFER_T::destroy ( BUFFER_T * _buf)
static

Definition at line 137 of file __STRING.cpp.

138{
139 free(_buf);
140}

◆ extend()

void BUFFER_T::extend ( BUFFER_T *& _buf,
size_t _len )
static

Definition at line 166 of file __STRING.cpp.

167{
168 __DCL_ASSERT_PARAM(_buf != NULL);
169 __DCL_ASSERT_PARAM(_buf->__allocLength < _len);
170
171 _len = __extended_length(_len);
172
173 BUFFER_T* buf = (BUFFER_T*)
174 realloc(_buf, sizeof(BUFFER_T) + (sizeof(CHAR_T) * (_len + 1)));
175
176 // buf와 _buf는 같지 않을 수 있다.
177 if (buf) {
178 _buf = buf;
179 _buf->__allocLength = _len;
180 }
181 /*
182 else {
183 throw BadAllocException
184 }
185 */
186}
#define NULL
Definition Config.h:340
#define __DCL_ASSERT_PARAM(expr)
Definition Object.h:384
size_t __allocLength
Definition __STRING.h:33

◆ release()

long BUFFER_T::release ( )

Definition at line 102 of file __STRING.cpp.

103{
104 __DCL_ASSERT_PARAM(__refCount > 0); // __DCL_ASSERT_VALID(this);
105 long n = Thread::decrementAndGet(__refCount);
106 if (n == 0)
107 BUFFER_T::destroy(this);
108 return n;
109}
static long decrementAndGet(volatile long &_n)
static void destroy(BUFFER_T *_buf)
Definition __STRING.cpp:137

◆ shrink()

void BUFFER_T::shrink ( BUFFER_T *& _buf)
static

Definition at line 188 of file __STRING.cpp.

189{
190 __DCL_ASSERT_PARAM(_buf != NULL);
191 if (_buf->__dataLength < _buf->__allocLength) {
192 size_t _len = _buf->__dataLength;
193 BUFFER_T* buf = (BUFFER_T*)
194 realloc(_buf, sizeof(BUFFER_T) + (sizeof(CHAR_T) * (_len + 1)));
195
196 if (buf) {
197 _buf = buf;
198 _buf->__allocLength = _len;
199 _buf->data()[_buf->__dataLength] = _T('\0');
200 }
201 else {
202 // throw new BadAllocException
203 }
204 }
205}
CHAR_T * data()
Definition __STRING.h:36
size_t __dataLength
Definition __STRING.h:34

◆ vformat()

int BUFFER_T::vformat ( BUFFER_T *& _buf,
const CHAR_T * _format,
va_list _arglist )
static

Definition at line 223 of file __STRING.cpp.

224{
225 __DCL_ASSERT_PARAM(_format != NULL);
226
227#if defined(__DCL_COMPILE_UNICODE__) && defined(_MSC_VER)
228 String format;
229 if (STRSTR(_format, L"%s")) {
230 __DCL_TRACE3(L"Warning!! vformat _format [%ls] included [%ls]. replaced to [%ls]\n",
231 _format, L"%s", L"%hs");
232 format.assign(_format);
233 format = format.replace(L"%s", L"%hs");
234 _format = format;
235 }
236#endif
237
238#define __EXTENDED_MAX 1024 * 1024
239#define __EXTEND_MIN 32
240 int n = 0;
241 size_t extend = __MAX(_buf->__allocLength - _buf->__dataLength, __EXTEND_MIN);
242 size_t extended = _buf->__dataLength + extend;
243 while (extended < __EXTENDED_MAX) {
244 if (_buf->__allocLength < extended) {
245 BUFFER_T::extend(_buf, extended);
246 }
247
248 va_list arglist;
249 va_copy(arglist, _arglist);
250 n = VSNPRINTF(
251 _buf->data() + _buf->__dataLength,
252 _buf->__allocLength - _buf->__dataLength,
253 _format,
254 arglist
255 );
256 va_end(arglist);
257
258 // 버퍼가 부족한 경우, MSVC는 -1을 반환한다.
259 // GNUC는 버퍼의 size로 문자열이 잘려지고, 만들어진 문자의 개수를 반환한다.
260 // GNUC의 경우 arg 중 하나라도 문자열의 길이가 버퍼보다 길면 -1을 반환한다.
261 if (0 <= n && (size_t)n <= (_buf->__allocLength - _buf->__dataLength)) {
262 _buf->__dataLength += n;
263 _buf->data()[_buf->__dataLength] = _T('\0');
264 return n;
265 }
266
267 extend *= 2;
268 if (n > 0) {
269 extend = __MAX(extend, n);
270 }
271 extended += extend;
272 __DCL_TRACE2(__T("VSNPRINTF Failed(%d) extend[%zd] and Retry\n"), n, extend);
273 }
274 // throw new BadAllocException;
275
276 // EXTEND_MAX 10MB 만큼 버퍼를 할당했음에도 불구하고 VSNPRINTF를 실패했다.
277 __DCL_TRACE2(__T("Warning!! VSNPRINTF Failed(%d) extend[%zd]\n"), n, extend);
278 return n;
279}
#define VSNPRINTF(buf, len, fmt, args)
Definition __STRING.cpp:76
#define __EXTEND_MIN
#define __EXTENDED_MAX
#define STRSTR(s, cs)
Definition __STRING.cpp:80
#define __DCL_TRACE3(fmt, arg1, arg2, arg3)
Definition Object.h:378
#define __T(str)
Definition Object.h:44
#define __DCL_TRACE2(fmt, arg1, arg2)
Definition Object.h:377
size_t __MAX(size_t x, size_t y)
Definition size_t.h:43
static void extend(BUFFER_T *&_buf, size_t _len)
Definition __STRING.cpp:166

◆ write() [1/2]

void BUFFER_T::write ( BUFFER_T *& _buf,
CHAR_T _ch )
static

Definition at line 218 of file __STRING.cpp.

219{
220 write(_buf, &_ch, 1);
221}
static void write(BUFFER_T *&_buf, const CHAR_T *_str, size_t _len)
Definition __STRING.cpp:207

◆ write() [2/2]

void BUFFER_T::write ( BUFFER_T *& _buf,
const CHAR_T * _str,
size_t _len )
static

Definition at line 207 of file __STRING.cpp.

208{
209 size_t avail = _buf->__allocLength - _buf->__dataLength;
210 if (avail < _len) {
211 BUFFER_T::extend(_buf, _buf->__allocLength + _len);
212 }
213 memcpy(_buf->data() + _buf->__dataLength, _p, _len * sizeof(CHAR_T));
214 _buf->__dataLength += _len;
215 _buf->data()[_buf->__dataLength] = _T('\0');
216}

Member Data Documentation

◆ __allocLength

size_t BUFFER_T::__allocLength

Definition at line 33 of file __STRING.h.

◆ __dataLength

size_t BUFFER_T::__dataLength

Definition at line 34 of file __STRING.h.

◆ __refCount

volatile long BUFFER_T::__refCount

Definition at line 32 of file __STRING.h.


The documentation for this struct was generated from the following files: