tizen 2.3 release
[framework/web/wearable/wrt-plugins-tizen.git] / src / Common / ArgumentValidator.h
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 #ifndef _ARGUMENT_VALIDATOR_H_
19 #define _ARGUMENT_VALIDATOR_H_
20
21 #include <string>
22 #include <vector>
23 #include <map>
24 #include <JavaScriptCore/JavaScript.h>
25 #include <ctime>
26
27 namespace DeviceAPI {
28 namespace Common{
29
30 class ArgumentValidator{
31 public:
32     ArgumentValidator(JSContextRef ctx, int argc, const JSValueRef* argv);
33     ~ArgumentValidator();
34
35     double toNumber(int index, bool nullable = false, double defaultvalue = 0.0) const;
36     long toLong(int index, bool nullable = false, long defaultvalue = 0) const;
37     unsigned long toULong(int index, bool nullable = false, unsigned long defaultvalue = 0) const;
38     long long toLongLong(int index, bool nullable = false, long long defaultvalue = 0) const;
39     unsigned long long toULongLong(int index, bool nullable = false, unsigned long long defaultvalue = 0) const;
40     double toDouble(int index, bool nullable = false, double defaultvalue = 0.0) const;
41     signed char toByte(int index, bool nullable = false, signed char defaultvalue = 0) const;
42     unsigned char toOctet(int index, bool nullable = false, unsigned char defaultvalue = 0) const;
43     std::string toString(int index, bool nullable = false, const std::string& defaultvalue = "") const;
44     bool toBool(int index, bool nullable = false, bool defaultvalue = false) const;
45     time_t toTimeT(int index, bool nullable = false, time_t defaultvalue = 0) const;
46     JSObjectRef toObject(int index, bool nullable = false) const;
47     JSObjectRef toObject(int index, JSClassRef info, bool nullable = false) const;
48     JSObjectRef toFunction(int index, bool nullable = false) const;
49     JSObjectRef toArrayObject(int index, bool nullable = false) const;
50     JSValueRef toJSValueRef(int index, bool nullable = false) const;
51
52     bool isOmitted(int index);
53     bool isNull(int index);
54     bool isUndefined(int index);
55
56     JSObjectRef toCallbackObject(int index, bool nullable, const char *callback, ...) const;
57
58     std::vector<std::string> toStringVector(int index, bool nullable = false) const;
59     std::vector<long> toLongVector(int index, bool nullable = false) const;
60     std::vector<double> toDoubleVector(int index, bool nullable = false) const;
61     std::vector<time_t> toTimeTVector(int index, bool nullable = false) const;
62     std::vector<bool> toBoolVector(int index, bool nullable = false) const;
63     std::vector<unsigned char> toUCharVector(int index, bool nullable = false) const;
64     std::vector<JSValueRef> toJSValueRefVector(int index, bool nullable= false) const;
65
66     std::map<std::string, std::string> toStringMap(int index, bool nullable = false) const;
67
68 private:
69     JSValueRef getArgument(int index, bool nullable) const;
70     JSContextRef mContext;
71     int mArgc;
72     const JSValueRef* mArgv;
73
74 };
75
76 }
77 }
78
79 #endif //_ARGUMENT_VALIDATOR_H_
80
81