DCL 3.7.4
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 96 of file Numeric.h.

Constructor & Destructor Documentation

◆ UInt32()

UInt32::UInt32 ( uint32_t _u)
inline

Definition at line 100 of file Numeric.inl.

101{
102 __u = _u;
103}
uint32_t __u
Definition Numeric.h:99

Member Function Documentation

◆ parse() [1/2]

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

Definition at line 435 of file Numeric.cpp.

436{
437 __DCL_ASSERT(_number != NULL);
438 __DCL_ASSERT(_base > 1);
439
440 if (*_number == __T('\0') || iswspace((wint_t)*_number)) {
441 return _default;
442 }
443
444 NumericConvertException::Error error = NumericConvertException::NoError;
445 errno = 0;
446 wchar_t* endptr = NULL;
447 unsigned long n = wcstoul(_number, &endptr, _base);
448 if (errno == ERANGE) {
449 if (ULONG_MAX == n) {
450 error = NumericConvertException::Overflow;
451 }
452#if __WORDSIZE > 32
453 else if (UINT32_MAX < n) {
454 error = NumericConvertException::Overflow;
455 }
456#endif
457 }
458
459 if (NumericConvertException::NoError != error) {
460 return _default;
461 }
462
463 if ((endptr && *endptr != '\0') || errno == EINVAL) {
464 return _default;
465 }
466
467 return (uint32_t) n;
468}
#define NULL
Definition Config.h:312
#define UINT32_MAX
Definition Config.h:295
#define __DCL_ASSERT(expr)
Definition Object.h:394
#define __T(str)
Definition Object.h:60

◆ parse() [2/2]

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

Definition at line 391 of file Numeric.cpp.

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

◆ toByteString()

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

Definition at line 470 of file Numeric.cpp.

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

◆ toString() [1/3]

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

Definition at line 381 of file Numeric.cpp.

382{
383 if (!_format)
384 _format = __T("%lu");
385
386 __DCL_ASSERT_PARAM(*_format != '\0');
387
388 return String::format(_format, _u);
389}

◆ toString() [2/3]

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

Definition at line 369 of file Numeric.cpp.

370{
371 __DCL_ASSERT_PARAM(2 <= _base && _base <= 32);
372 // 2진수일경우 32 + sign = 33
373 CharBuffer* buf = CharBuffer::create(40);
374 __uint32tow(_u, buf->data(), _base);
375 buf->__dataLength = String::length(buf->data());
376 String s(buf);
377 buf->release();
378 return s;
379}
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 105 of file Numeric.inl.

106{
107 return UInt32::toString(__u, _base);
108}
String toString(unsigned _base=10) const
Definition Numeric.inl:105

Member Data Documentation

◆ __u

uint32_t UInt32::__u

Definition at line 99 of file Numeric.h.


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