DCL 3.7.4
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}
static long incrementAndGet(volatile long &_n)

◆ create()

BUFFER_T * BUFFER_T::create ( size_t _len)
static

Definition at line 149 of file __STRING.cpp.

150{
151 BUFFER_T* buf = (BUFFER_T*)
152 malloc(sizeof(BUFFER_T) + (sizeof(CHAR_T) * (_len + 1)));
153
154 if (buf) {
155 buf->__refCount = 1;
156 buf->__allocLength = _len;
157 buf->__dataLength = 0;
158 buf->data()[buf->__dataLength] = _T('\0');
159 }
160 /*
161 else {
162 throw BadAllocException
163 }
164 */
165 return buf;
166}
#define _T(s)
Definition __STRING.h:19
#define BUFFER_T
Definition __STRING.h:22
#define CHAR_T
Definition __STRING.h:20
size_t __allocLength
Definition __STRING.h:33
CHAR_T * data()
Definition __STRING.h:36
volatile long __refCount
Definition __STRING.h:32
size_t __dataLength
Definition __STRING.h:34

◆ create_e()

BUFFER_T * BUFFER_T::create_e ( size_t _len)
static

Definition at line 168 of file __STRING.cpp.

169{
171}
size_t __extended_length(size_t _allocLength)
Definition __STRING.cpp:113
static BUFFER_T * create(size_t _len)
Definition __STRING.cpp:149

◆ 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 141 of file __STRING.cpp.

142{
143 free(_buf);
144}

◆ extend()

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

Definition at line 173 of file __STRING.cpp.

174{
175 __DCL_ASSERT_PARAM(_buf != NULL);
176 __DCL_ASSERT_PARAM(_buf->__allocLength < _len);
177
178 _len = __extended_length(_len);
179
180 BUFFER_T* buf = (BUFFER_T*)
181 realloc(_buf, sizeof(BUFFER_T) + (sizeof(CHAR_T) * (_len + 1)));
182
183 // buf와 _buf는 같지 않을 수 있다.
184 if (buf) {
185 _buf = buf;
186 _buf->__allocLength = _len;
187 }
188 /*
189 else {
190 throw BadAllocException
191 }
192 */
193}
#define NULL
Definition Config.h:312
#define __DCL_ASSERT_PARAM(expr)
Definition Object.h:409

◆ 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:141

◆ shrink()

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

Definition at line 195 of file __STRING.cpp.

196{
197 __DCL_ASSERT_PARAM(_buf != NULL);
198 if (_buf->__dataLength < _buf->__allocLength) {
199 size_t _len = _buf->__dataLength;
200 BUFFER_T* buf = (BUFFER_T*)
201 realloc(_buf, sizeof(BUFFER_T) + (sizeof(CHAR_T) * (_len + 1)));
202
203 if (buf) {
204 _buf = buf;
205 _buf->__allocLength = _len;
206 _buf->data()[_buf->__dataLength] = _T('\0');
207 }
208 else {
209 // throw new BadAllocException
210 }
211 }
212}

◆ vformat()

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

Definition at line 230 of file __STRING.cpp.

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

◆ write() [1/2]

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

Definition at line 225 of file __STRING.cpp.

226{
227 write(_buf, &_ch, 1);
228}
static void write(BUFFER_T *&_buf, const CHAR_T *_str, size_t _len)
Definition __STRING.cpp:214

◆ write() [2/2]

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

Definition at line 214 of file __STRING.cpp.

215{
216 size_t avail = _buf->__allocLength - _buf->__dataLength;
217 if (avail < _len) {
218 BUFFER_T::extend(_buf, _buf->__allocLength + _len);
219 }
220 memcpy(_buf->data() + _buf->__dataLength, _p, _len * sizeof(CHAR_T));
221 _buf->__dataLength += _len;
222 _buf->data()[_buf->__dataLength] = _T('\0');
223}

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: