DCL 3.7.4
Loading...
Searching...
No Matches
Int64 Class Reference

#include <Numeric.h>

Public Member Functions

 Int64 (int64_t _n)
String toString (unsigned _base=10) const

Static Public Member Functions

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

Public Attributes

int64_t __n

Detailed Description

Definition at line 119 of file Numeric.h.

Constructor & Destructor Documentation

◆ Int64()

Int64::Int64 ( int64_t _n)
inline

Definition at line 112 of file Numeric.inl.

113{
114 __n = _n;
115}
int64_t __n
Definition Numeric.h:122

Member Function Documentation

◆ parse() [1/2]

int64_t Int64::parse ( const wchar_t * _number,
unsigned _base,
int64_t _default )
static

Definition at line 553 of file Numeric.cpp.

555{
556 __DCL_ASSERT(_number != NULL);
557 __DCL_ASSERT(_base > 1);
558
559 if (*_number == __T('\0') || iswspace((wint_t)*_number)) {
560 return _default;
561 }
562
563 NumericConvertException::Error error = NumericConvertException::NoError;
564 errno = 0;
565 wchar_t* endptr = NULL;
566 long long n = wcstoll(_number, &endptr, _base);
567 if (errno == ERANGE) {
568 if (LLONG_MIN == n) {
569 error = NumericConvertException::Underflow;
570 }
571 else if (LLONG_MAX == n) {
572 error = NumericConvertException::Overflow;
573 }
574 }
575
576 if (NumericConvertException::NoError != error) {
577 return _default;
578 }
579
580 if ((endptr && *endptr != '\0') || errno == EINVAL) {
581 return _default;
582 }
583
584 return (int64_t) n;
585}
#define NULL
Definition Config.h:312
#define __DCL_ASSERT(expr)
Definition Object.h:394
#define __T(str)
Definition Object.h:60

◆ parse() [2/2]

int64_t Int64::parse ( const wchar_t * _number,
unsigned _base = 10 )
static

Definition at line 511 of file Numeric.cpp.

513{
514 __DCL_ASSERT(_number != NULL);
515 __DCL_ASSERT(_base > 1);
516
517 if (*_number == __T('\0') || iswspace((wint_t)*_number)) {
518 throw new NumericConvertException(_number, _base, 0);
519 }
520
521 NumericConvertException::Error error = NumericConvertException::NoError;
522 errno = 0;
523 wchar_t* endptr = NULL;
524 long long n = wcstoll(_number, &endptr, _base);
525 if (errno == ERANGE) {
526 if (LLONG_MIN == n) {
527 error = NumericConvertException::Underflow;
528 }
529 else if (LLONG_MAX == n) {
530 error = NumericConvertException::Overflow;
531 }
532
533 if (NumericConvertException::NoError != error) {
534 throw new NumericConvertException(
535 error,
536 _number,
537 _base
538 );
539 }
540 }
541
542 if ((endptr && *endptr != '\0') || errno == EINVAL) {
543 throw new NumericConvertException(
544 _number,
545 _base,
546 endptr ? (endptr - _number) : 0
547 );
548 }
549
550 return (int64_t) n;
551}

◆ toByteString()

ByteString Int64::toByteString ( int64_t _n,
unsigned _base = 10 )
static

Definition at line 587 of file Numeric.cpp.

588{
589 __DCL_ASSERT_PARAM(2 <= _base && _base <= 32);
590 // 2진수일경우 32 + sign = 33
591 ByteBuffer* buf = ByteBuffer::create(70);
592 __int64toa(_n, buf->data(), _base);
593 buf->__dataLength = ByteString::length(buf->data());
594 ByteString s(buf);
595 buf->release();
596 return s;
597}
char * __int64toa(int64_t _n, char *_buf, unsigned _base)
Definition __xtoa.cpp:47
#define __DCL_ASSERT_PARAM(expr)
Definition Object.h:409

◆ toString() [1/3]

String Int64::toString ( int64_t _n,
const wchar_t * _format )
static

Definition at line 496 of file Numeric.cpp.

497{
498 if (!_format)
499 _format = __T("%lld");
500
501 __DCL_ASSERT_PARAM(*_format != '\0');
502
503 return String::format(_format, _n);
504}

◆ toString() [2/3]

String Int64::toString ( int64_t _n,
unsigned _base = 10 )
static

Definition at line 484 of file Numeric.cpp.

485{
486 __DCL_ASSERT_PARAM(2 <= _base && _base <= 32);
487 // 2진수일경우 64 + sign = 65
488 CharBuffer* buf = CharBuffer::create(70);
489 __int64tow(_n, buf->data(), _base);
490 buf->__dataLength = String::length(buf->data());
491 String s(buf);
492 buf->release();
493 return s;
494}
wchar_t * __int64tow(int64_t _n, wchar_t *_buf, unsigned _base)
Definition __xtoa.cpp:87

◆ toString() [3/3]

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

Definition at line 117 of file Numeric.inl.

118{
119 return Int64::toString(__n, _base);
120}
String toString(unsigned _base=10) const
Definition Numeric.inl:117

Member Data Documentation

◆ __n

int64_t Int64::__n

Definition at line 122 of file Numeric.h.


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