DUECA/DUSIME
Loading...
Searching...
No Matches
Public Member Functions | List of all members
dueca::MemberCall2Way< C, T > Class Template Reference

Template specialisation of the GenericVarIO. More...

#include <MemberCall2Way.hxx>

Inheritance diagram for dueca::MemberCall2Way< C, T >:
Inheritance graph
[legend]
Collaboration diagram for dueca::MemberCall2Way< C, T >:
Collaboration graph
[legend]

Public Member Functions

 MemberCall2Way (bool(C ::*c)(T &, bool in))
 Constructor.
 
bool poke (void *obj, const T &v) const
 Call the member function with data.
 
bool peek (void *obj, T &v) const
 Obtain data from the class object.
 
- Public Member Functions inherited from dueca::GenericVarIO
 GenericVarIO ()
 constructor
 
virtual ~GenericVarIO ()
 destructor
 
ProbeType getType () const
 returns the argument type required
 
 DECLARE_IN_GENERICVAR_IO (int)
 Use handy macro to declare stuff for int.
 
 DECLARE_IN_GENERICVAR_IO (uint32_t)
 Use handy macro to declare stuff for int.
 
 DECLARE_IN_GENERICVAR_IO (uint16_t)
 Use handy macro to declare stuff for int.
 
 DECLARE_IN_GENERICVAR_IO (double)
 Use handy macro to declare stuff for double.
 
 DECLARE_IN_GENERICVAR_IO (float)
 Use handy macro to declare stuff for float.
 
 DECLARE_IN_GENERICVAR_IO (bool)
 Use handy macro to declare stuff for bool.
 
 DECLARE_IN_GENERICVAR_IO (TimeSpec)
 Use handy macro to declare stuff for TimeSpec.
 
 DECLARE_IN_GENERICVAR_IO (PeriodicTimeSpec)
 Use handy macro to declare stuff for PeriodicTimeSpec.
 
 DECLARE_IN_GENERICVAR_IO (PrioritySpec)
 Use handy macro to declare stuff for PrioritySpec.
 
 DECLARE_IN_GENERICVAR_IO (vstring)
 Use handy macro to declare stuff for vstring.
 
 DECLARE_IN_GENERICVAR_IO (SCM)
 Use handy macro to declare stuff for SCM.
 
 DECLARE_IN_GENERICVAR_IO (vector_int)
 Use handy macro to declare stuff for vector<int>
 
 DECLARE_IN_GENERICVAR_IO (vector_float)
 Use handy macro to declare stuff for vector<float>
 
 DECLARE_IN_GENERICVAR_IO (vector_double)
 Use handy macro to declare stuff for vector<double>
 
 DECLARE_IN_GENERICVAR_IO (vector_vstring)
 Use handy macro to declare stuff for vector<vstring>
 
 DECLARE_IN_GENERICVAR_IO (ScriptCreatable)
 Objects creatable from scripts.
 
 DECLARE_IN_GENERICVAR_IO (string8)
 Dstring8.
 
 DECLARE_IN_GENERICVAR_IO (string16)
 Dstring.
 
 DECLARE_IN_GENERICVAR_IO (string32)
 Dstring.
 
 DECLARE_IN_GENERICVAR_IO (string64)
 Dstring.
 
 DECLARE_IN_GENERICVAR_IO (string128)
 Dstring.
 

Additional Inherited Members

- Protected Attributes inherited from dueca::GenericVarIO
ProbeType ptype
 type of argument passed/inserted/read
 

Detailed Description

template<class C, class T>
class dueca::MemberCall2Way< C, T >

Template specialisation of the GenericVarIO.

The MemberCall2Way takes a pointer to a member function of simple shape, and with that information and a pointer to an object in that class it can call the member function.

One common use is accepting Scheme or Python (helper) objects in your class. Suppose that you have made a class MyHelper creatable to Scheme, by deriving it from the dueca::ScriptCreatable class. Then in Scheme code you can create the helper, and pass it on to your (module) class:

(define helper (new-my-helper <arguments>))
(new-module 'my-module ""
'set-helper helper)
This is a "light weight object" that enables you to read the latest set of data on a StreamChannelEnd...
Definition StreamReaderLatest.hxx:43

The same in Python:

helper = dueca.MyHelper(<arguments>).complete()
module = dueca.Module("my-module", "", some_prio_spec).param(
set_helper = helper)

To process the setting of the helper, you add an entry to your ParameterTable:

(&MyModule::setHelper),
"give me a MyHelper object" },

The setHelper call should accept a ScriptCreatable, check whether it is really a MyHelper object, and keep a reference to the MyHelper object.

bool MyModule::setHelper(ScriptCreatable &h, bool in);
{
// direction MUST be in
if (!in) return false;
// try a dynamic cast
MyHelper* local_helper = dynamic_cast<MyHelper*> (&h);
if (local_helper == NULL) {
E_MOD("Object is not a helper!");
return false;
}
// keep the pointer to the helper
helper = local_helper;
// say its all right
return true;
}
#define E_MOD(A)
Error messages for application module code.
Definition newlog-macros.hxx:620

Note that the helper object has been created in the script language; object ownership is therefore by the script. Any helper objects (also ones you don't use in the end), will be made dependent on the modules you attached them to, so garbage collection will only kick in when both the helper and module objects in the above scripts are cleared.

Constructor & Destructor Documentation

◆ MemberCall2Way()

template<class C , class T >
dueca::MemberCall2Way< C, T >::MemberCall2Way ( bool(C ::*)(T &, bool in) c)

Constructor.

Parameters
cA pointer to a member function, with signature
bool C::function(T&, bool in).
This function must accept the value in T when the variable "in" is true (into the class), or return the value of T when "in" is false (out of the class).

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