OSDN Git Service

initial files
[iptd/iPTd_R3.git] / src / Raym / Number.cpp
1 //
2 // Number.cpp
3 //
4
5 #define DBG_LEVEL 0
6 #include <Raym/Log.h>
7 #include <Raym/Number.h>
8
9 namespace Raym
10 {
11
12 Number::Number()
13 {
14     DebugLog2("Number::Number()");
15
16     _type = TYPE_Unkonown;
17     _value._unsignedLongLongValue = 0;
18 }
19
20 Number::~Number()
21 {
22     DebugLog2("Number::~Number()");
23 }
24
25 Number *Number::alloc()
26 {
27     DebugLog2("Number::alloc()");
28     return new Number();
29 }
30
31 Number *Number::initWithBool(bool value)
32 {
33     DebugLog2("Number::initWithBool()");
34
35     _type = TYPE_Bool;
36     _value._boolValue = value;
37     return this;
38 }
39
40 Number *Number::initWithInt(int value)
41 {
42     DebugLog2("Number::initWithInt()");
43
44     _type = TYPE_Int;
45     _value._intValue = value;
46     return this;
47 }
48
49 Number *Number::initWithUnsignedInt(uint value)
50 {
51     DebugLog2("Number::initWithUnsignedInt()");
52
53     _type = TYPE_UnsignedInt;
54     _value._unsignedIntValue = value;
55     return this;
56 }
57
58 Number *Number::retain()
59 {
60     DebugLog2("Number::retain()");
61
62     Object::retain();
63     return this;
64 }
65
66 Number *Number::autorelease()
67 {
68     DebugLog2("Number::autorelease()");
69
70     Object::autorelease();
71     return this;
72 }
73
74 bool Number::boolValue()
75 {
76     DebugLog2("Number::boolValue()");
77
78     return _value._boolValue;
79 }
80
81 int Number::intValue()
82 {
83     DebugLog2("Number::intValue()");
84
85     return _value._intValue;
86 }
87
88 uint Number::unsignedIntValue()
89 {
90     DebugLog2("Number::unsignedIntValue()");
91
92     return _value._unsignedIntValue;
93 }
94
95 String *Number::description()
96 {
97     DebugLog2("Number::description()");
98
99     switch (_type)
100     {
101     case TYPE_Bool:
102         return String::stringWithUTF8String(_value._boolValue ? "true" : "false");
103
104     case TYPE_Char:
105     case TYPE_Double:
106     case TYPE_Float:
107         break;
108
109     case TYPE_Int:
110         return String::stringWithFormat(String::stringWithUTF8String("%d"), _value._intValue);
111
112     case TYPE_Integer:
113     case TYPE_Long:
114     case TYPE_LongLong:
115     case TYPE_Short:
116     case TYPE_UnsignedChar:
117         break;
118
119     case TYPE_UnsignedInt:
120         return String::stringWithFormat(String::stringWithUTF8String("%u"), _value._intValue);
121         break;
122
123     case TYPE_UnsignedInteger:
124     case TYPE_UnsignedLong:
125     case TYPE_UnsignedLongLong:
126     case TYPE_UnsignedShort:
127     case TYPE_Unkonown:
128     default:
129         break;
130     }
131  
132     return String::stringWithFormat(String::stringWithCString("<Number: 0x%08x>", UTF8StringEncoding), this);
133 }
134
135
136 const char *Number::className()
137 {
138     return "Number";
139 }
140
141 } // Raym