Attributes¶
-
enum
Header
¶ This enum is used by several of the other attributes to specify includes in the generated code.
-
enum
ParameterStyle
¶ This enum specifies the way in which an external type is passed in a call to an external function.
-
case
ConstReference
¶ The parameter should be of type
const T&
.
-
case
Pointer
¶ The parameter should be of type
T*
.
-
case
RValueReference
¶ The parameter should be of type
T&&
.
-
case
Value
¶ The parameter should be of type
T
.
-
case
-
attribute
@mapToMember
(name : String)¶ Applies to: External functions with at least one argument This attribute specifies that a function should be mapped to a member function of the first argument instead of to a top-level function. For example, given:
@CPP.mapToMember("f") external function f(x : T, y : Bool) : Nil = {}
then an expression like
f(a, b)
will be mapped toa.f(b)
in the generated C++ code.
-
attribute
@mapToType
(name : String, parameterStyle : ParameterStyle, header : List<Header>)¶ Applies to: External types This attribute specifies how an external type should be mapped into the generated C++. The following example defines how the external datatype
ChronoDuration
is mapped tostd::chrono::duration
in the generated C++ code:
-
attribute
@mapToValue
(name : String, header : List<Header>)¶ Applies to: External functions This attribute specifies how external functions are to be mapped into the generated C++. The following example defines how a reference to the standard library
std::this_thread::sleep_for
function can be accessed:
Advanced Attributes¶
-
attribute
@binaryOperator
(operator : BinaryOperator)¶ Used to specify that the given Coco function, which must be a function with exactly two arguments, should be mapped to the given operator in C++.
-
attribute
@include
(header : List<Header>)¶ When applied to a Coco declaration, will cause any usage of this declaration to contain the given includes. For example:
will include
#include "hdr"
in the generated C++ file that includesP
.
-
attribute
@implicitCast
¶ Applies to: External functions with exactly one argument This attribute can be used to specify that an external function represents an implicit cast in C++ and therefored does not need to be represented in the generated code. For example, given:
@CPP.implicitCast external function f(x : Int) : IntLike = _
f(y)
will appear in the generated code asy
.
-
attribute
@unaryOperator
(operator : UnaryOperator)¶ Used to specify that the given Coco function, which must be a function with exactly one argument, should be mapped to the given operator in C++.