CSIM: Setting and getting field values of objects

Setting and getting field values of objects

At the Matlab level CSIM allows you to set and get values of fields of objects by means of the commands

  v=csim('get',o,fieldname)
  csim('set',o,fieldname,value)

where o is the handle of the object returned by

  o=csim('create',classname)

and fieldname is a string identifying the field (i.e. the name of the field).

Implementaion

We implemented this mechanism using four classes:

  • csimClass : the base classes of all classes in CSIM which implements the basic set and get methodes for accessable fields

  • csimClassInfo : which stores information (accessible fields, description) about a certain class

  • csimFieldInfo : stores information about a certain field of a given class

Registering classes and fields

To make the set and get methodes of a class derived from csimClass work one has to register this class via csimClassInfoDB::registerCsimClass() and then to register each member variable which we want to be an accessable field via csimClassInfo::registerField() .

Class member variable of the types

  • double and double *
  • float and float *
  • int and int *

can be made accessible fields.

Each field has the following associated information (see csimFieldInfo )

  • access : READWRITE or READONLY
  • units
  • lower and upper bound
  • size : the number of elements if the field is of type float *, double *, or int *

reggen

It woul be a tedious work to code all the csimClassInfoDB::registerCsimClass() and csimClassInfo::registerField() function calls by hand. So we decided to generate it automatically from the source code. We use a tool named reggen (a quick and dirty hack based on doxygen) to gather the infomation from the source code and its doxygen style documentation. reggen writes all relevant function calls to register fields an classes to registerclass.i

Default behaviour of \c reggen

  • public class member variables are registered as READWRITE fields

  • protected class member variables are registered as READONLY

  • private class member variables are not registered.

  • no units are assumed (i.e. a dimensionless field)

  • lower and upper bound are set to -Inf and +Inf respectively

  • an warning is issued if no size information is given for arrays

  • the brief doxygen comment is used as descriptio of the field

  • the brief doxygen comment of a class is used as its description

Specifying information for use by reggen

If you want to register a class you just put the macro DO_REGISTERING somewhere in the class definition.

For each of the member variables where you want to change the default behaviour of reggen you have to put a doxygen brief comment where you specify the relevant information.

Example 1
Make the float variable S a read-writable field with units Volt and a lower and upper bound of -1 and +1 respectively:
  //! A voltage scale factor [readwrite; units=Volt; range=(-1,1);]
  float S;
Example 2
Make the double variable *A a read-only field with 20 elements, units Ohm, and a lower and upper bound of -100 and +100 respectively:
  //! A voltage scale factor [readonly; size=20; units=Ohm; range=(-100,100);]
  double *A;

Source code of reggen

  • Currently reggen is maintained in lsm/develop/reggen .
  • The relevant source file is lsm/develop/reggen/src/defgen.cpp .
  • The binaries are lsm/develop/reggen/bin/reggen for Linux and lsm/develop/reggen/bin/reggen.exe for windows.
  • To compile reggen under Linux type

  cd lsm/develop/reggen; ./configure; make

  • To compile reggen under Windows XP with MS Visual C++ type

  cd lsm/develop/reggen; make.bat msvc

 
(C) 2003, Thomas Natschläger last modified 07/10/2006