Open francesco-romano opened 10 years ago
+100
Thanks Francesco for thinking about this. I think it is in a good direction.
For object allocation. Another possibility could be to let the user allocate memory and then link them with specific methods. E.g.
Thirft could generate:
void setMyVariable(Eigen::VectorXd myVariable);
and
void bindMyVariable(Eigen::VectorXd *myVariable);
The user would then allocate
Eigen::VectorXd myVariable;
and bind it with the proxy that handles the rpc:
void proxy.bindMyVariable(&myVariable);
But we still have to decided if we want thirft to pass default initializers to objects, in this case allocation would have to be inside the proxy.
During the last weeks I have been thinking about the new implementation of the parameters setting and getting through RPC. In my opinion the most flexible way (and also safest) is through the definition of real setters and getters instead of accessing directly the memory of an object. Unfortunately C++ does not offer native support to dynamic object creations...but here is where thrift comes into play. I am thinking of something similar to Objective C 2.0
properties
. We can define in thrift a new ''command''property
which takes the type of variable and some attributes and it generates automatically setters and getters. This methods are (public) virtual thus allowing overriding by the derived classes in case the user wants to implement a more sophisticated behaviour.So this is just a sketch... I use a vector as an example even if there are some issues still open.
It generates a couple of accessor methods:
And a variable named
a_myVariable
(a_ stands for automatic.. just an idea)We can use the attributes to customize the generation of the methods. I thought about the following attributes:
name
: allows customization of the automatically created variableAbout the issue I was mentioning before: object construction. If (and I would like to do this) we add automatically creation of instance variables we should also call a constructor for them. Which constructor we should call? (for example
Eigen::VectorXd
has an empty constructor, but to be completely automatic we should call its constructor with the size of the vector specified).@traversaro @lornat75