1 |
#ifndef _CALLBACK_FUNCTOR_H_ |
2 |
#define _CALLBACK_FUNCTOR_H_ |
3 |
#include <map> |
4 |
#include <utility> |
5 |
#include "TypeInfo.hpp" |
6 |
using namespace std; |
7 |
|
8 |
class ConstraintPair; |
9 |
class ConstraintElement; |
10 |
class SimInfo; |
11 |
class ConstraintAtom; |
12 |
class ConstraintRigidBody; |
13 |
|
14 |
class CallbackFunctor{ |
15 |
public: |
16 |
typedef pair<TypeInfo, TypeInfo> KeyType; |
17 |
typedef int (CallbackFunctor::*MappedType)(ConstraintElement*, ConstraintElement*); |
18 |
typedef map<KeyType, MappedType> DoubleDispatchMap; |
19 |
|
20 |
virtual ~CallbackFunctor(){} |
21 |
|
22 |
//operator() is resiponsible for double dispatching |
23 |
int operator()(ConstraintPair* consPair); |
24 |
|
25 |
//double dispatch map can not store virtual function |
26 |
//below functions are just wrapping functions which will be forwarded to virtual function |
27 |
int constrainAtomAtom(ConstraintElement* ce1, ConstraintElement* ce2); |
28 |
int constrainAtomRigidBody(ConstraintElement* ce1, ConstraintElement* ce2); |
29 |
int constrainRigidBodyAtom(ConstraintElement* ce1, ConstraintElement* ce2); |
30 |
int constrainRigidBodyRigidBody(ConstraintElement* ce1, ConstraintElement* ce2); |
31 |
|
32 |
protected: |
33 |
CallbackFunctor(SimInfo* rhs); |
34 |
|
35 |
void registerFunction(const KeyType& key, MappedType f); |
36 |
|
37 |
// |
38 |
virtual int operator()(ConstraintAtom*, ConstraintAtom*) = 0; |
39 |
virtual int operator()(ConstraintAtom*, ConstraintRigidBody*) = 0; |
40 |
virtual int operator()(ConstraintRigidBody*, ConstraintRigidBody*) = 0; |
41 |
|
42 |
SimInfo* info; |
43 |
ConstraintPair* curPair; |
44 |
|
45 |
DoubleDispatchMap ddMap; |
46 |
|
47 |
const double consTolerance; |
48 |
}; |
49 |
|
50 |
#endif //end ifndef _CALLBACK_FUNCTOR_H_ |