class RbGCCXML::Class

Public Class Methods

new(*args) click to toggle source
# File lib/rbplusplus/transformers/class.rb, line 4
def initialize(*args)
  super

  @included_classes = []
  @included_methods = []

  @declarations = []
  @wrappings = []
end

Public Instance Methods

add_custom_code(declaration, wrapping) click to toggle source

Sometimes, type manipulation, moving nodes around, or flat ignoring nodes just doesn’t do the trick and you need to write your own custom wrapper code. This method is for that. There are two parts to custom code: the declaration and the wrapping.

The Declaration:

This is the actual custom code you write. It may need to take
a pointer to the class type as the first parameter
and follow with that any parameters you want.

The Wrapping

The wrapping is the custom (usually one-line) bit of Rice code that
hooks up your declaration with the class in question. To ensure that
you doesn't need to know the variable of the ruby class object,
use <class> and rb++ will replace it as needed.

Example (taken from Ogre.rb’s wrapping of Ogre)

decl = "int RenderTarget_getCustomAttributeInt(Ogre::RenderTarget* self, const std::string& name) {
  int value(0);
  self->getCustomAttribute(name, &value);
  return value;
}
"
wrapping = "<class>.define_method(\"get_custom_attribute_int\", &RenderTarget_getCustomAttributeInt);"

ogre.classes("RenderTarget").add_custom_code(decl, wrapping)

This method works as an aggregator, so feel free to use it any number of times for a class, it won’t clobber any previous uses.

# File lib/rbplusplus/transformers/class.rb, line 111
def add_custom_code(declaration, wrapping)
  @declarations << declaration
  @wrappings << wrapping
end
director() click to toggle source

Until all the kinks of the director code generation can be worked out, rb++ must be told which classes to build directors for. Simply call this method on the class to do so

# File lib/rbplusplus/transformers/class.rb, line 134
def director
  @build_director = true
end
implicit_casting(state) click to toggle source

See RbGCCXML::Constructor::implicit_casting

# File lib/rbplusplus/transformers/class.rb, line 139
def implicit_casting(state)
  self.constructors.each {|c| c.implicit_casting(state) }
end
includes(val) click to toggle source

Class can include nested classes and nested structs.

Class can also include external methods/functions as class level methods also supports instance level methods

ex.

math_class.includes node.namespaces("Math").functions("mod")

or for a instance method:

math_class.includes node.namespaces("Math").functions("mod").as_instance_method

or for nesting a class/struct:

math_class.includes node.namespaces("Math").classes("Degree")
# File lib/rbplusplus/transformers/class.rb, line 31
def includes(val)
  if (val.is_a?(RbGCCXML::Struct) || val.is_a?(RbGCCXML::Class))
    @included_classes << val
  else
    @included_methods << val
  end
  val.moved_to = self
end
use_constructor(node) click to toggle source

Like use_superclass, this method allows the user to specify which constructor Rice should expose to Ruby. Rice currently, because of the lack of method overloading, only supports one constructor definition. Having multiple in the code will work, but only the last defined will actually work.

# File lib/rbplusplus/transformers/class.rb, line 71
def use_constructor(node)
  @use_constructor = node
end
use_superclass(klass) click to toggle source

Specify which superclass to use. Because Rice doesn’t support multiple inheritance right now, we need to know which superclass Rice should use for this class. An error message will show on classes with mutiple superclasses where this method hasn’t been used yet.

klass should be the node for the class you want to wrap

# File lib/rbplusplus/transformers/class.rb, line 57
def use_superclass(klass)
  @use_superclass = klass
end