DUECA/DUSIME
Public Types | Public Member Functions | List of all members
ScriptCreatableDataHolder< T > Class Template Reference

ScriptCreatable templated holder class. More...

Inheritance diagram for ScriptCreatableDataHolder< T >:
Inheritance graph
[legend]
Collaboration diagram for ScriptCreatableDataHolder< T >:
Collaboration graph
[legend]

Public Types

typedef T data_type
 Encapsulated type.
 

Public Member Functions

 ScriptCreatableDataHolder ()
 Constructor. More...
 
bool complete ()
 Continued construction. More...
 
const char * getTypeName ()
 Type name information.
 
virtual ~ScriptCreatableDataHolder ()
 Destructor. More...
 
T & data ()
 Gives access to the data object contained in this DataHolder.
 
const T & data () const
 Gives access to the data object contained in this DataHolder.
 

Detailed Description

template<class T>
class ScriptCreatableDataHolder< T >

ScriptCreatable templated holder class.

This template can be used for scheme creatable objects (defined in a DCO file) that do not directly derive from ScriptCreatable.

Typically, use of this class is invoked by setting

(Option ScriptCreatable)

in your DCO object definition.

This ensures that the object can be created from the (scheme) creation script, and all member variables are accessable and settable, with lines like:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.scheme} (define obj (make-my-dco-object 'set-my-member-variable <some-value> ) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In python this looks a little different,

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.python} object = dueca.MyDCOObject().param( my_member_variable = <some value> ) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

To "accept" one of these variables in your module, you can add a function to the parametertable which accepts a ScriptCreatable object. This object can take a dynamic cast to a ScriptCreatableDataHolder of your object type, and with the data() function the data can be accessed.

In your table:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.c++} { "my-object", new MemberCall<ThisModule,ScriptCreatable> (&_ThisModule_::acceptMyObject), "Pass a DCO object created in the script" }, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Then the code to accept the object (declare a matching function in your class):

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.c++} MyModule::acceptMyObject(const ScriptCreatable& objbase) { ScriptCreatableDataHolder<MyObject> *obj = dynamic_cast<ScriptCreatableDataHolder<MyObject> >(&objbase); if (obj != NULL) { do something with that, like cout << obj->data() << endl; } else { E_MOD("You probably passed something that is not a MyObject"); return false; } return true; } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Constructor & Destructor Documentation

◆ ScriptCreatableDataHolder()

template<class T >
ScriptCreatableDataHolder< T >::ScriptCreatableDataHolder ( )
inline

Constructor.

Is normally called from scheme/the creation script.

◆ ~ScriptCreatableDataHolder()

template<class T >
virtual ScriptCreatableDataHolder< T >::~ScriptCreatableDataHolder ( )
inlinevirtual

Destructor.

Member Function Documentation

◆ complete()

template<class T >
bool ScriptCreatableDataHolder< T >::complete ( )
inline

Continued construction.

This is called after all script parameters have been read and filled in, according to the parameter table.


The documentation for this class was generated from the following file: