class RbPlusPlus::Builders::ClassNode

Handles the generation of Rice code to wrap classes

Public Instance Methods

build() click to toggle source
# File lib/rbplusplus/builders/class.rb, line 13
def build
  add_child IncludeNode.new(self, "rice/Class.hpp", :system)
  add_child IncludeNode.new(self, "rice/Data_Type.hpp", :system)
  add_child IncludeNode.new(self, code.file)

  typedef = find_typedef

  @short_name, @qualified_name = typedef ? [typedef.name, typedef.qualified_name] : [code.name, code.qualified_name]

  Logger.info "Wrapping class #{@qualified_name}"

  @class_base_type = @qualified_name

  supers = self.code.superclasses(:public)
  @superclass = supers[0]

  if supers.length > 1
    if (@superclass = self.code._get_superclass).nil?
      @superclass = supers[0]
      Logger.warn :mutiple_superclasses, "#{@qualified_name} has multiple public superclasses. " +
        "Will use first superclass, which is #{@superclass.qualified_name} "
        "Please use #use_superclass to specify another superclass as needed."
    end
  end

  @director = nil
  if self.code.needs_director?
    @director = DirectorNode.new(self.code, self, @qualified_name, @superclass)
    add_child @director
  end

  self.rice_variable = "rb_c#{@short_name.as_variable}"
  self.rice_variable_type = "Rice::Data_Type< #{@qualified_name} >"

  with_enumerations
  with_classes
  with_constructors
  with_constants
  with_variables
  with_methods

  unless @director
    check_allocation_strategies
  end
end
qualified_name() click to toggle source
# File lib/rbplusplus/builders/class.rb, line 9
def qualified_name
  @qualified_name || self.code.qualified_name
end
write() click to toggle source
# File lib/rbplusplus/builders/class.rb, line 59
def write
  prefix = "#{rice_variable_type} #{rice_variable} = "
  ruby_name = @short_name
  superclass = @superclass.qualified_name if @superclass && !do_not_wrap?(@superclass)

  class_names = [@qualified_name]
  class_names << superclass if superclass
  class_names = class_names.join(",")

  if parent.rice_variable
    registrations << "\t#{prefix} Rice::define_class_under< #{class_names} >" +
                       "(#{parent.rice_variable}, \"#{ruby_name}\");"
  else
    registrations << "\t#{prefix} Rice::define_class< #{class_names} >(\"#{ruby_name}\");"
  end

  handle_custom_code
end