dot operator for typekits

Hi all,

I want to add some dot operators for the BFL typekit.
Everything compiles when I use dot operators without arguments but I cannot
use the dot operators in the task browser. The error I get is Fatal Semantic
error: Matrix does not have member "size".

RTT::types::OperatorRepository::shared_ptr oreg =
RTT::types::OperatorRepository::Instance();
oreg->add( newDotOperator( "size", get_size<const Matrix&>() ) );

template<class T>
struct get_size
: public std::unary_function<T, int>
{
int operator()(T cont ) const
{
return cont.size();
}
};

Using dot operators with arguments even does not compile :(

struct cv_resize
: public std::binary_function<ColumnVector,int, ColumnVector>
{
ColumnVector operator()(ColumnVector& cv, int size) const
{
cv.resize(size);
return cv;
}
};

oreg->add( RTT::types::newDotOperator( "resize", cv_resize() ) );

I heard a rumor that we are not supposed to use dot operators anymore but
rather use GetMember ... For obvious reasons the resize operator is not a
member at all.
Could you give me a clue how to implement the dot operators?

Tinne

dot operator for typekits

On Monday 17 January 2011 13:40:56 Tinne De Laet wrote:
> Hi all,
>
> I want to add some dot operators for the BFL typekit.
> Everything compiles when I use dot operators without arguments but I cannot
> use the dot operators in the task browser. The error I get is Fatal
> Semantic error: Matrix does not have member "size".
>
>
> RTT::types::OperatorRepository::shared_ptr oreg =
> RTT::types::OperatorRepository::Instance();
> oreg->add( newDotOperator( "size", get_size<const Matrix&>() ) );
>
> template<class T>
> struct get_size
>
> : public std::unary_function<T, int>
>
> {
> int operator()(T cont ) const
> {
> return cont.size();
> }
> };
>
> Using dot operators with arguments even does not compile :(
>
> struct cv_resize
>
> : public std::binary_function<ColumnVector,int, ColumnVector>
>
> {
> ColumnVector operator()(ColumnVector& cv, int size) const
> {
> cv.resize(size);
> return cv;
> }
> };
>
> oreg->add( RTT::types::newDotOperator( "resize", cv_resize() ) );
>
> I heard a rumor that we are not supposed to use dot operators anymore but
> rather use GetMember ... For obvious reasons the resize operator is not a
> member at all.
> Could you give me a clue how to implement the dot operators?

You found dead code in RTT :-(. All references to DotOperator should be
removed from the code, and I thought they were.

Data types can only have 'value fields', not 'functions' like in C++ objects.

The easiest solution is to register a function (operation) in the global
service. For example: resize_matrix(matrix& m, int rows, int cols):

#include <rtt/internal/GlobalService.hp

RTT::internal::GlobalService::Instance()->provides("bfl")-
>addOperation("resize_matrix",&resize_matrix).doc("...") ... etc...

You'll then be able to write in a script:

bfl.resize_matrix( bfl_matrix, rows, cols )

So we use 'bfl' as a scope to put your functions in.

I must admit that we're still gaining experience with this. An alternative to
the above is to specify a constructor in your typekit such that you can write:

var matrix m;

m = matrix(rows, cols) // overwrites and resizes 'm'

It depends on your usecase...

Peter

dot operator for typekits

On Monday 17 January 2011 14:04:29 Peter Soetens wrote:
> On Monday 17 January 2011 13:40:56 Tinne De Laet wrote:
> > Hi all,
> >
> > I want to add some dot operators for the BFL typekit.
> > Everything compiles when I use dot operators without arguments but I
> > cannot use the dot operators in the task browser. The error I get is
> > Fatal Semantic error: Matrix does not have member "size".
> >
> >
> > RTT::types::OperatorRepository::shared_ptr oreg =
> > RTT::types::OperatorRepository::Instance();
> > oreg->add( newDotOperator( "size", get_size<const Matrix&>() ) );
> >
> > template<class T>
> > struct get_size
> >
> > : public std::unary_function<T, int>
> >
> > {
> >
> > int operator()(T cont ) const
> > {
> >
> > return cont.size();
> >
> > }
> >
> > };
> >
> > Using dot operators with arguments even does not compile :(
> >
> > struct cv_resize
> >
> > : public std::binary_function<ColumnVector,int, ColumnVector>
> >
> > {
> >
> > ColumnVector operator()(ColumnVector& cv, int size) const
> > {
> >
> > cv.resize(size);
> > return cv;
> >
> > }
> >
> > };
> >
> > oreg->add( RTT::types::newDotOperator( "resize", cv_resize() ) );
> >
> > I heard a rumor that we are not supposed to use dot operators anymore but
> > rather use GetMember ... For obvious reasons the resize operator is not a
> > member at all.
> > Could you give me a clue how to implement the dot operators?
>
> You found dead code in RTT :-(. All references to DotOperator should be
> removed from the code, and I thought they were.
The dead code is easily found when doing a grep
grep -r "Dot" *
RealTimeTypekitOperators.cpp: oreg->add( newDotOperator( "size",
get_size<const std::string&>() ) );
RealTimeTypekitOperators.cpp: oreg->add( newDotOperator( "length",
get_size<const std::string&>() ) );
RealTimeTypekitOperators.cpp: oreg->add( newDotOperator( "capacity",
get_capacity<const std::string&>() ) );
RealTimeTypekitOperators.cpp: oreg->add( newDotOperator( "size",
get_size<const std::vector RealTimeTypekitOperators.cpp: oreg->add( newDotOperator( "capacity",
get_capacity<const std::vector

Can you explain me why the dotOperator has been removed?
>
> Data types can only have 'value fields', not 'functions' like in C++
> objects.
>
> The easiest solution is to register a function (operation) in the global
> service. For example: resize_matrix(matrix& m, int rows, int cols):
>
> #include <rtt/internal/GlobalService.hp

>
> RTT::internal::GlobalService::Instance()->provides("bfl")-
>
> >addOperation("resize_matrix",&resize_matrix).doc("...") ... etc...
>
> You'll then be able to write in a script:
>
> bfl.resize_matrix( bfl_matrix, rows, cols )
>
> So we use 'bfl' as a scope to put your functions in.

This would to the trick but I cannot deny I don't like the syntax.

>
> I must admit that we're still gaining experience with this. An alternative
> to the above is to specify a constructor in your typekit such that you can
> write:
>
> var matrix m;
>
> m = matrix(rows, cols) // overwrites and resizes 'm'

I alread have this, but the constructor and the resize function have different
behavior.

Tinne

dot operator for typekits

2011/1/17 Tinne De Laet <tinne [dot] delaet [..] ...>

> On Monday 17 January 2011 14:04:29 Peter Soetens wrote:
> > On Monday 17 January 2011 13:40:56 Tinne De Laet wrote:
> > > Hi all,
> > >
> > > I want to add some dot operators for the BFL typekit.
> > > Everything compiles when I use dot operators without arguments but I
> > > cannot use the dot operators in the task browser. The error I get is
> > > Fatal Semantic error: Matrix does not have member "size".
> > >
> > >
> > > RTT::types::OperatorRepository::shared_ptr oreg =
> > > RTT::types::OperatorRepository::Instance();
> > > oreg->add( newDotOperator( "size", get_size<const Matrix&>() ) );
> > >
> > > template<class T>
> > > struct get_size
> > >
> > > : public std::unary_function<T, int>
> > >
> > > {
> > >
> > > int operator()(T cont ) const
> > > {
> > >
> > > return cont.size();
> > >
> > > }
> > >
> > > };
> > >
> > > Using dot operators with arguments even does not compile :(
> > >
> > > struct cv_resize
> > >
> > > : public std::binary_function<ColumnVector,int, ColumnVector>
> > >
> > > {
> > >
> > > ColumnVector operator()(ColumnVector& cv, int size) const
> > > {
> > >
> > > cv.resize(size);
> > > return cv;
> > >
> > > }
> > >
> > > };
> > >
> > > oreg->add( RTT::types::newDotOperator( "resize", cv_resize() ) );
> > >
> > > I heard a rumor that we are not supposed to use dot operators anymore
> but
> > > rather use GetMember ... For obvious reasons the resize operator is
> not a
> > > member at all.
> > > Could you give me a clue how to implement the dot operators?
> >
> > You found dead code in RTT :-(. All references to DotOperator should be
> > removed from the code, and I thought they were.
> The dead code is easily found when doing a grep
> grep -r "Dot" *
> RealTimeTypekitOperators.cpp: oreg->add( newDotOperator( "size",
> get_size<const std::string&>() ) );
> RealTimeTypekitOperators.cpp: oreg->add( newDotOperator( "length",
> get_size<const std::string&>() ) );
> RealTimeTypekitOperators.cpp: oreg->add( newDotOperator( "capacity",
> get_capacity<const std::string&>() ) );
> RealTimeTypekitOperators.cpp: oreg->add( newDotOperator( "size",
> get_size<const std::vector > RealTimeTypekitOperators.cpp: oreg->add( newDotOperator( "capacity",
> get_capacity<const std::vector >
>
> Can you explain me why the dotOperator has been removed?
> >
> > Data types can only have 'value fields', not 'functions' like in C++
> > objects.
> >
> > The easiest solution is to register a function (operation) in the global
> > service. For example: resize_matrix(matrix& m, int rows, int cols):
> >
> > #include <rtt/internal/GlobalService.hp

> >
> > RTT::internal::GlobalService::Instance()->provides("bfl")-
> >
> > >addOperation("resize_matrix",&resize_matrix).doc("...") ... etc...
> >
> > You'll then be able to write in a script:
> >
> > bfl.resize_matrix( bfl_matrix, rows, cols )
> >
> > So we use 'bfl' as a scope to put your functions in.
>
> This would to the trick but I cannot deny I don't like the syntax.
>
> >
> > I must admit that we're still gaining experience with this. An
> alternative
> > to the above is to specify a constructor in your typekit such that you
> can
> > write:
> >
> > var matrix m;
> >
> > m = matrix(rows, cols) // overwrites and resizes 'm'
>
> I alread have this, but the constructor and the resize function have
> different
> behavior.
>
> Tinne
>
>

Let me bump this thread up, because some question were not answered. Could
someone update this ? (Ruben ? Peter ? )

I am writing a typekit manually (because for some reasons typegen can't
generate it), and I would like to access value field. I used to take
DotOperator in v1.X. It seems to have disappeared in v2.X. In fact it
happens that we don't need to do this anymore, it is automatically done
underneath (which is great, but I spend hours searching how to do something
that my Taskbrowser was capable and that I didn't even tried). I am not
sure it is very clear there :
http://www.orocos.org/stable/documentation/rtt/v2.x/doc-xml/orocos-typek...
that your data fields are automatically accessible in script and
Taskbrowser without any further coding.

> --
> Orocos-Users mailing list
> Orocos-Users [..] ...
> http://lists.mech.kuleuven.be/mailman/listinfo/orocos-users
>

Ruben Smits's picture

dot operator for typekits

On Monday 17 January 2011 14:04:29 Peter Soetens wrote:
> On Monday 17 January 2011 13:40:56 Tinne De Laet wrote:
> > Hi all,
> >
> > I want to add some dot operators for the BFL typekit.
> > Everything compiles when I use dot operators without arguments but I
> > cannot use the dot operators in the task browser. The error I get is
> > Fatal Semantic error: Matrix does not have member "size".
> >
> >
> > RTT::types::OperatorRepository::shared_ptr oreg =
> > RTT::types::OperatorRepository::Instance();
> > oreg->add( newDotOperator( "size", get_size<const Matrix&>() ) );
> >
> > template<class T>
> > struct get_size
> >
> > : public std::unary_function<T, int>
> >
> > {
> >
> > int operator()(T cont ) const
> > {
> >
> > return cont.size();
> >
> > }
> >
> > };
> >
> > Using dot operators with arguments even does not compile :(
> >
> > struct cv_resize
> >
> > : public std::binary_function<ColumnVector,int,
> > : ColumnVector>
> >
> > {
> >
> > ColumnVector operator()(ColumnVector& cv, int size)
> > const
> > {
> >
> > cv.resize(size);
> > return cv;
> >
> > }
> >
> > };
> >
> > oreg->add( RTT::types::newDotOperator( "resize", cv_resize() ) );
> >
> > I heard a rumor that we are not supposed to use dot operators anymore
> > but
> > rather use GetMember ... For obvious reasons the resize operator is not
> > a
> > member at all.
> > Could you give me a clue how to implement the dot operators?
>
> You found dead code in RTT :-(. All references to DotOperator should be
> removed from the code, and I thought they were.
>
> Data types can only have 'value fields', not 'functions' like in C++
> objects.

Why did all this functionality got removed? The KDL typekit uses a lot of
these dotOperators to use the basic KDL functions in scripting, this means a
lot of rewriting on the typekit code :(

Ruben

> The easiest solution is to register a function (operation) in the global
> service. For example: resize_matrix(matrix& m, int rows, int cols):
>
> #include <rtt/internal/GlobalService.hp

>
> RTT::internal::GlobalService::Instance()->provides("bfl")-
>
> >addOperation("resize_matrix",&resize_matrix).doc("...") ... etc...
>
> You'll then be able to write in a script:
>
> bfl.resize_matrix( bfl_matrix, rows, cols )
>
> So we use 'bfl' as a scope to put your functions in.
>
> I must admit that we're still gaining experience with this. An alternative
> to the above is to specify a constructor in your typekit such that you can
> write:
>
> var matrix m;
>
> m = matrix(rows, cols) // overwrites and resizes 'm'
>
> It depends on your usecase...
>
> Peter