Bindgen::Cpp::Pass
Inherits Bindgen::TypeHelper < Struct < Value < Object
Methods for passing data from and to C++.
This is a helper struct: Cheap to create and to pass around.
Constructors
Instance methods
Builds the out argument arg of a C++ wrapper function, see
TypeDatabase#converted_out_argument?. The function takes a pointer to
the binding structure, like CrystalString *, converts it into a local
of the C++ type, passes that to the method, and converts the local back
through the pointer afterwards. The local is moved into the from_cpp
conversion, so a conversion keeping a temporary's data, like the
std::string one, copies it. A pointer argument is out-only: the local
starts out value-initialized.
Turns the list of arguments into a list of Call::Arguments. A
non-const reference or pointer to a converted type becomes a
Call::OutArgument, see #out_argument_to_cpp.
Computes a result which is directly usable from C++ code, without changes, and passes it through to crystal using conversion.
The pass rules are similar to #to_crystal. The primary
difference is that this version has no special handling of constructors.
There is a second major difference: This method always signals the C++
type to the outside, as received by C++ (Thus even ignoring
rules.cpp_type!). It still follows the passing rules towards Crystal.
Builds the out argument arg of a C++ wrapper function, see
TypeDatabase#converted_out_argument?. The function takes a pointer to
the binding structure, like CrystalString *, converts it into a local
of the C++ type, passes that to the method, and converts the local back
through the pointer afterwards. The local is moved into the from_cpp
conversion, so a conversion keeping a temporary's data, like the
std::string one, copies it. A pointer argument is out-only: the local
starts out value-initialized.
Computes a result for passing type from Crystal to C++.
The primary job of this method is to figure out how to pass something of type over to C++. It doesn't matter if this is a result from a method or an argument for this. It also signals how a value of this type shall be handled by the receiver, e.g., if conversions apply (Which?).
The method responsible for the opposite direction is #to_crystal.
Pass rules:
- The type is a value-type and passed by-value a. The type is copied? Then pass by-value. b. Else, pass by-reference.
- The type is passed by-reference a. Pass by-reference
- The type is passed by-pointer a. Pass by-pointer
Also see #pass_to_cpp for the reverse direction.
See #passthrough_to_crystal to call Crystal from C++.
Set is_constructor to true if this is a return-result of a method
and this method is a constructor.
Pass rules:
- If is_constructor and the type is copied
a. Then pass by-value. (See
MethodName#generatetoo) - If pass by-reference a. Invoke the types copy-constructor and pass by-pointer.
- If pass by-value but the type is not copied a. Invoke the types copy-constructor and pass by-pointer.
- In all other cases a. Pass by-reference or by-pointer as defined by type.