Class: RbPlusPlus::Builders::AllocationStrategyNode

Inherits:
Base
  • Object
show all
Defined in:
lib/rbplusplus/builders/allocation_strategy.rb

Overview

Handles code generation for telling Rice how to allocate / deallocate classes. See ClassNode#check_allocation_strategies.

Instance Attribute Summary

Attributes inherited from Base

#code, #declarations, #global_nodes, #includes, #nodes, #parent, #registrations, #rice_variable, #rice_variable_type

Instance Method Summary collapse

Methods inherited from Base

#has_children?, #sort

Constructor Details

#initialize(parent, code, has_public_constructor, has_public_destructor) ⇒ AllocationStrategyNode

Returns a new instance of AllocationStrategyNode.



8
9
10
11
12
# File 'lib/rbplusplus/builders/allocation_strategy.rb', line 8

def initialize(parent, code, has_public_constructor, has_public_destructor)
  super(code, parent)
  @public_constructor = has_public_constructor
  @public_destructor = has_public_destructor
end

Instance Method Details

#buildObject



19
20
# File 'lib/rbplusplus/builders/allocation_strategy.rb', line 19

def build
end

#qualified_nameObject

Used by MultipleFileWriter to only wrap a given type once.



15
16
17
# File 'lib/rbplusplus/builders/allocation_strategy.rb', line 15

def qualified_name
  "#{self.code.qualified_name}_AllocStrat"
end

#writeObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rbplusplus/builders/allocation_strategy.rb', line 22

def write
  includes << "#include <rice/Data_Object.hpp>"

  node_name = self.code.qualified_name
  code = <<-END
namespace Rice {
  template<>
  struct Default_Free_Function< #{node_name} > {
    static void free(#{node_name} * obj);
  };
}
  END

  declarations << code

  pre = "Rice::Default_Free_Function< #{node_name} >::"

  tmp = "void #{pre}free(#{node_name} * obj) { "
  tmp += @public_destructor ? "delete obj;" : ""
  tmp += " }"

  registrations << tmp
end