DCL 4.0
Loading...
Searching...
No Matches
Int32 Class Reference

#include <Numeric.h>

Public Member Functions

 Int32 (int32_t _n)
String toString (unsigned _base=10) const

Static Public Member Functions

static String toString (int32_t _n, unsigned _base=10)
static String toString (int32_t _n, const wchar_t *_format)
static int32_t parse (const wchar_t *_number, unsigned _base=10) __DCL_THROWS1(NumericConvertException *)
static int32_t parse (const wchar_t *_number, unsigned _base, int32_t _default)
static ByteString toByteString (int32_t _n, unsigned _base=10)

Public Attributes

int32_t __n

Detailed Description

Definition at line 67 of file Numeric.h.

Constructor & Destructor Documentation

◆ Int32()

Int32::Int32 ( int32_t _n)
inline

Definition at line 82 of file Numeric.inl.

83{
84 __n = _n;
85}
int32_t __n
Definition Numeric.h:70

Member Function Documentation

◆ parse() [1/2]

int32_t Int32::parse ( const wchar_t * _number,
unsigned _base,
int32_t _default )
static

Definition at line 329 of file Numeric.cpp.

330{
331 __DCL_ASSERT(_number != NULL);
332 __DCL_ASSERT(_base > 1);
333
334 if (*_number == __T('\0') || iswspace((wint_t)*_number)) {
335 return _default;
336 }
337
338 NumericConvertException::Error error = NumericConvertException::NoError;
339 wchar_t* endptr = NULL;
340 long n = wcstol(_number, &endptr, _base);
341 if (LONG_MIN == n) {
342 error = NumericConvertException::Underflow;
343 } else if (LONG_MAX == n) {
344 error = NumericConvertException::Overflow;
345 }
346 #if __WORDSIZE > 32
347 else if (n < INT32_MIN) {
348 error = NumericConvertException::Underflow;
349 } else if (INT32_MAX < n) {
350 error = NumericConvertException::Overflow;
351 }
352 #endif
353
354 if (NumericConvertException::NoError != error) {
355 return _default;
356 }
357
358 if ((endptr && *endptr != '\0') || errno == EINVAL) {
359 return _default;
360 }
361
362 return (int32_t)n;
363}
#define NULL
Definition Config.h:340
#define INT32_MAX
Definition Config.h:318
#define INT32_MIN
Definition Config.h:313
#define __DCL_ASSERT(expr)
Definition Object.h:371
#define __T(str)
Definition Object.h:44
void CharsetConvertException *size_t n
Definition SQLField.cpp:253

◆ parse() [2/2]

int32_t Int32::parse ( const wchar_t * _number,
unsigned _base = 10 )
static

Definition at line 284 of file Numeric.cpp.

286{
287 __DCL_ASSERT(_number != NULL);
288 __DCL_ASSERT(_base > 1);
289
290 if (*_number == __T('\0') || iswspace((wint_t)*_number)) {
291 throw new NumericConvertException(_number, _base, 0);
292 }
293
294 NumericConvertException::Error error = NumericConvertException::NoError;
295 wchar_t* endptr = NULL;
296 long n = wcstol(_number, &endptr, _base);
297 if (LONG_MIN == n) {
298 error = NumericConvertException::Underflow;
299 } else if (LONG_MAX == n) {
300 error = NumericConvertException::Overflow;
301 }
302#if __WORDSIZE > 32
303 else if (n < INT32_MIN) {
304 error = NumericConvertException::Underflow;
305 } else if (INT32_MAX < n) {
306 error = NumericConvertException::Overflow;
307 }
308#endif
309
310 if (NumericConvertException::NoError != error) {
311 throw new NumericConvertException(
312 error,
313 _number,
314 _base
315 );
316 }
317
318 if ((endptr && *endptr != '\0') || errno == EINVAL) {
319 throw new NumericConvertException(
320 _number,
321 _base,
322 endptr ? (endptr - _number) : 0
323 );
324 }
325
326 return (int32_t)n;
327}

◆ toByteString()

ByteString Int32::toByteString ( int32_t _n,
unsigned _base = 10 )
static

Definition at line 365 of file Numeric.cpp.

366{
367 __DCL_ASSERT_PARAM(2 <= _base && _base <= 32);
368 // 2진수일경우 32 + sign = 33
369 ByteBuffer* buf = ByteBuffer::create(40);
370 __int32toa(_n, buf->data(), _base);
371 buf->__dataLength = ByteString::length(buf->data());
372 ByteString s(buf);
373 buf->release();
374 return s;
375}
char * __int32toa(int32_t _n, char *_buf, unsigned _base)
Definition __xtoa.cpp:27
#define __DCL_ASSERT_PARAM(expr)
Definition Object.h:384
ByteBuffer * buf

◆ toString() [1/3]

String Int32::toString ( int32_t _n,
const wchar_t * _format )
static

Definition at line 274 of file Numeric.cpp.

275{
276 if (!_format)
277 _format = __T("%ld");
278
279 __DCL_ASSERT_PARAM(*_format != '\0');
280
281 return String::format(_format, _n);
282}

◆ toString() [2/3]

__DCL_BEGIN_NAMESPACE String Int32::toString ( int32_t _n,
unsigned _base = 10 )
static

Definition at line 262 of file Numeric.cpp.

263{
264 __DCL_ASSERT_PARAM(2 <= _base && _base <= 32);
265 // 2진수일경우 32 + sign = 33
266 CharBuffer* buf = CharBuffer::create(40);
267 __int32tow(_n, buf->data(), _base);
268 buf->__dataLength = String::length(buf->data());
269 String s(buf);
270 buf->release();
271 return s;
272}
wchar_t * __int32tow(int32_t _n, wchar_t *_buf, unsigned _base)
Definition __xtoa.cpp:67

◆ toString() [3/3]

String Int32::toString ( unsigned _base = 10) const
inline

Definition at line 87 of file Numeric.inl.

88{
89 return Int32::toString(__n, _base);
90}
String toString(unsigned _base=10) const
Definition Numeric.inl:87

Member Data Documentation

◆ __n

int32_t Int32::__n

Definition at line 70 of file Numeric.h.


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