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

Constructor & Destructor Documentation

◆ Int32()

Int32::Int32 ( int32_t _n)
inline

Definition at line 88 of file Numeric.inl.

89{
90 __n = _n;
91}
int32_t __n
Definition Numeric.h:76

Member Function Documentation

◆ parse() [1/2]

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

Definition at line 314 of file Numeric.cpp.

315{
316 __DCL_ASSERT(_number != NULL);
317 __DCL_ASSERT(_base > 1);
318
319 if (*_number == __T('\0') || iswspace((wint_t)*_number)) {
320 return _default;
321 }
322
323 NumericConvertException::Error error = NumericConvertException::NoError;
324 errno = 0;
325 wchar_t* endptr = NULL;
326 long n = wcstol(_number, &endptr, _base);
327 if (errno == ERANGE) {
328 if (LONG_MIN == n) {
329 error = NumericConvertException::Underflow;
330 }
331 else if (LONG_MAX == n) {
332 error = NumericConvertException::Overflow;
333 }
334#if __WORDSIZE > 32
335 else if (n < INT32_MIN) {
336 error = NumericConvertException::Underflow;
337 }
338 else if (INT32_MAX < n) {
339 error = NumericConvertException::Overflow;
340 }
341#endif
342 }
343
344 if (NumericConvertException::NoError != error) {
345 return _default;
346 }
347
348 if ((endptr && *endptr != '\0') || errno == EINVAL) {
349 return _default;
350 }
351
352 return (int32_t)n;
353}
#define NULL
Definition Config.h:312
#define INT32_MAX
Definition Config.h:290
#define INT32_MIN
Definition Config.h:285
#define __DCL_ASSERT(expr)
Definition Object.h:394
#define __T(str)
Definition Object.h:60

◆ parse() [2/2]

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

Definition at line 264 of file Numeric.cpp.

266{
267 __DCL_ASSERT(_number != NULL);
268 __DCL_ASSERT(_base > 1);
269
270 if (*_number == __T('\0') || iswspace((wint_t)*_number)) {
271 throw new NumericConvertException(_number, _base, 0);
272 }
273
274 NumericConvertException::Error error = NumericConvertException::NoError;
275 errno = 0;
276 wchar_t* endptr = NULL;
277 long n = wcstol(_number, &endptr, _base);
278 if (errno == ERANGE) {
279 if (LONG_MIN == n) {
280 error = NumericConvertException::Underflow;
281 }
282 else if (LONG_MAX == n) {
283 error = NumericConvertException::Overflow;
284 }
285#if __WORDSIZE > 32
286 else if (n < INT32_MIN) {
287 error = NumericConvertException::Underflow;
288 }
289 else if (INT32_MAX < n) {
290 error = NumericConvertException::Overflow;
291 }
292#endif
293 }
294
295 if (NumericConvertException::NoError != error) {
296 throw new NumericConvertException(
297 error,
298 _number,
299 _base
300 );
301 }
302
303 if ((endptr && *endptr != '\0') || errno == EINVAL) {
304 throw new NumericConvertException(
305 _number,
306 _base,
307 endptr ? (endptr - _number) : 0
308 );
309 }
310
311 return (int32_t)n;
312}

◆ toByteString()

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

Definition at line 355 of file Numeric.cpp.

356{
357 __DCL_ASSERT_PARAM(2 <= _base && _base <= 32);
358 // 2진수일경우 32 + sign = 33
359 ByteBuffer* buf = ByteBuffer::create(40);
360 __int32toa(_n, buf->data(), _base);
361 buf->__dataLength = ByteString::length(buf->data());
362 ByteString s(buf);
363 buf->release();
364 return s;
365}
char * __int32toa(int32_t _n, char *_buf, unsigned _base)
Definition __xtoa.cpp:27
#define __DCL_ASSERT_PARAM(expr)
Definition Object.h:409

◆ toString() [1/3]

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

Definition at line 254 of file Numeric.cpp.

255{
256 if (!_format)
257 _format = __T("%ld");
258
259 __DCL_ASSERT_PARAM(*_format != '\0');
260
261 return String::format(_format, _n);
262}

◆ toString() [2/3]

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

Definition at line 242 of file Numeric.cpp.

243{
244 __DCL_ASSERT_PARAM(2 <= _base && _base <= 32);
245 // 2진수일경우 32 + sign = 33
246 CharBuffer* buf = CharBuffer::create(40);
247 __int32tow(_n, buf->data(), _base);
248 buf->__dataLength = String::length(buf->data());
249 String s(buf);
250 buf->release();
251 return s;
252}
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 93 of file Numeric.inl.

94{
95 return Int32::toString(__n, _base);
96}
String toString(unsigned _base=10) const
Definition Numeric.inl:93

Member Data Documentation

◆ __n

int32_t Int32::__n

Definition at line 76 of file Numeric.h.


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