array of properties in cpf file

Hi,

I recently started using orocos and I have a few questions while working with properties.

Every orocos component can have its own configuration file to store properties. I only have a few simple examples of such files.

Now, I was wondering if it is possible to create more complex configuration files, to store an array of properties.
The following example should clarify the object model:


- SensorCollection (holds an array of "Sensor" objects)
- Sensor 0
- propertyName
- propertyChannel
- Sensor 1
- propertyName
- propertyChannel
- Sensor n

SensorCollection is a container object to manage all Sensor objects. Each sensor has a few properties to configure a PulseTrainGenerator. Because I don't want each Sensor to have its own configuration file, it would be handy to create a configuration file for all sensor objects.

Question 1: Is their any way to build such a property file ?
Question 2: If so, how do you iterate these arrays in the code ?

e.g.

Property propChannel = mPropertyBag.getProperty("PropSpeedChannel")[0];

Thanks in advance !

Best regards,

Tom Langeraet

array of properties in cpf file

On Monday 23 June 2008 15:08:12 Tom Langeraet wrote:
> Hi,
>
> I recently started using orocos and I have a few questions while working
> with properties.
>
> Every orocos component can have its own configuration file to store
> properties. I only have a few simple examples of such files.
>
> Now, I was wondering if it is possible to create more complex configuration
> files, to store an array of properties. The following example should
> clarify the object model:
>
>
> - SensorCollection (holds an array of "Sensor" objects)
> - Sensor 0
> - propertyName
> - propertyChannel
> - Sensor 1
> - propertyName
> - propertyChannel
> - Sensor n
>
>
> SensorCollection is a container object to manage all Sensor objects. Each
> sensor has a few properties to configure a PulseTrainGenerator. Because I
> don't want each Sensor to have its own configuration file, it would be
> handy to create a configuration file for all sensor objects.
>
> Question 1: Is their any way to build such a property file ?

You can 'build' the property file using (nested) ' elements. They map
to Property C++ types. According to a recent bug report, this is
indeed poorly documented.

> Question 2: If so, how do you iterate these arrays in the code ?
>
> e.g.
>
> Property propChannel = mPropertyBag.getProperty("PropSpeedChannel")[0];

in XML:

1
...

To iterate over this XML struct, you would write (in a TaskContext):
// Get a top-level struct from a PropertyBag:
Property bag1 = this->properties()->find("PropSpeedChannel");
if ( !bag1.ready() ) {
// error, no such struct
}
// use rvalue() to access the 'PropertyBag' inside
the 'Property'
Property channel = bag1.rvalue().find("Channel");
if ( !channel.ready() ) {
// no such struct
}
//Or iterate (again using rvalue):
for (int i = 0; i != bag1.rvalue().size(); ++i) {
PropertyBase* item = bag1.rvalue().getItem(i);
// use item...
}

Peter