References
References to objects are helpful to avoid expensive copies, which makes your feature code more efficient. Basically, you can think of a reference to be a new name that you give to an existing object, which you can then use to “talk“ to that object. References are created using the creator syntax and replacing the creator command’s name with the type name. Here is an example:
// create a line with the name “l“
line l([0,1,2],[3,4,5])
// the following does not create a new line that is a copy of l,
// it creates a reference to the original FLine object!
FLine ref(l)
// print the x-coordinate of the starting point
// of l into the console, which is "0"
echo(“start x = “ + ref.getStart().getX())
// change the start position through the reference
ref.setStart([8, 7, 6])
// write again a message, using the original line
// and now it will show a "8"
echo(“start x = “ + l.getStart().getX())
References are especially useful when accessing an object that is stored inside an object list. You can iterate through the list and perform operations directly on those objects that are stored in the list, and not on temporary copies of those objects. The object list returns an object of type FObject (the parent type of all objects in CAESES), so anything can be in there, such as lines, points, parameters etc. If we assume the object list contains lines, we need to cast the object in order to receive the correct reference:
// create a reference to the sixth object of the list
FLine ref(list.at(5).castTo(FLine))
// do something with ref,
// note again that this can change the original object
It is not possible to create references to objects of basic types. Remember, basic types are e.g. FDouble, FUnsigned, FVector3, FString, ...