[Bug 640] New: providing RTT with type vector<ANYTYPE>

For more infomation about this bug, visit https://www.fmtc.be/bugzilla/orocos/show_bug.cgi?id=640
Summary: providing RTT with type vector<ANYTYPE>
Product: RTT
Version: rtt-trunk
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P3
Component: Properties & XML
AssignedTo: orocos-dev [..] ...
ReportedBy: tinne [dot] delaet [..] ...
CC: orocos-dev [..] ...
Estimated Hours: 0.0

Created an attachment (id=407)
--> (https://www.fmtc.be/bugzilla/orocos/attachment.cgi?id=407)
patch to add support for types vector<ANYTYPE>

Enhancement as discussed on the ML:
<quote>
Ruben and I extended the OCL vectorTemplateComposition (patch and original file
attached) such that support for the type vector<ANYTYPE> is provided. Anytype
can be a really anything. We thoroughly tested for double, int, bool, string,
and some home created types like ColumnVector, Matrix, ....

You can create your own vector<Type> as follows:

RTT::TypeInfoRepository::Instance()->addType( new
StdVectorTemplateTypeInfo<ColumnVector,true>("ColumnVectors") );
RTT::TypeInfoRepository::Instance()->type("ColumnVectors")->addConstructor(newConstructor(stdvector_ctor<ColumnVector>()
) );
RTT::TypeInfoRepository::Instance()->type("ColumnVectors")->addConstructor(newConstructor(stdvector_ctor2<ColumnVector>()
) );
RTT::TypeInfoRepository::Instance()->type("ColumnVectors")->addConstructor(new
StdVectorBuilder<ColumnVector>() );

where you replace ColumnVector with you own type.

We believe this can be usefull contribution for a lot of users. I even believe
it should be added to RTT in stead of OCL.

Tinne

<quote>

[Bug 640] providing RTT with type vector<ANYTYPE>

https://www.fmtc.be/bugzilla/orocos/show_bug.cgi?id=640

Tinne De Laet <tinne [dot] delaet [..] ...> changed:

What |Removed |Added
----------------------------------------------------------------------------
Resolution| |FIXED
Status|NEW |RESOLVED

--- Comment #7 from Tinne De Laet <tinne [dot] delaet [..] ...> 2009-10-02 14:35:00 ---
From: Peter Soetens <peter [..] ...>
------------------------------------------------------------------------
r30186 | psoetens | 2009-06-04 15:57:19 +0200 (Thu, 04 Jun 2009) | 6 lines

Fixes bug #640:providing RTT with type vector<ANYTYPE>

Ruben Smits's picture

[Bug 640] providing RTT with type vector<ANYTYPE>

https://www.fmtc.be/bugzilla/orocos/show_bug.cgi?id=640

Ruben Smits <ruben [dot] smits [..] ...> changed:

What |Removed |Added
----------------------------------------------------------------------------
CC| |ruben [dot] smits [..] ...en.b
| |e

--- Comment #6 from Ruben Smits <ruben [dot] smits [..] ...> 2009-08-20 08:30:56 ---
*** Bug 513 has been marked as a duplicate of this bug. ***

[Bug 640] providing RTT with type vector<ANYTYPE>

https://www.fmtc.be/bugzilla/orocos/show_bug.cgi?id=640

--- Comment #5 from Peter Soetens <peter [dot] soetens [..] ...> 2009-04-03 10:04:43 ---
(In reply to comment #4)
> Created an attachment (id=418)
--> (https://www.fmtc.be/bugzilla/orocos/attachment.cgi?id=418) [details]
> final proposal for vector<ANYTYPE> support
>
> Final proposal.

Reviewing the code, I still have an objection. Since all functions are in the
header and in the RTT namespace, I would propose to regroup and rename them in
namespaces like this:

Remain the same:
RTT::StdVectorTemplateTypeInfo
RTT::operator<<
RTT::operator>>
RTT::StdVectorBuilder
RTT::stdvector_ctor*

Moves and/or Renames into namespace detail {...}:
RTT::detail::composeStdVectorProperty()
RTT::detail::decomposeStdVectorProperty()
RTT::stdvector_get_size()

It wouldn't be bad to also provide a factory function for the operators and
constructors which are now a bit 'floating' in the file. For example:

namespace RTT {
 
/**
 * Add mandatory doc here...
 */
template<class T>
TypeInfo* createStdVectorType(string name) {
    types()->addType( new StdVectorTemplateTypeInfo<T,true>(name) );
    return types()->getType(name);
}
 
/**
 * Add mandatory doc here...
 */
template<class T>
void RTT::createStdVectorConstructors(TypeInfo* type) {
 // the newConstructor code
}
 
/**
 * Add mandatory doc here...
 */
template<class T>
void RTT::createStdVectorOperators(TypeInfo* type) {
 // the dot operators etc
}
 
}

That would even allow you to move the stdvector_* helper functions into the
detail:: namespace as well.

Peter

[Bug 640] providing RTT with type vector<ANYTYPE>

https://www.fmtc.be/bugzilla/orocos/show_bug.cgi?id=640

Tinne De Laet <tinne [dot] delaet [..] ...> changed:

What |Removed |Added
----------------------------------------------------------------------------
Attachment #413 is|0 |1
obsolete| |
Attachment #407 is|0 |1
obsolete| |

--- Comment #4 from Tinne De Laet <tinne [dot] delaet [..] ...> 2009-04-02 13:17:11 ---
Created an attachment (id=418)
--> (https://www.fmtc.be/bugzilla/orocos/attachment.cgi?id=418)
final proposal for vector<ANYTYPE> support

Final proposal.

[Bug 640] providing RTT with type vector<ANYTYPE>

For more infomation about this bug, visit https://www.fmtc.be/bugzilla/orocos/show_bug.cgi?id=640

--- Comment #3 from Tinne De Laet <tinne [dot] delaet [..] ...> 2009-03-27 10:41:32 ---
Created an attachment (id=413)
--> (https://www.fmtc.be/bugzilla/orocos/attachment.cgi?id=413)
patch in which problem with writing to xml fixed

Problem of writing to xml file fixed!! (thanks Ruben and Peter)
I believe the file is ready for inclusion in RTT.

Tinne

[Bug 640] providing RTT with type vector<ANYTYPE>

For more infomation about this bug, visit https://www.fmtc.be/bugzilla/orocos/show_bug.cgi?id=640

Peter Soetens <peter [dot] soetens [..] ...> changed:

What |Removed |Added
----------------------------------------------------------------------------
CC| |peter [dot] soetens [..] ...

--- Comment #2 from Peter Soetens <peter [dot] soetens [..] ...> 2009-03-26 16:54:14 ---
(In reply to comment #1)
> There is still a problem when decomposing vector<ANYTYPE> (for reporting to a
> file).
>
> The decompose function looks like this:
> template<class T>
> void decomposeProperty(const std::vector<T>& vec, PropertyBag& targetbag)
> {
> std::string tname = detail::DataSourceTypeInfo<T>::getType();
> targetbag.setType(tname+"s");
> int dimension = vec.size();
> std::string str;
>
> assert( targetbag.empty() );
>
> for ( int i=0; i < dimension ; i++){
> std::stringstream out;
> out << i+1;
> str = out.str();
> targetbag.add( new Property<T>("Element" + str, str +"th element of
> list",vec[i]) );
> }
> };
>
> The problem is when ANYTYPE is not a standard type like bool, double, int, ...
> but a type that has to be decomposed itself.
> When using this decompose function for reporting the ANYTYPE is not decomposed
> but the << operator is used to write it to the propertyfile.
>
> Therefor I would like to change the following line
> targetbag.add( new Property<T>("Element" + str, str +"th element of
> list",vec[i]) );
> to something like, when the ANYTYPE still has to be decomposed.
> decomposeProperty(vec[i],targetbag);
>
> Problem: I have to check if ANYTYPE(or T) is still a container, i.e. is still
> decomposable but I don't know how to check this :(
> Any hints, help, ... is welcome!

You can use decomposeType() by default and if that returns false, add it to the
target bag.

ReferenceDataSource<T> rds( vec[i] );
PropertyBag tmp_bag;
if (detail::DataSourceTypeInfo<T>::getTypeInfo()->decomposeType( &rds, tmp_bag
) )
targetbag.add( new Property<PropertyBag>("Element" + str, str +"th element
of list",tmp_bag) );
else
targetbag.add( new Property<T>("Element" + str, str +"th element of
list",vec[i]) );

That should be very close to your solution, didn't compile/test this though.

Peter

[Bug 640] providing RTT with type vector<ANYTYPE>

For more infomation about this bug, visit https://www.fmtc.be/bugzilla/orocos/show_bug.cgi?id=640

--- Comment #1 from Tinne De Laet <tinne [dot] delaet [..] ...> 2009-03-25 17:21:24 ---
There is still a problem when decomposing vector<ANYTYPE> (for reporting to a
file).

The decompose function looks like this:
template<class T>
void decomposeProperty(const std::vector<T>& vec, PropertyBag& targetbag)
{
std::string tname = detail::DataSourceTypeInfo<T>::getType();
targetbag.setType(tname+"s");
int dimension = vec.size();
std::string str;

assert( targetbag.empty() );

for ( int i=0; i < dimension ; i++){
std::stringstream out;
out << i+1;
str = out.str();
targetbag.add( new Property<T>("Element" + str, str +"th element of
list",vec[i]) );
}
};

The problem is when ANYTYPE is not a standard type like bool, double, int, ...
but a type that has to be decomposed itself.
When using this decompose function for reporting the ANYTYPE is not decomposed
but the << operator is used to write it to the propertyfile.

Therefor I would like to change the following line
targetbag.add( new Property<T>("Element" + str, str +"th element of
list",vec[i]) );
to something like, when the ANYTYPE still has to be decomposed.
decomposeProperty(vec[i],targetbag);

Problem: I have to check if ANYTYPE(or T) is still a container, i.e. is still
decomposable but I don't know how to check this :(
Any hints, help, ... is welcome!

Tinne