I have a use case where I have a Matlab class that I want to be part of the interface when generating c++ code. The class holds some double values.
When these values are being set by the user, the value have to be checked to be inside some boundaries. When constructing an object the values have to be set to useful default values.
This is my example class:
properties ( Access = private )
Value = 0;
function obj = MyClass( val )
obj = obj.set_value( val );
function obj = set_value( obj, val )
if val < 0
val = 0;
obj.Value = val;
function val = get_value( obj )
val = obj.Value;
The property is private with a valid default value and I have a setter with bound checking and a getter.
The constructor explicitly calls the setter.
The generated C++ code looks like this:
double get_value() const;
void init(double b_Value);
double MyClass::get_value() const
void MyClass::init(double b_Value)
this->Value = b_Value;
The default value is lost, the setter does not even get defined, the bound checking is not happening.
Coder always generates an init method that sets the property directly.
How can I have the coder generate c++ code that does not allow the user of the class to misuse it?