constructing template properties, e.g. std::vector<T>

Hi,

I try to construct template properties which are of type std::vector.
In the RealTimeToolkit only the std::vector is available.
Therefor, I tried to extend my home-made toolkit with the following code:

template
struct StdVectorTemplateTypeInfo
: public TemplateContainerTypeInfo, int, double,
ArrayIndexChecker >, SizeAssignChecker {
StdVectorTypeInfo( std::string name )
: TemplateContainerTypeInfo, int, double,
ArrayIndexChecker >, SizeAssignChecker
{}

bool decomposeTypeImpl(const std::vector& vec, PropertyBag&
targetbag) const
{
decomposeProperty( vec, targetbag );
return true;
}

bool composeTypeImpl(const PropertyBag& bag, std::vector& result)
const
{
return composeProperty( bag, result );
}
};

and ofcourse I added the property to the defined types:
ti->addType( new StdVectorTemplateTypeInfo("vector") );

Add compile-time I get the following error:
/src/orocos-apps/applications/marshalling/src/localProperties.hpp:28: error:
ISO C++ forbids declaration of ‘StdVectorTypeInfo’ with no type
/src/orocos-apps/applications/marshalling/src/localProperties.hpp: In member
function ‘int
RTT::StdVectorTemplateTypeInfo::StdVectorTypeInfo(std::string)’:
/src/orocos-apps/applications/marshalling/src/localProperties.hpp:29: error:
only constructors take base initialisers
/src/orocos-apps/applications/marshalling/src/localProperties.hpp:30: warning:
no return statement in function returning non-void
make[2]: *** [src/CMakeFiles/propertyBib.dir/localProperties.o] Error 1
make[1]: *** [src/CMakeFiles/propertyBib.dir/all] Error 2
make: *** [all] Error 2

Any ideas what I am doing wrong or how I could create template properties
without implementing them again for all possible templates?

Tinne

constructing template properties, e.g. std::vector<T>

> Hi,
>
> I try to construct template properties which are of type std::vector.
> In the RealTimeToolkit only the std::vector is available.
> Therefor, I tried to extend my home-made toolkit with the following code:
>
> template
> struct StdVectorTemplateTypeInfo
> : public TemplateContainerTypeInfo, int, double,
> ArrayIndexChecker >, SizeAssignChecker > {
> StdVectorTypeInfo( std::string name )
> : TemplateContainerTypeInfo, int, double,
> ArrayIndexChecker >, SizeAssignChecker
> {}
>
> bool decomposeTypeImpl(const std::vector& vec, PropertyBag&
> targetbag) const
> {
> decomposeProperty( vec, targetbag );
> return true;
> }
>
> bool composeTypeImpl(const PropertyBag& bag, std::vector&
> result)
> const
> {
> return composeProperty( bag, result );
> }
> };
>
> and ofcourse I added the property to the defined types:
> ti->addType( new StdVectorTemplateTypeInfo("vector") );

This is illegal C++ syntax. Since StdVectorTemplateTypeInfo is a templated
class, you need to provide the template parameter always when using this
class name. For example:

#include
//...

ti->addType( new StdVectorTemplateTypeInfo("gvector") );

Or whatever type you want to store. In the scripting language, you can
then use gvector for using std::vector data objects. Repeat
for every meaningful type. If this is different for specific applications,
your application code will need to add this statement. The
TypeInfoRepository is a singleton which you can always access by using:

TypeInfoRepository::Instance()->addType( ... );

Hope this helps,
Peter

constructing template properties, e.g. std::vector<T>

On Thursday 13 December 2007 15:35:13 Peter Soetens wrote:
> > Hi,
> >
> > I try to construct template properties which are of type std::vector.
> > In the RealTimeToolkit only the std::vector is available.
> > Therefor, I tried to extend my home-made toolkit with the following code:

>
> This is illegal C++ syntax. Since StdVectorTemplateTypeInfo is a templated
> class, you need to provide the template parameter always when using this
> class name. For example:
>
> #include
> //...
>
> ti->addType( new StdVectorTemplateTypeInfo("gvector") );
>
> Or whatever type you want to store. In the scripting language, you can
> then use gvector for using std::vector data objects. Repeat
> for every meaningful type. If this is different for specific applications,
> your application code will need to add this statement. The
> TypeInfoRepository is a singleton which you can always access by using:
>
> TypeInfoRepository::Instance()->addType( ... );
>
Hi,

