Class: Rbind::RBase
- Inherits:
-
Object
- Object
- Rbind::RBase
- Defined in:
- lib/rbind/core/rbase.rb
Direct Known Subclasses
Class Attribute Summary collapse
-
.cprefix ⇒ Object
Returns the value of attribute cprefix.
Instance Attribute Summary collapse
-
#alias(val = nil) ⇒ Object
Returns the value of attribute alias.
-
#auto_alias ⇒ Object
set to true if rbind is aliasing the object.
-
#cname(name = nil) ⇒ Object
Returns the value of attribute cname.
-
#csignature(sig = nil) ⇒ Object
Returns the value of attribute csignature.
-
#doc(&block) ⇒ Object
Returns the value of attribute doc.
-
#extern_package_name ⇒ Object
Returns the value of attribute extern_package_name.
-
#ignore ⇒ Object
Returns the value of attribute ignore.
-
#name ⇒ Object
Returns the value of attribute name.
-
#namespace ⇒ Object
Returns the value of attribute namespace.
-
#owner ⇒ Object
Returns the value of attribute owner.
-
#signature(sig = nil) ⇒ Object
Returns the value of attribute signature.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
- .basename(name) ⇒ Object
- .namespace(name) ⇒ Object
- .normalize(name) ⇒ Object
- .split_name(name) ⇒ Object
- .to_cname(name) ⇒ Object
Instance Method Summary collapse
- #binding ⇒ Object
- #delete! ⇒ Object
- #doc? ⇒ Boolean
-
#extern? ⇒ Boolean
returns true if this object is defined in another extern package.
- #full_name ⇒ Object
- #generate_signatures ⇒ Object
- #ignore? ⇒ Boolean
-
#initialize(name) ⇒ RBase
constructor
A new instance of RBase.
- #map_to_namespace(name) ⇒ Object
- #namespace? ⇒ Boolean
-
#overwrite_c(&block) ⇒ Object
depends on type at the moment only operations can be overwritten.
-
#overwrite_ruby(&block) ⇒ Object
depends on type at the moment only rbind_from_native can be overwritten.
- #pretty_print(pp) ⇒ Object
- #rename(name) ⇒ Object
-
#specialize_ruby(&block) ⇒ Object
specialize.
- #to_s ⇒ Object
Constructor Details
#initialize(name) ⇒ RBase
Returns a new instance of RBase.
71 72 73 74 |
# File 'lib/rbind/core/rbase.rb', line 71 def initialize(name) rename(name) @version = 1 end |
Class Attribute Details
.cprefix ⇒ Object
Returns the value of attribute cprefix.
17 18 19 |
# File 'lib/rbind/core/rbase.rb', line 17 def cprefix @cprefix end |
Instance Attribute Details
#alias(val = nil) ⇒ Object
Returns the value of attribute alias.
5 6 7 |
# File 'lib/rbind/core/rbase.rb', line 5 def alias @alias end |
#auto_alias ⇒ Object
set to true if rbind is aliasing the object
6 7 8 |
# File 'lib/rbind/core/rbase.rb', line 6 def auto_alias @auto_alias end |
#cname(name = nil) ⇒ Object
Returns the value of attribute cname.
4 5 6 |
# File 'lib/rbind/core/rbase.rb', line 4 def cname @cname end |
#csignature(sig = nil) ⇒ Object
Returns the value of attribute csignature.
11 12 13 |
# File 'lib/rbind/core/rbase.rb', line 11 def csignature @csignature end |
#doc(&block) ⇒ Object
Returns the value of attribute doc.
14 15 16 |
# File 'lib/rbind/core/rbase.rb', line 14 def doc @doc end |
#extern_package_name ⇒ Object
Returns the value of attribute extern_package_name.
13 14 15 |
# File 'lib/rbind/core/rbase.rb', line 13 def extern_package_name @extern_package_name end |
#ignore ⇒ Object
Returns the value of attribute ignore.
12 13 14 |
# File 'lib/rbind/core/rbase.rb', line 12 def ignore @ignore end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/rbind/core/rbase.rb', line 3 def name @name end |
#namespace ⇒ Object
Returns the value of attribute namespace.
7 8 9 |
# File 'lib/rbind/core/rbase.rb', line 7 def namespace @namespace end |
#owner ⇒ Object
Returns the value of attribute owner.
8 9 10 |
# File 'lib/rbind/core/rbase.rb', line 8 def owner @owner end |
#signature(sig = nil) ⇒ Object
Returns the value of attribute signature.
10 11 12 |
# File 'lib/rbind/core/rbase.rb', line 10 def signature @signature end |
#version ⇒ Object
Returns the value of attribute version.
9 10 11 |
# File 'lib/rbind/core/rbase.rb', line 9 def version @version end |
Class Method Details
.basename(name) ⇒ Object
61 62 63 |
# File 'lib/rbind/core/rbase.rb', line 61 def basename(name) split_name(name)[1] end |
.namespace(name) ⇒ Object
57 58 59 |
# File 'lib/rbind/core/rbase.rb', line 57 def namespace(name) split_name(name)[0] end |
.normalize(name) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/rbind/core/rbase.rb', line 36 def normalize(name) name = name.to_s if name.split("/n").size > 1 raise "mulitple lines for a name is not supported: #{name}" end name.gsub(".","::").gsub(" ","") end |
.split_name(name) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rbind/core/rbase.rb', line 44 def split_name(name) name = normalize(name) if(name =~/(.*>)::(.*)$/) [$1,$2] elsif(name =~ /^([\w\d]*)::(.*)/) b,n = split_name($2) b = b ? "::#{b}" : "" [$1+b,n] else [nil,name] end end |
.to_cname(name) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rbind/core/rbase.rb', line 19 def to_cname(name) name = normalize(name) cn = "#{cprefix}#{name.gsub("::","_")}" if cn =~ /operator/ # Use alias instead of operator symbol for name RNamespace.default_operator_alias.each do |op, alias_name| cn = cn.gsub("operator#{op}","operator_#{alias_name}") end end cn = cn.gsub("*","_ptr") cn = cn.gsub("&","_ref") cn = cn.gsub("<","_") cn = cn.gsub(">","") cn = cn.gsub(",","__") cn end |
Instance Method Details
#binding ⇒ Object
185 186 187 |
# File 'lib/rbind/core/rbase.rb', line 185 def binding Kernel.binding end |
#delete! ⇒ Object
177 178 179 180 181 182 183 |
# File 'lib/rbind/core/rbase.rb', line 177 def delete! if @owner @owner.delete_type self.name else raise "#{self} has no owner." end end |
#doc? ⇒ Boolean
189 190 191 |
# File 'lib/rbind/core/rbase.rb', line 189 def doc? !!doc end |
#extern? ⇒ Boolean
returns true if this object is defined in another extern package
85 86 87 |
# File 'lib/rbind/core/rbase.rb', line 85 def extern? extern_package_name && !extern_package_name.empty? end |
#full_name ⇒ Object
149 150 151 |
# File 'lib/rbind/core/rbase.rb', line 149 def full_name map_to_namespace(name) end |
#generate_signatures ⇒ Object
76 77 78 |
# File 'lib/rbind/core/rbase.rb', line 76 def generate_signatures ["#{full_name}","#{cname}"] end |
#ignore? ⇒ Boolean
80 81 82 |
# File 'lib/rbind/core/rbase.rb', line 80 def ignore? !!@ignore end |
#map_to_namespace(name) ⇒ Object
157 158 159 160 161 162 163 |
# File 'lib/rbind/core/rbase.rb', line 157 def map_to_namespace(name) if namespace "#{namespace}::#{name}" else name end end |
#namespace? ⇒ Boolean
145 146 147 |
# File 'lib/rbind/core/rbase.rb', line 145 def namespace? namespace && namespace.size != 0 end |
#overwrite_c(&block) ⇒ Object
depends on type at the moment only operations can be overwritten
215 216 217 218 219 220 221 |
# File 'lib/rbind/core/rbase.rb', line 215 def overwrite_c(&block) if block @overwrite_c = block elsif @overwrite_c @overwrite_c.call end end |
#overwrite_ruby(&block) ⇒ Object
depends on type at the moment only rbind_from_native can be overwritten
226 227 228 229 230 231 232 |
# File 'lib/rbind/core/rbase.rb', line 226 def overwrite_ruby(&block) if block @overwrite_ruby = block elsif @overwrite_ruby @overwrite_ruby.call end end |
#pretty_print(pp) ⇒ Object
67 68 69 |
# File 'lib/rbind/core/rbase.rb', line 67 def pretty_print(pp) pp.text "#{signature}" end |
#rename(name) ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/rbind/core/rbase.rb', line 165 def rename(name) old_name = self.name name = RBase::normalize(name) raise ArgumentError, "no name" unless name && name.size > 0 @name = RBase::basename(name) @namespace = RBase::namespace(name) if @owner @owner.delete_type old_name @owner.add_type(self) end end |
#specialize_ruby(&block) ⇒ Object
specialize
204 205 206 207 208 209 210 |
# File 'lib/rbind/core/rbase.rb', line 204 def specialize_ruby(&block) if block @specialize_ruby = block elsif @specialize_ruby @specialize_ruby.call end end |
#to_s ⇒ Object
153 154 155 |
# File 'lib/rbind/core/rbase.rb', line 153 def to_s signature end |