forked from Softmotions/ejdb-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathejdb_args.h
More file actions
120 lines (93 loc) · 5.87 KB
/
ejdb_args.h
File metadata and controls
120 lines (93 loc) · 5.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/**************************************************************************************************
* EJDB database library http://ejdb.org
* Copyright (C) 2012-2013 Softmotions Ltd <info@softmotions.com>
*
* This file is part of EJDB.
* EJDB is free software; you can redistribute it and/or modify it under the terms of
* the GNU Lesser General Public License as published by the Free Software Foundation; either
* version 2.1 of the License or any later version. EJDB is distributed in the hope
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
* You should have received a copy of the GNU Lesser General Public License along with EJDB;
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA.
*************************************************************************************************/
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#ifndef EJDB_ARGS_H
#define EJDB_ARGS_H
#include <v8.h>
#include <node.h>
#define REQ_ARGS(N) \
if (args.Length() < (N)) \
return ThrowException(Exception::TypeError( \
String::New("Expected " #N " arguments")));
#define REQ_STR_ARG(I, VAR) \
if (args.Length() <= (I) || !args[I]->IsString()) \
return ThrowException(Exception::TypeError( \
String::New("Argument " #I " must be a string"))); \
String::Utf8Value VAR(args[I]->ToString());
#define REQ_STRW_ARG(I, VAR) \
if (args.Length() <= (I) || !args[I]->IsString()) \
return ThrowException(Exception::TypeError( \
String::New("Argument " #I " must be a string"))); \
String::Value VAR(args[I]->ToString());
#define REQ_FUN_ARG(I, VAR) \
if (args.Length() <= (I) || !args[I]->IsFunction()) \
return ThrowException(Exception::TypeError( \
String::New("Argument " #I " must be a function"))); \
Local<Function> VAR = Local<Function>::Cast(args[I]);
#define REQ_OBJ_ARG(I, VAR) \
if (args.Length() <= (I) || !args[I]->IsObject()) \
return ThrowException(Exception::TypeError( \
String::New("Argument " #I " must be a object"))); \
Local<Object> VAR = Local<Object>::Cast(args[I]);
#define REQ_VAL_ARG(I, VAR) \
if (args.Length() <= (I)) \
return ThrowException(Exception::TypeError( \
String::New("Argument " #I " must be a provided"))); \
Local<Value> VAR = args[I];
#define REQ_ARR_ARG(I, VAR) \
if (args.Length() <= (I) || !args[I]->IsArray()) \
return ThrowException(Exception::TypeError( \
String::New("Argument " #I " must be an array"))); \
Local<Array> VAR = Local<Array>::Cast(args[I]);
#define REQ_EXT_ARG(I, VAR) \
if (args.Length() <= (I) || !args[I]->IsExternal()) \
return ThrowException(Exception::TypeError( \
String::New("Argument " #I " invalid"))); \
Local<External> VAR = Local<External>::Cast(args[I]);
#define OPT_INT_ARG(I, VAR, DEFAULT) \
int VAR; \
if (args.Length() <= (I)) { \
VAR = (DEFAULT); \
} else if (args[I]->IsInt32()) { \
VAR = args[I]->Int32Value(); \
} else { \
return ThrowException(Exception::TypeError( \
String::New("Argument " #I " must be an integer"))); \
}
#define REQ_INT32_ARG(I, VAR) \
if (args.Length() <= (I) || !args[I]->IsInt32()) \
return ThrowException(Exception::TypeError( \
String::New("Argument " #I " must be an integer"))); \
int32_t VAR = args[I]->Int32Value();
#define REQ_INT64_ARG(I, VAR) \
if (args.Length() <= (I) || !args[I]->IsNumber()) \
return ThrowException(Exception::TypeError( \
String::New("Argument " #I " must be an number"))); \
int64_t VAR = args[I]->IntegerValue();
#define REQ_NUM_ARG(I, VAR) \
if (args.Length() <= (I) || !args[I]->IsNumber()) \
return ThrowException(Exception::TypeError( \
String::New("Argument " #I " must be an number"))); \
double VAR = args[I]->ToNumber()->Value();
#define REQ_BUFF_ARG(I, VAR) \
if (!Buffer::HasInstance(args[I])) { \
return ThrowException(Exception::Error( \
String::New("Argument " #I " must to be a buffer"))); \
} \
Buffer* VAR = ObjectWrap::Unwrap<Buffer>(args[I]->ToObject());
#endif /* EJDB_ARGS_H */