First of all thanks for the previous comment Peter, it already was a great
help.
Unfortunately I still haven't succeeded in getting what I want :(.
Now I have the following linking error when compiling:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
CMakeFiles/main.dir/toolkit.o: In function
`RTT::StdVectorTemplateTypeInfo::composeTypeImpl(RTT::PropertyBag
const&, std::vector >&) const':
toolkit.cpp:
(.text._ZNK3RTT25StdVectorTemplateTypeInfoI6PersonE15composeTypeImplERKNS_11PropertyBagERSt6vectorIS1_SaIS1_EE[RTT::StdVectorTemplateTypeInfo::composeTypeImpl(RTT::PropertyBag
const&, std::vector >&) const]+0x14):
undefined reference to `bool RTT::composeProperty(RTT::PropertyBag
const&, std::vector >&)'
CMakeFiles/main.dir/toolkit.o: In function
`RTT::StdVectorTemplateTypeInfo::decomposeTypeImpl(std::vector std::allocator > const&, RTT::PropertyBag&) const':
toolkit.cpp:
(.text._ZNK3RTT25StdVectorTemplateTypeInfoI6PersonE17decomposeTypeImplERKSt6vectorIS1_SaIS1_EERNS_11PropertyBagE[RTT::StdVectorTemplateTypeInfo::decomposeTypeImpl(std::vector std::allocator > const&, RTT::PropertyBag&) const]+0x14): undefined
reference to `void RTT::decomposeProperty(std::vector std::allocator > const&, RTT::PropertyBag&)'
CMakeFiles/main.dir/toolkit.o: In function
`RTT::StdVectorTemplateTypeInfo::composeTypeImpl(RTT::PropertyBag
const&, std::vector >&) const':
toolkit.cpp:
(.text._ZNK3RTT25StdVectorTemplateTypeInfoI8BirthdayE15composeTypeImplERKNS_11PropertyBagERSt6vectorIS1_SaIS1_EE[RTT::StdVectorTemplateTypeInfo::composeTypeImpl(RTT::PropertyBag
const&, std::vector >&) const]+0x14):
undefined reference to `bool RTT::composeProperty(RTT::PropertyBag
const&, std::vector >&)'
CMakeFiles/main.dir/toolkit.o: In function
`RTT::StdVectorTemplateTypeInfo::decomposeTypeImpl(std::vector std::allocator > const&, RTT::PropertyBag&) const':
toolkit.cpp:
(.text._ZNK3RTT25StdVectorTemplateTypeInfoI8BirthdayE17decomposeTypeImplERKSt6vectorIS1_SaIS1_EERNS_11PropertyBagE[RTT::StdVectorTemplateTypeInfo::decomposeTypeImpl(std::vector std::allocator > const&, RTT::PropertyBag&) const]+0x14): undefined
reference to `void RTT::decomposeProperty(std::vector std::allocator > const&, RTT::PropertyBag&)'
collect2: ld returned 1 exit status
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

It seems that the program does not succeed in finding the composeProperty,
which I implemented as a template function outside a class as you can see in
the attached file VectorTemplateComposition.cpp. (I also attached the tar.gz
of my entire test application if you think the mistake is somewhere else).

Hope that someone has a clue,

Tinne

Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

constructing template properties, e.g. std::vector<T>

On Friday 14 December 2007 10:27:03 Tinne De Laet wrote:
>
> First of all thanks for the previous comment Peter, it already was a great
> help.
> Unfortunately I still haven't succeeded in getting what I want :(.
> Now I have the following linking error when compiling:
>

If a function or class has a template parameter, you must include the
implementation (.cpp file) as well when you include the header. Thus in

localProperties.hpp, write

#include "VectorTemplateComposition.hpp"
#include "VectorTemplateComposition.cpp"

Or change VectorTemplateComposition.hpp to include
VectorTemplateComposition.cpp always.

Also do not compile VectorTemplateComposition.cpp , no object code will be
generated from it as it only contains template classes.

Peter

constructing template properties, e.g. std::vector<T>

On Monday 17 December 2007 17:08:21 Peter Soetens wrote:
> On Friday 14 December 2007 10:27:03 Tinne De Laet wrote:
> > First of all thanks for the previous comment Peter, it already was a
> > great help.
> > Unfortunately I still haven't succeeded in getting what I want :(.
> > Now I have the following linking error when compiling:
>
>
> If a function or class has a template parameter, you must include the
> implementation (.cpp file) as well when you include the header. Thus in
>
> localProperties.hpp, write
>
> #include "VectorTemplateComposition.hpp"
> #include "VectorTemplateComposition.cpp"
>
> Or change VectorTemplateComposition.hpp to include
> VectorTemplateComposition.cpp always.
>
> Also do not compile VectorTemplateComposition.cpp , no object code will be
> generated from it as it only contains template classes.

woeps,
that was indeed the mistake.
Maybe the template code could be integrated in rtt? (I can provide you an
updated version - or a patch ofcourse)

Tinne

constructing template properties, e.g. std::vector<T>

On Tuesday 18 December 2007 09:27:11 Tinne De Laet wrote:
> On Monday 17 December 2007 17:08:21 Peter Soetens wrote:
> > On Friday 14 December 2007 10:27:03 Tinne De Laet wrote:
> >
> >
> > If a function or class has a template parameter, you must include the
> > implementation (.cpp file) as well when you include the header. Thus in
> >
> > localProperties.hpp, write
> >
> > #include "VectorTemplateComposition.hpp"
> > #include "VectorTemplateComposition.cpp"
> >
> > Or change VectorTemplateComposition.hpp to include
> > VectorTemplateComposition.cpp always.
> >
> > Also do not compile VectorTemplateComposition.cpp , no object code will
> > be generated from it as it only contains template classes.
>
> woeps,
> that was indeed the mistake.
> Maybe the template code could be integrated in rtt? (I can provide you an
> updated version - or a patch ofcourse)

I don't see any harm in providing tools for future toolkit builders. I'm just
not sure where it would belong in the RTT, as it would possibly go lost very
quickly. Maybe it is better to add it as a code example to the
toolkit/plugins manual ?

Peter