//
-// Open Service Platform
// Copyright (c) 2012 Samsung Electronics Co., Ltd.
//
// Licensed under the Apache License, Version 2.0 (the License);
* @brief This is the implementation file for LongLong class.
* @see Number
*/
-
#include <wchar.h>
#include <limits.h>
#include <errno.h>
#include <FBaseResult.h>
#include <FBaseCharacter.h>
#include <FBaseSysLog.h>
+#include "FBase_NumberUtil.h"
namespace Tizen { namespace Base
{
bool
LongLong::Equals(const Object& obj) const
{
- const LongLong* pOther = dynamic_cast <const LongLong*>(&obj);
+ const LongLong* pOther = dynamic_cast< const LongLong* >(&obj);
if (pOther == null)
{
return false;
int
LongLong::GetHashCode(void) const
{
- return static_cast<int> (value);
+ return static_cast< int >(value);
}
int
LongLong::GetHashCode(long long val)
{
- return static_cast<int> (val);
+ return static_cast< int >(val);
}
char
LongLong::ToChar(void) const
{
- return static_cast<char> (value);
+ return static_cast< char >(value);
+}
+
+int8_t
+LongLong::ToInt8(void) const
+{
+ return static_cast< int8_t >(value);
}
short
LongLong::ToShort(void) const
{
- return static_cast<short> (value);
+ return static_cast< short >(value);
}
int
LongLong::ToInt(void) const
{
- return static_cast<int> (value);
+ return static_cast< int >(value);
}
long
LongLong::ToLong(void) const
{
- return static_cast<long> (value);
+ return static_cast< long >(value);
}
float
LongLong::ToFloat(void) const
{
- return static_cast<float> (value);
+ return static_cast< float >(value);
}
double
LongLong::ToDouble(void) const
{
- return static_cast<double> (value);
+ return static_cast< double >(value);
}
long long
}
result
-LongLong::Parse(const String& s, long long& ret)
+LongLong::Decode(const String& inputStr, long long& ret)
{
- wchar_t* pEnd = null;
-
- int len = s.GetLength();
- SysTryReturn(NID_BASE, (len > 0), E_NUM_FORMAT, E_NUM_FORMAT, "[E_NUM_FORMAT] The length of s MUST be greater than 0.");
+ long long value;
+ result r = _NumberUtil::Decode(inputStr, value);
+ SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "Propagating.");
+ ret = value;
+ return r;
+}
- errno = 0;
- ret = wcstoll(s.GetPointer(), &pEnd, 10);
- SysTryReturn(NID_BASE, (!(ret == 0 && errno == EINVAL) && (pEnd[0] == 0)), E_NUM_FORMAT, E_NUM_FORMAT,
- "[E_NUM_FORMAT] LongLong parse failed. Scan stopped at (%ls)",
- pEnd);
- SysTryReturn(NID_BASE, !(errno == ERANGE && (ret == LLONG_MAX || ret == LLONG_MIN)), E_NUM_FORMAT, E_NUM_FORMAT,
- "[E_NUM_FORMAT] Parsed value cannot fit into a LongLong.");
+result
+LongLong::Parse(const String& s, long long& ret)
+{
+ return Parse(s, Character::RADIX_DECIMAL, ret);
+}
- return E_SUCCESS;
+result
+LongLong::Parse(const String& s, int radix, long long& ret)
+{
+ long long value;
+ result r = _NumberUtil::Parse(s, radix, value);
+ SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "Propagating.");
+ ret = value;
+ return r;
}
}} //Tizen::Base