Class: RbPlusPlus::Builders::AllocationStrategyNode
- 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
- #build ⇒ Object
-
#initialize(parent, code, has_public_constructor, has_public_destructor) ⇒ AllocationStrategyNode
constructor
A new instance of AllocationStrategyNode.
-
#qualified_name ⇒ Object
Used by MultipleFileWriter to only wrap a given type once.
- #write ⇒ Object
Methods inherited from Base
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
#build ⇒ Object
19 20 |
# File 'lib/rbplusplus/builders/allocation_strategy.rb', line 19 def build end |
#qualified_name ⇒ Object
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 |
#write ⇒ Object
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 |