Class: Rbind::GeneratorRuby::RTypeHelper
- Inherits:
-
HelperBase
- Object
- HelperBase
- Rbind::GeneratorRuby::RTypeHelper
- Defined in:
- lib/rbind/generator_ruby.rb
Defined Under Namespace
Classes: OperationHelper
Instance Method Summary collapse
- #add_constructor ⇒ Object
- #add_consts(root = @root) ⇒ Object
- #add_methods(root = @root) ⇒ Object
- #add_specializing ⇒ Object
- #add_types(root = @root) ⇒ Object
- #cdelete_method ⇒ Object
- #cname ⇒ Object
- #full_name ⇒ Object
-
#initialize(name, root, compact_namespace = false) ⇒ RTypeHelper
constructor
A new instance of RTypeHelper.
- #name ⇒ Object
- #result ⇒ Object
Methods inherited from HelperBase
Constructor Details
#initialize(name, root, compact_namespace = false) ⇒ RTypeHelper
Returns a new instance of RTypeHelper.
275 276 277 278 279 280 281 282 283 |
# File 'lib/rbind/generator_ruby.rb', line 275 def initialize(name, root,compact_namespace = false) @type_wrapper = ERB.new(File.open(File.join(File.dirname(__FILE__),"templates","ruby","rtype.rb")).read,nil,"-") @type_constructor_wrapper = ERB.new(File.open(File.join(File.dirname(__FILE__),"templates","ruby","rtype_constructor.rb")).read,nil,"-") @namespace_wrapper = ERB.new(File.open(File.join(File.dirname(__FILE__),"templates","ruby","rnamespace.rb")).read,nil,"-") @static_method_wrapper = ERB.new(File.open(File.join(File.dirname(__FILE__),"templates","ruby","rstatic_method.rb")).read) @method_wrapper = ERB.new(File.open(File.join(File.dirname(__FILE__),"templates","ruby","rmethod.rb")).read,nil,'-') @compact_namespace = compact_namespace super(name,root) end |
Instance Method Details
#add_constructor ⇒ Object
305 306 307 308 309 310 311 312 313 314 |
# File 'lib/rbind/generator_ruby.rb', line 305 def add_constructor raise "there is no constructor for namespaces!" if self.is_a?(RNamespace) ops = Array(@root.operation(@root.name,false)) return until ops ops.map do |c| next if c.ignore? ch = OperationHelper.new(c) @type_constructor_wrapper.result(ch.binding) end.join("\n") end |
#add_consts(root = @root) ⇒ Object
316 317 318 319 320 321 322 323 324 325 326 327 328 |
# File 'lib/rbind/generator_ruby.rb', line 316 def add_consts(root=@root) str = @root.consts.map do |c| next if c.extern? || c.ignore? " #{c.name} = #{GeneratorRuby::normalize_type_name(c.value)}\n" end.join return str unless @compact_namespace root.each_type(false) do |t| next if t.basic_type? && !t.is_a?(RNamespace) str += add_consts(t) if name == GeneratorRuby.normalize_type_name(t.full_name) end str end |
#add_methods(root = @root) ⇒ Object
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 |
# File 'lib/rbind/generator_ruby.rb', line 330 def add_methods(root=@root) str = "" @root.each_operation do |op| next if op.constructor? oph = OperationHelper.new(op) str += if op.instance_method? @method_wrapper.result(oph.binding) else @static_method_wrapper.result(oph.binding) end end return str unless @compact_namespace root.each_type(false) do |t| next if t.basic_type? && !t.is_a?(RNamespace) str += add_methods(t) if name == GeneratorRuby.normalize_type_name(t.full_name) end str end |
#add_specializing ⇒ Object
297 298 299 300 301 302 303 |
# File 'lib/rbind/generator_ruby.rb', line 297 def add_specializing if @root.respond_to?(:specialize_ruby) @root.specialize_ruby else nil end end |
#add_types(root = @root) ⇒ Object
350 351 352 353 354 355 356 357 358 359 360 361 |
# File 'lib/rbind/generator_ruby.rb', line 350 def add_types(root = @root) str = "" root.each_type(false) do |t| next if t.basic_type? && !t.is_a?(RNamespace) str += if @compact_namespace && name == GeneratorRuby.normalize_type_name(t.full_name) add_types(t) else RTypeHelper.new(t.name,t).result end end str end |
#cdelete_method ⇒ Object
293 294 295 |
# File 'lib/rbind/generator_ruby.rb', line 293 def cdelete_method GeneratorRuby.normalize_method_name(@root.cdelete_method) end |
#cname ⇒ Object
289 290 291 |
# File 'lib/rbind/generator_ruby.rb', line 289 def cname GeneratorRuby.normalize_type_name(@root.cname) end |
#full_name ⇒ Object
363 364 365 |
# File 'lib/rbind/generator_ruby.rb', line 363 def full_name @root.full_name end |
#name ⇒ Object
285 286 287 |
# File 'lib/rbind/generator_ruby.rb', line 285 def name GeneratorRuby.normalize_type_name(@name) end |
#result ⇒ Object
367 368 369 370 371 372 373 374 375 376 377 378 379 380 |
# File 'lib/rbind/generator_ruby.rb', line 367 def result return "" if @root.extern? str = if @root.is_a? RStruct @type_wrapper.result(self.binding) else @namespace_wrapper.result(self.binding) end if(@root.root?) str else str.gsub!("\n","\n ").gsub!(" \n","\n") " "+str[0,str.size-4] end end |