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

#include <Numeric.h>

Public Member Functions

 UInt32 (uint32_t _u)
String toString (unsigned _base=10) const

Static Public Member Functions

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

Public Attributes

uint32_t __u

Detailed Description

Definition at line 87 of file Numeric.h.

Constructor & Destructor Documentation

◆ UInt32()

UInt32::UInt32 ( uint32_t _u)
inline

Definition at line 94 of file Numeric.inl.

95{
96 __u = _u;
97}
uint32_t __u
Definition Numeric.h:90

Member Function Documentation

◆ parse() [1/2]

uint32_t UInt32::parse ( const wchar_t * _number,
unsigned _base,
uint32_t _default )
static

Definition at line 441 of file Numeric.cpp.

442{
443 __DCL_ASSERT(_number != NULL);
444 __DCL_ASSERT(_base > 1);
445
446 if (*_number == __T('\0') || iswspace((wint_t)*_number)) {
447 return _default;
448 }
449
450 NumericConvertException::Error error = NumericConvertException::NoError;
451 wchar_t* endptr = NULL;
452 unsigned long n = wcstoul(_number, &endptr, _base);
453 if (ULONG_MAX == n) {
454 error = NumericConvertException::Overflow;
455 }
456#if __WORDSIZE > 32
457 else if (UINT32_MAX < n) {
458 error = NumericConvertException::Overflow;
459 }
460#endif
461 if (NumericConvertException::NoError != error) {
462 return _default;
463 }
464
465 if ((endptr && *endptr != '\0') || errno == EINVAL) {
466 return _default;
467 }
468
469 return (uint32_t) n;
470}
#define NULL
Definition Config.h:340
#define UINT32_MAX
Definition Config.h:323
#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]

uint32_t UInt32::parse ( const wchar_t * _number,
unsigned _base = 10 )
static

Definition at line 401 of file Numeric.cpp.

403{
404 __DCL_ASSERT(_number != NULL);
405 __DCL_ASSERT(_base > 1);
406
407 if (*_number == __T('\0') || iswspace((wint_t)*_number)) {
408 throw new NumericConvertException(_number, _base, 0);
409 }
410
411 NumericConvertException::Error error = NumericConvertException::NoError;
412 wchar_t* endptr = NULL;
413 unsigned long n = wcstoul(_number, &endptr, _base);
414 if (ULONG_MAX == n) {
415 error = NumericConvertException::Overflow;
416 }
417#if __WORDSIZE > 32
418 else if (UINT32_MAX < n) {
419 error = NumericConvertException::Overflow;
420 }
421#endif
422 if (NumericConvertException::NoError != error) {
423 throw new NumericConvertException(
424 error,
425 _number,
426 _base
427 );
428 }
429
430 if ((endptr && *endptr != '\0') || errno == EINVAL) {
431 throw new NumericConvertException(
432 _number,
433 _base,
434 endptr ? (endptr - _number) : 0
435 );
436 }
437
438 return (uint32_t) n;
439}

◆ toByteString()

ByteString UInt32::toByteString ( uint32_t _u,
unsigned _base = 10 )
static

Definition at line 472 of file Numeric.cpp.

473{
474 __DCL_ASSERT_PARAM(2 <= _base && _base <= 32);
475 // 2진수일경우 32 + sign = 33
476 ByteBuffer* buf = ByteBuffer::create(40);
477 __uint32toa(_u, buf->data(), _base);
478 buf->__dataLength = ByteString::length(buf->data());
479 ByteString s(buf);
480 buf->release();
481 return s;
482}
char * __uint32toa(uint32_t _n, char *_buf, unsigned _base)
Definition __xtoa.cpp:33
#define __DCL_ASSERT_PARAM(expr)
Definition Object.h:384
ByteBuffer * buf

◆ toString() [1/3]

String UInt32::toString ( uint32_t _u,
const wchar_t * _format )
static

Definition at line 391 of file Numeric.cpp.

392{
393 if (!_format)
394 _format = __T("%lu");
395
396 __DCL_ASSERT_PARAM(*_format != '\0');
397
398 return String::format(_format, _u);
399}

◆ toString() [2/3]

String UInt32::toString ( uint32_t _u,
unsigned _base = 10 )
static

Definition at line 379 of file Numeric.cpp.

380{
381 __DCL_ASSERT_PARAM(2 <= _base && _base <= 32);
382 // 2진수일경우 32 + sign = 33
383 CharBuffer* buf = CharBuffer::create(40);
384 __uint32tow(_u, buf->data(), _base);
385 buf->__dataLength = String::length(buf->data());
386 String s(buf);
387 buf->release();
388 return s;
389}
wchar_t * __uint32tow(uint32_t _n, wchar_t *_buf, unsigned _base)
Definition __xtoa.cpp:73

◆ toString() [3/3]

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

Definition at line 99 of file Numeric.inl.

100{
101 return UInt32::toString(__u, _base);
102}
String toString(unsigned _base=10) const
Definition Numeric.inl:99

Member Data Documentation

◆ __u

uint32_t UInt32::__u

Definition at line 90 of file Numeric.h.


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