Overview¶
Rice enable native C++ code and Ruby code to work together. This requires translating types between the two languages.
C++ Types¶
C++ defines fundamental and compound types. Fundamental types consist of void, integers, float, double, etc. Compound types are everything else such as enums, arrays, classes, pointers, references, etc.
Type Mapping¶
Objects can either be converted or wrapped. Converted objects are copied between the two languages. For example, a C++ integer is copied to a Ruby Integer resulting in two disconnected objects. If you update the value of the Ruby integer the change is not reflected in the C++ integer. For more information refer to the Type Conversion section.
Wrapped objects are C++ objects that are wrapped by Ruby objects, or alternatively, Ruby objects wrapped by C++ objects. Thus the two objects are connected. For example, if a C++ object is wrapped by a Ruby object then any modifications to the Ruby object will be reflected in the C++ object. For more information refer to the Type Wrapping section.
The table below shows how fundamental and compound C++ types are mapped to Ruby types based on whether they are passed by value, reference or pointer.
C++ Type |
Fundamental |
Compound |
---|---|---|
Value (T) |
Converted |
Wrapped |
Reference (T&) |
Converted |
Wrapped |
Pointer (T*) |
Pointer<T> |
Wrapped |
Array (T[]) |
Pointer<T> |
Pointer<T> |
Pointer (T**) |
Pointer<T*> |
Pointer<T*> |
The Pointer classes are automatically generated by Rice to wrap C++ arrays and pointers to fundamental types. Use Buffers to manipulate the pointer’s memory.