Use of Special Data ina scripting file

Hello everyone

In my company, we have developped a new type of data. This data is a template. We use this data with Orocos script. So we add this template on Orocos Struct .We also add unary and binary operator to use the severals methods of this kind of data with the dot operator. The problem is that i can only use the dot operator to read. In a scripting file, i want to modify the value of may date (i don't want to modify the others member's variables of this data). To resolve this, i decide to overload the operator "=" for my data. The overload is OK in a C++ file, but it doesn't work in a scripting file. It seems that in a scripting file, it is the constructor with value that is used when i try to modify the value of my data (and of course, the others member's variables of the data are modified) How can i solve this problem ?

Heres is an example oft the code

In C++ file : template<class T> class RTData: public RTDataGeneric {public:
    T m_value;
    T m_lowerLimit;
    T m_upperLimit;
    operator T&(){     return m_value; }
    RTData() :RTDataGeneric()
    {
        m_value = 0;
        m_lowerLimit = 0;
        m_upperLimit = 0;
    }

    RTData(const RTData &data) :RTDataGeneric(data)
    {
            m_value = data.m_value;
        m_lowerLimit = data.m_lowerLimit;
        m_upperLimit = data.m_upperLimit;
    }

    /** Constructor with value
     */
    RTData(const T & value) :RTDataGeneric()
    {
        m_value = value;
        m_lowerLimit = 0;
        m_upperLimit = 0;
    }
    virtual ~RTData(){ }
    RTData & operator=(const T value)
    {
        this->setValue(value);
        return *this;
    }
The use in a scripting file is : program PrgTestData {
  var doubleRT_t x_1 = doubleRT_t(25.0, 4 , 10);
  set x_1 = 4;
}

In this example, when i log the data x_1 after modify the value, the value oft the lower and the upper limit are equals to zero.

Thank you

Didier

Use of Special Data ina scripting file

Hi Didier,

On Mon, Nov 9, 2009 at 16:25, <didier [dot] gardan [..] ...> wrote:

> Hello everyone
>
> In my company, we have developped a new type of data. This data is a
> template. We use this data
> with Orocos script. So we add this template on Orocos Struct .We also add
> unary and binary operator to use the severals methods of this kind of data
> with the dot operator.
> The problem is that i can only use the dot operator to read. In a scripting
> file, i want to modify the value of may date (i don't want to modify the
> others member's variables of this data). To resolve this, i decide to
> overload the operator "=" for my data. The overload is OK in a C++ file, but
> it doesn't work in a scripting file. It seems that in a scripting file, it
> is the constructor with value that is used when i try to modify the value of
> my data (and of course, the others member's variables of the data are
> modified)
> How can i solve this problem ?
>

The reason this does not work is because the parser rewrites:

program PrgTestData
{
var doubleRT_t x_1 = doubleRT_t(25.0, 4 , 10);
set x_1 = 4;
}

to:

program PrgTestData
{
var doubleRT_t x_1 = doubleRT_t(25.0, 4 , 10);
set x_1 = doubleRT(4);
}

It casts the 4 to the type of x_1, using the C++ constructor that you
defined. Today's scripting does not allow to overload the = operator.

I see only two short-term solutions to your problem:
1. define a C++ function that does the assignment and export that as a
method for scripting. This would bind that function to a certain component,
which is pretty ugly.
2. change your RTData class such that if it is assigned another RTData which
has limits 0,0 (to denote uninitialized limits), the limits are not
overwritten.

The long term solution is to have the 'dot' operator being writable, but
that's for early next year the soonest.

Peter

Use of Special Data ina scripting file

Hello everyone

In my company, we have developped a new type of data. This data is a template. We use this data
with Orocos script. So we add this template on Orocos Struct .We also add unary and binary operator to use the severals methods of this kind of data with the dot operator.
The problem is that i can only use the dot operator to read. In a scripting file, i want to modify the value of may date (i don't want to modify the others member's variables of this data). To resolve this, i decide to overload the operator "=" for my data. The overload is OK in a C++ file, but it doesn't work in a scripting file. It seems that in a scripting file, it is the constructor with value that is used when i try to modify the value of my data (and of course, the others member's variables of the data are modified)
How can i solve this problem ?

Heres is an example oft the code

In C++ file :
template<class T> class RTData: public RTDataGeneric
{
public:
T m_value;
T m_lowerLimit;
T m_upperLimit;
operator T&(){ return m_value; }
RTData() :RTDataGeneric()
{
m_value = 0;
m_lowerLimit = 0;
m_upperLimit = 0;
}

RTData(const RTData &data) :RTDataGeneric(data)
{
m_value = data.m_value;
m_lowerLimit = data.m_lowerLimit;
m_upperLimit = data.m_upperLimit;
}

/** Constructor with value
*/
RTData(const T & value) :RTDataGeneric()
{
m_value = value;
m_lowerLimit = 0;
m_upperLimit = 0;
}
virtual ~RTData(){ }
RTData & operator=(const T value)
{
this->setValue(value);
return *this;
}

The use in a scripting file is :
program PrgTestData
{
var doubleRT_t x_1 = doubleRT_t(25.0, 4 , 10);
set x_1 = 4;
}
In this example, when i log the data x_1 after modify the value, the value oft the lower and the upper limit are equals to zero.

Thank you

Didier