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.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;
52 bool isOmitted(int index);
53 bool isNull(int index);
54 bool isUndefined(int index);
56 JSObjectRef toCallbackObject(int index, bool nullable, const char *callback, ...) const;
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;
66 std::map<std::string, std::string> toStringMap(int index, bool nullable = false) const;
69 JSValueRef getArgument(int index, bool nullable) const;
70 JSContextRef mContext;
72 const JSValueRef* mArgv;
79 #endif //_ARGUMENT_VALIDATOR_H_