Dot Notation

The "dot" operator has syntactic and didactic advantages and simplifies working with attributes.

It is used to call an expression (e.g.: a shape attribute or function) for another expression (e.g.: a shape or variable).

shape.color()

The expressions following (right side expression) the initial expression (left side expression) can be chained in an arbitrary depth.

The expression on the left side can be any expression, even a constant string, e.g:

"the string".length()

Therefore the left expression can also be a sub expression, like a.b.c or even the result of a function call like a().b().c() etc.

When using class instances from a function call that result in the left expression, keep in mind that we can not return references to classes with a return statement in a function and therefore the resulting object is a copy!

E.g. when having class instances inside a dyn, vector or mapping and you have an expression of dyn.last().action() then dyn.last() does not return a reference to the object but a copy.

However, when using an index operation on the dyn, then the result is the object directly without a copy being done. E.g. dyn[last].action() would directly act on the last object of the dyn.

There are exceptions to this:

When the array stores a datatype which has C++-like methods (e.g. string), then the internally implemented functions on that datatype can act directly on the array content.

E.g. dyn_string ds; ds.last().chop(2) directly modifies the string in the dyn_string (this can be accomplished since internally chop() knows that it needs a modifyable left expression and therefore gets this in an extra step, but this is not possible for functions written in CTRL. This exception is only relevant for dyn and vector, which use at(), first() or last() - these are the only internally implemented methods which can return a reference to the object in the array

Note: To directly act on objects stored in a container (e.g. dyn, vector, mapping) you can also use shared_ptr<TheClass> since a shared_ptr itself can be copied and will still point at the original object.