MocoExtendProblem: Interface Between OpenSim and MATLAB for Rapidly Developing Direct Collocation Goals in Moco 1.1.0
add custom Moco goals to existing matlab scripts
Session< T > Class Template Reference

Key-value storage to make a stateful MEX function. More...

#include <dispatch.h>

Public Types

typedef std::map< intptr_t, std::shared_ptr< T > > InstanceMap
 

Static Public Member Functions

static intptr_t create (T *instance)
 Create an instance.
 
static void destroy (intptr_t id)
 Destroy an instance.
 
static void destroy (const mxArray *pointer)
 
static T * get (intptr_t id)
 Retrieve an instance or throw if no instance is found.
 
static T * get (const mxArray *pointer)
 
static const T & getConst (intptr_t id)
 Retrieve a const instance or throw if no instance is found.
 
static const T & getConst (const mxArray *pointer)
 
static bool exist (intptr_t id)
 Check if the given id exists.
 
static bool exist (const mxArray *pointer)
 
static void clear ()
 Clear all session instances.
 
static const InstanceMapgetInstanceMap ()
 Get instance map.
 

Private Member Functions

 Session ()
 Constructor prohibited.
 
 ~Session ()
 

Static Private Member Functions

static intptr_t getIntPointer (const mxArray *pointer)
 Convert mxArray to intptr_t.
 
static InstanceMapgetInstances ()
 Get static instance storage.
 

Detailed Description

template<class T>
class mexplus::Session< T >

Key-value storage to make a stateful MEX function.

using namespace std;
using namespace mexplus;
class Database;
template class Session<Database>;
MEX_DEFINE(open) (int nlhs, mxArray* plhs[],
int nrhs, const mxArray* prhs[]) {
unique_ptr<Database> database(new Database(...));
database->open(...);
intptr_t session_id = Session<Database>::create(database.release());
plhs[0] = mxCreateDoubleScalar(session_id);
}
MEX_DEFINE(query) (int nlhs, mxArray* plhs[],
int nrhs, const mxArray* prhs[]) {
intptr_t session_id = mxGetScalar(prhs[0]);
Database* database = Session<Database>::get(session_id);
database->query(...);
}
MEX_DEFINE(close) (int nlhs, mxArray* plhs[],
int nrhs, const mxArray* prhs[]) {
intptr_t session_id = mxGetScalar(prhs[0]);
}
Key-value storage to make a stateful MEX function.
Definition dispatch.h:211
static T * get(intptr_t id)
Retrieve an instance or throw if no instance is found.
Definition dispatch.h:235
static void destroy(intptr_t id)
Destroy an instance.
Definition dispatch.h:226
static intptr_t create(T *instance)
Create an instance.
Definition dispatch.h:217
#define MEX_DEFINE(name)
Define a MEX API function.
Definition dispatch.h:315
MEX function arguments helper library.
Definition arguments.h:40

Member Typedef Documentation

◆ InstanceMap

template<class T >
typedef std::map<intptr_t, std::shared_ptr<T> > InstanceMap

Constructor & Destructor Documentation

◆ Session()

template<class T >
Session ( )
inlineprivate

Constructor prohibited.

◆ ~Session()

template<class T >
~Session ( )
inlineprivate

Member Function Documentation

◆ clear()

template<class T >
static void clear ( )
inlinestatic

Clear all session instances.

Here is the call graph for this function:

◆ create()

template<class T >
static intptr_t create ( T * instance)
inlinestatic

Create an instance.

Here is the call graph for this function:

◆ destroy() [1/2]

template<class T >
static void destroy ( const mxArray * pointer)
inlinestatic
Here is the call graph for this function:

◆ destroy() [2/2]

template<class T >
static void destroy ( intptr_t id)
inlinestatic

Destroy an instance.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ exist() [1/2]

template<class T >
static bool exist ( const mxArray * pointer)
inlinestatic
Here is the call graph for this function:

◆ exist() [2/2]

template<class T >
static bool exist ( intptr_t id)
inlinestatic

Check if the given id exists.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get() [1/2]

template<class T >
static T * get ( const mxArray * pointer)
inlinestatic
Here is the call graph for this function:

◆ get() [2/2]

template<class T >
static T * get ( intptr_t id)
inlinestatic

Retrieve an instance or throw if no instance is found.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getConst() [1/2]

template<class T >
static const T & getConst ( const mxArray * pointer)
inlinestatic
Here is the call graph for this function:

◆ getConst() [2/2]

template<class T >
static const T & getConst ( intptr_t id)
inlinestatic

Retrieve a const instance or throw if no instance is found.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getInstanceMap()

template<class T >
static const InstanceMap & getInstanceMap ( )
inlinestatic

Get instance map.

Here is the call graph for this function:

◆ getInstances()

template<class T >
static InstanceMap * getInstances ( )
inlinestaticprivate

Get static instance storage.

Here is the caller graph for this function:

◆ getIntPointer()

template<class T >
static intptr_t getIntPointer ( const mxArray * pointer)
inlinestaticprivate

Convert mxArray to intptr_t.

Here is the caller graph for this function:

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