2 // Tizen Web Device API
3 // Copyright (c) 2013 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 #ifndef _ARGUMENT_VALIDATOR_H_
19 #define _ARGUMENT_VALIDATOR_H_
24 #include <JavaScriptCore/JavaScript.h>
30 class ArgumentValidator{
32 ArgumentValidator(JSContextRef ctx, int argc, const JSValueRef* argv);
35 double toNumber(int index, bool nullable = false, double defaultvalue = 0) const;
36 long toLong(int index, bool nullable = false, long defaultvalue = 0) const;
37 unsigned long toULong(int index, bool nullable = false, 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, long long defaultvalue = 0) const;
40 double toDouble(int index, bool nullable = false, double defaultvalue = 0) const;
41 std::string toString(int index, bool nullable = false, const std::string& defaultvalue = "") const;
42 bool toBool(int index, bool nullable = false, bool defaultvalue = false) const;
43 time_t toTimeT(int index, bool nullable = false, time_t defaultvalue = 0) const;
44 JSObjectRef toObject(int index, bool nullable = false) const;
45 JSObjectRef toObject(int index, JSClassRef info, bool nullable = false) const;
46 JSObjectRef toFunction(int index, bool nullable = false) const;
47 JSObjectRef toArrayObject(int index, bool nullable = false) const;
48 JSValueRef toJSValueRef(int index, bool nullable = false) const;
50 std::vector<std::string> toStringVector(int index, bool nullable = false) const;
51 std::vector<long> toLongVector(int index, bool nullable = false) const;
52 std::vector<double> toDoubleVector(int index, bool nullable = false) const;
53 std::vector<time_t> toTimeTVector(int index, bool nullable = false) const;
54 std::vector<bool> toBoolVector(int index, bool nullable = false) const;
55 std::vector<JSValueRef> toJSValueRefVector(int index, bool nullable= false) const;
57 std::map<std::string, std::string> toStringMap(int index, bool nullable = false) const;
60 JSValueRef getArgument(int index, bool nullable) const;
61 JSContextRef mContext;
63 const JSValueRef* mArgv;
70 #endif //_ARGUMENT_VALIDATOR_H_