Sha256: 21c8f80ef53ea14911d32253aef3a9ae63340c9654b59bef118b7750c37aee61
Contents?: true
Size: 1.38 KB
Versions: 2
Compression:
Stored size: 1.38 KB
Contents
module RbPlusPlus module Builders # Handles code generation for telling Rice how to allocate / deallocate # classes. See ClassNode#check_allocation_strategies. class AllocationStrategyNode < Base def initialize(parent, code, has_public_constructor, has_public_destructor) super(code, parent) @public_constructor = has_public_constructor @public_destructor = has_public_destructor end # Used by MultipleFileWriter to only wrap a given type once. def qualified_name "#{self.code.qualified_name}_AllocStrat" end def build end def write includes << "#include <rice/Allocation_Strategies.hpp>" node_name = self.code.qualified_name code = <<-END namespace Rice { template<> struct Default_Allocation_Strategy< #{node_name} > { static #{node_name} * allocate(); static void free(#{node_name} * obj); }; } END declarations << code pre = "Rice::Default_Allocation_Strategy< #{node_name} >::" tmp = "#{node_name} * #{pre}allocate() { return " tmp += @public_constructor ? "new #{node_name};" : "NULL;" tmp += " }" registrations << tmp tmp = "void #{pre}free(#{node_name} * obj) { " tmp += @public_destructor ? "delete obj;" : "" tmp += " }" registrations << tmp end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rbplusplus-0.9.1 | lib/rbplusplus/builders/allocation_strategy.rb |
rbplusplus-0.9 | lib/rbplusplus/builders/allocation_strategy.rb |