Hello devs.
I try to re-use some code of the OCL reporting component. Somewhere there is cloning (ReportingComponent::reportDataSource line 377) and i wonder how i should do in my own code ?
Her is my code :
double val; RTT::base::DataSourceBase::shared_ptr orig; RTT::base::DataSourceBase::shared_ptr clone; RTT::base::ActionInterface * update; orig = new RTT::internal::ValueDataSource<double>(val); clone = orig->getTypeInfo()->buildValue(); // seems to call TemplateTypeInfo.hpp line 216 : buildValue that call internal::ValueDataSource<>() // is it equivalent to call clone ? // clone = orig->clone(); // seem to call DataSources.inl line 34 : clone() that call new ValueDataSource<>() update = clone->updateAction(orig.get());
Thank you for your help.
Different way of cloning, wich is the recommended one ?
On Monday 21 February 2011 10:29:28 paul [dot] chavent [..] ... wrote:
> Hello devs.
>
> I try to re-use some code of the OCL reporting component. Somewhere there
> is cloning (ReportingComponent::reportDataSource line 377) and i wonder
> how i should do in my own code ?
>
> Her is my code :
>
>
>
If you want to clone a value data source, don't use buildValue(), which
creates a new one, but use clone() instead. When using buildValue(), the data
source will be initialized to the default, while clone() will initialize it
with the value of 'orig'. In both cases, a new object is created.
> Thank you for your help.
Peter
Re: Different way of cloning, wich is the recommended one ?
Thank you for your reply.
In the ReportingComponent of OCL, the source uses buildValue. So it seems to not be a problem as the clone is initialized with the update action.
I have rewriten my own Reporting. I share with you the code if you are interested. It's not usable as is but it is essentially to suggest an OCL implementation refactoring. If you are interested in the whole code, i can send it.