-
Notifications
You must be signed in to change notification settings - Fork 1
/
qrubyobject.cpp
144 lines (116 loc) · 3.72 KB
/
qrubyobject.cpp
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//
// Copyright 2010-2015 Jacob Dawid <jacob@omg-it.works>
//
// This file is part of QtRuby.
//
// QtRuby is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// QtRuby 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 Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public
// License along with QtRuby.
// If not, see <http://www.gnu.org/licenses/>.
//
// It is possible to obtain a commercial license of QtRuby.
// Please contact Jacob Dawid <jacob@omg-it.works>
//
// Own includes
#include "qrubyobject.h"
#include "qrubyid.h"
#include "qrubyclass.h"
QRubyObject::QRubyObject() :
QRubyValue() {
_value = rb_newobj();
}
bool QRubyObject::isInstanceOf(QRubyClass classValue) {
return AS_BOOL(rb_obj_is_instance_of(_value, classValue.value()));
}
bool QRubyObject::isKindOf(QRubyClass classValue) {
return AS_BOOL(rb_obj_is_kind_of(_value, classValue.value()));
}
bool QRubyObject::respondsTo(QRubyId rubyId, bool includePrivate) {
return rb_obj_respond_to(_value, rubyId.id(), includePrivate ? Qtrue : Qfalse);
}
QRubyValue QRubyObject::instanceEval(QRubyValueList arguments) {
VALUE valueArguments[arguments.count()];
for(int index = 0; index < arguments.count(); index++) {
valueArguments[index] = arguments[index].value();
}
return rb_obj_instance_eval(arguments.count(), valueArguments, _value);
}
QRubyValue QRubyObject::instanceExec(QRubyValueList arguments) {
VALUE valueArguments[arguments.count()];
for(int index = 0; index < arguments.count(); index++) {
valueArguments[index] = arguments[index].value();
}
return rb_obj_instance_exec(arguments.count(), valueArguments, _value);
}
bool QRubyObject::isMethod() {
return AS_BOOL(rb_obj_is_method(_value));
}
bool QRubyObject::isProc() {
return AS_BOOL(rb_obj_is_proc(_value));
}
QRubyValue QRubyObject::method(QRubyValue methodName) {
return rb_obj_method(_value, methodName.value());
}
int QRubyObject::methodArity(QRubyId id) {
return rb_obj_method_arity(_value, id.id());
}
QRubyValue QRubyObject::initCopy(QRubyValue origin) {
return rb_obj_init_copy(_value, origin.value());
}
QRubyValue QRubyObject::alloc() {
return rb_obj_alloc(_value);
}
QRubyObject QRubyObject::clone() {
return QRubyValue(rb_obj_clone(_value)).toObject();
}
QRubyObject QRubyObject::dup() {
return QRubyValue(rb_obj_dup(_value)).toObject();
}
QRubyValue QRubyObject::taint() {
return rb_obj_taint(_value);
}
QRubyValue QRubyObject::untaint() {
return rb_obj_untaint(_value);
}
QRubyValue QRubyObject::tainted() {
return rb_obj_tainted(_value);
}
QRubyValue QRubyObject::trust() {
return rb_obj_trust(_value);
}
QRubyValue QRubyObject::untrust() {
return rb_obj_untrust(_value);
}
QRubyValue QRubyObject::untrusted() {
return rb_obj_untrusted(_value);
}
QRubyObject QRubyObject::freeze() {
return fromRubyValue(rb_obj_freeze(_value));
}
bool QRubyObject::isFrozen() {
return AS_BOOL(rb_obj_frozen_p(_value));
}
QRubyId QRubyObject::id() {
return rb_obj_id(_value);
}
QRubyClass QRubyObject::rubyClass() {
return QRubyClass::fromRubyValue(rb_obj_class(_value));
}
QRubyObject QRubyObject::fromRubyValue(QRubyValue rubyValue) {
QRubyObject rubyObject;
if(rubyValue.isObject()) {
rubyObject._value = rubyValue.value();
} else {
rubyObject._value = Qnil;
}
return rubyObject;
}