2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 * @author Kisub Song (kisubs.song@samsung.com)
21 * @brief Declaration of the JSFilter class
24 #ifndef _API_ANYTYPE_H_
25 #define _API_ANYTYPE_H_
30 #include <dpl/shared_ptr.h>
31 #include <CommonsJavaScript/Converter.h>
38 #define _PT_UNDEFINED (0)
39 #define _PT_NULL (1 << 0)
40 #define _PT_BOOLEAN (1 << 1)
41 #define _PT_CHAR (1 << 2)
42 #define _PT_UCHAR (1 << 3)
43 #define _PT_INT (1 << 4)
44 #define _PT_UINT (1 << 5)
45 #define _PT_LONG (1 << 6)
46 #define _PT_ULONG (1 << 7)
47 #define _PT_DOUBLE (1 << 8)
48 #define _PT_STRING (1 << 9)
49 #define _PT_TIME (1 << 10)
50 #define _PT_OBJECT (1 << 11)
53 PrimitiveType_NoType = 0,
54 PrimitiveType_Undefined = _PT_UNDEFINED,
55 PrimitiveType_Null = _PT_NULL,
56 PrimitiveType_Boolean = _PT_BOOLEAN,
57 PrimitiveType_Char = _PT_CHAR,
58 PrimitiveType_UChar = _PT_UCHAR,
59 PrimitiveType_Int = _PT_INT,
60 PrimitiveType_UInt = _PT_UINT,
61 PrimitiveType_Long = _PT_LONG,
62 PrimitiveType_ULong = _PT_ULONG,
63 PrimitiveType_Double = _PT_DOUBLE,
64 PrimitiveType_String = _PT_STRING,
65 PrimitiveType_Time = _PT_TIME,
66 PrimitiveType_Object = _PT_OBJECT,
67 PrimitiveType_Number = (_PT_CHAR | _PT_UCHAR | _PT_INT | _PT_UINT |
68 _PT_LONG | _PT_ULONG | _PT_DOUBLE),
69 PrimitiveType_Integer = (_PT_CHAR | _PT_UCHAR | _PT_INT | _PT_UINT |
70 _PT_LONG | _PT_ULONG),
71 PrimitiveType_Any = (_PT_BOOLEAN | _PT_CHAR | _PT_UCHAR | _PT_INT |
72 _PT_UINT | _PT_LONG | _PT_ULONG | _PT_DOUBLE |
73 _PT_STRING | _PT_TIME | _PT_OBJECT)
99 Any(double value, std::string json);
100 Any(std::string value);
101 Any(std::tm value, std::string json);
102 Any(void * priv, std::string json);
105 virtual std::string toString() const;
106 std::string toJSON() const;
108 unsigned int getType() const;
109 bool isType(PrimitiveType type) const;
110 bool isNullOrUndefined() const;
112 bool getBool() const;
113 char getChar() const;
114 unsigned char getUChar() const;
116 unsigned int getUInt() const;
117 long getLong() const;
118 unsigned long getULong() const;
119 double getDouble() const;
120 std::string getString() const;
121 std::tm getDateTm() const;
122 std::time_t getTimeT() const;
124 typedef DPL::SharedPtr<Any> AnyPtr;
126 typedef std::vector<AnyPtr> AnyArray;
127 typedef DPL::SharedPtr<AnyArray> AnyArrayPtr;
129 class AnyTypeConverter : public WrtDeviceApis::CommonsJavaScript::Converter
132 explicit AnyTypeConverter(JSContextRef context);
133 virtual ~AnyTypeConverter();
135 JSValueRef toJSValueRef(const AnyPtr& arg);
136 AnyPtr toAny(const JSValueRef &value);
138 bool toBool(const AnyPtr& arg);
139 char toChar(const AnyPtr& arg);
140 unsigned char toUChar(const AnyPtr& arg);
141 int toInt(const AnyPtr& arg);
142 unsigned int toUInt(const AnyPtr& arg);
143 long toLong(const AnyPtr& arg);
144 unsigned long toULong(const AnyPtr& arg);
145 double toDouble(const AnyPtr& arg);
146 std::string toString(const AnyPtr& arg);
147 tm toDateTm(const AnyPtr& arg);
148 time_t toTimeT(const AnyPtr& arg);
150 using WrtDeviceApis::CommonsJavaScript::Converter::toJSValueRef;
151 using WrtDeviceApis::CommonsJavaScript::Converter::toString;
152 using WrtDeviceApis::CommonsJavaScript::Converter::toDateTm;
155 bool isDate(const JSValueRef& arg);
158 typedef WrtDeviceApis::CommonsJavaScript::ConverterFactory<AnyTypeConverter> AnyTypeConverterFactory;
164 #endif // _API_ANYTYPE_H_