Class: Rbind::RClass
Defined Under Namespace
Classes: ParentClass
Instance Attribute Summary collapse
Attributes inherited from RNamespace
#consts, #operation_alias, #root, #type_alias
Attributes inherited from RDataType
#check_type, #invalid_value, #ptr, #ref, #typedef
Attributes inherited from RBase
#alias, #auto_alias, #cname, #csignature, #doc, #extern_package_name, #ignore, #name, #namespace, #owner, #signature, #version
Instance Method Summary
collapse
Methods inherited from RNamespace
#add_const, #add_default_types, #add_namespace, #add_operation, #add_simple_type, #add_simple_types, #add_type, #const, #container?, #delete_type, #each_const, #each_container, #each_operation, #each_type, #extern?, #method_missing, #operation?, #root?, #type, #types, #use_namespace
Methods inherited from RDataType
#==, #check_type?, #cname, #const?, #container?, #ptr?, #raw?, #ref?, #remove_const, #template?, #to_const, #to_ptr, #to_raw, #to_ref, #to_single_ptr, #typedef?
Methods inherited from RBase
basename, #binding, #delete!, #extern?, #full_name, #generate_signatures, #ignore?, #map_to_namespace, namespace, #namespace?, normalize, #rename, #specialize_ruby, split_name, to_cname, #to_s
Constructor Details
#initialize(name, *parent_classes) ⇒ RClass
Returns a new instance of RClass.
8
9
10
11
12
13
14
15
16
|
# File 'lib/rbind/core/rclass.rb', line 8
def initialize(name,*parent_classes)
@parent_classes = Hash.new
@attributes = Hash.new
parent_classes.flatten!
parent_classes.each do |p|
add_parent(p)
end
super(name)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Rbind::RNamespace
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
5
6
7
|
# File 'lib/rbind/core/rclass.rb', line 5
def attributes
@attributes
end
|
#parent_classes(accessor = :public) ⇒ Object
Returns the value of attribute parent_classes.
4
5
6
|
# File 'lib/rbind/core/rclass.rb', line 4
def parent_classes
@parent_classes
end
|
Instance Method Details
#add_attribute(attr) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/rbind/core/rclass.rb', line 31
def add_attribute(attr)
if attr.namespace?
type(attr.namespace).add_attribute(attr)
else
if @attributes.has_key? attr.name
raise "#An attribute with the name #{attr.name} already exists"
end
attr.owner = self
@attributes[attr.name] = attr
add_operation(RGetter.new(attr)) if attr.readable?
add_operation(RSetter.new(attr)) if attr.writeable?
end
self
end
|
#add_parent(klass, accessor = :public) ⇒ Object
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
|
# File 'lib/rbind/core/rclass.rb', line 186
def add_parent(klass,accessor=:public)
klass,accessor = if klass.is_a?(ParentClass)
[klass.type,klass.accessor]
else
[klass,accessor]
end
if @parent_classes.has_key? klass.name
raise ArgumentError,"#A parent class with the name #{klass.name} already exists"
end
if klass.full_name == full_name || klass == self
raise ArgumentError,"class #{klass.full_name} cannot be parent of its self"
end
klass.check_type = false
@parent_classes[klass.name] = ParentClass.new(klass,accessor)
self
end
|
#attribute(name) ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/rbind/core/rclass.rb', line 63
def attribute(name)
attrib = @attributes[name]
attrib ||= begin
p = parent_classes.find do |k|
k.type.attribute(name)
end
a = p.attribute(name).dup if p
a.owner = self if a
a
end
end
|
#basic_type? ⇒ Boolean
18
19
20
|
# File 'lib/rbind/core/rclass.rb', line 18
def basic_type?
false
end
|
#cdelete_method ⇒ Object
143
144
145
146
147
148
149
150
151
152
153
|
# File 'lib/rbind/core/rclass.rb', line 143
def cdelete_method
if @cdelete_method
@cdelete_method
else
if cname =~ /^#{RBase.cprefix}(.*)/
"#{RBase.cprefix}delete_#{$1}"
else
"#{RBase.cprefix}delete_#{name}"
end
end
end
|
#constructor? ⇒ Boolean
22
23
24
25
26
27
28
29
|
# File 'lib/rbind/core/rclass.rb', line 22
def constructor?
ops = Array(operation(name,false))
return false unless ops
op = ops.find do |op|
op.constructor?
end
!!op
end
|
#empty? ⇒ Boolean
155
156
157
|
# File 'lib/rbind/core/rclass.rb', line 155
def empty?
super && parent_classes.empty? && attributes.empty?
end
|
#operation(name, raise_ = true) ⇒ Object
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
# File 'lib/rbind/core/rclass.rb', line 121
def operation(name,raise_=true)
ops = if @operations.has_key? name
@operations[name].dup
else
[]
end
parent_classes.each do |k|
other_ops = Array(k.type.operation(name,false))
other_ops.delete_if do |other_op|
ops.include? other_op
end
ops += other_ops
end
if(ops.size == 1)
ops.first
elsif ops.empty?
raise "#{full_name} has no operation called #{name}." if raise_
else
ops
end
end
|
#operations ⇒ Object
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
|
# File 'lib/rbind/core/rclass.rb', line 75
def operations
own_ops = @operations.dup
parent_classes.each do |k|
k.type.operations.each do |other_ops|
next if other_ops.empty?
ops = if @operations.has_key?(other_ops.first.name)
@operations[other_ops.first.name]
else
[]
end
other_ops.delete_if do |other_op|
next true if !other_op
op = ops.find do |o|
o == other_op
end
next false if !op
next true if op.base_class == self
next true if op.base_class == other_op.base_class
op.ambiguous_name = true
other_op.ambiguous_name = true
false
end
other_ops = other_ops.map(&:dup)
other_ops.each do |other|
old = other.alias
add_operation other
end
end
end
result = @operations.values.map(&:dup)
@operations = own_ops
result
end
|
#parent_class(name) ⇒ Object
205
206
207
|
# File 'lib/rbind/core/rclass.rb', line 205
def parent_class(name)
@parent_class[name].type
end
|
#pretty_print(pp) ⇒ Object
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
# File 'lib/rbind/core/rclass.rb', line 170
def pretty_print(pp)
super
unless attributes.empty?
pp.nest(2) do
pp.breakable
pp.text "Attributes:"
pp.nest(2) do
attributes.each do |a|
pp.breakable
pp.pp(a)
end
end
end
end
end
|
#pretty_print_name ⇒ Object
159
160
161
162
163
164
165
166
167
168
|
# File 'lib/rbind/core/rclass.rb', line 159
def pretty_print_name
str = "#{"template " if template?}class #{full_name}"
unless parent_classes.empty?
parents = parent_classes.map do |p|
p.type.full_name
end
str += " : " + parents.join(", ")
end
str
end
|
#used_namespaces ⇒ Object
113
114
115
116
117
118
119
|
# File 'lib/rbind/core/rclass.rb', line 113
def used_namespaces
namespaces = super.clone
parent_classes.each do |k|
namespaces += k.type.used_namespaces
end
namespaces
end
|