| 1 | tim | 1232 | #include "CallbackFunctor.hpp" | 
| 2 |  |  | #include "ConstraintPair.hpp" | 
| 3 |  |  | #include "SimInfo.hpp" | 
| 4 |  |  | #include "ConstraintPair.hpp" | 
| 5 |  |  |  | 
| 6 | tim | 1248 | CallbackFunctor:: CallbackFunctor(SimInfo* rhs) : info(rhs), consTolerance(1.0e-6){ | 
| 7 | tim | 1234 | registerFunction(KeyType(typeid(ConstraintAtom), typeid(ConstraintAtom)), &CallbackFunctor::constrainAtomAtom); | 
| 8 |  |  | registerFunction(KeyType(typeid(ConstraintAtom), typeid(ConstraintRigidBody)), &CallbackFunctor::constrainAtomRigidBody); | 
| 9 |  |  | registerFunction(KeyType(typeid(ConstraintRigidBody), typeid(ConstraintAtom)), &CallbackFunctor::constrainRigidBodyAtom); | 
| 10 | tim | 1232 | registerFunction(KeyType(typeid(ConstraintRigidBody), typeid(ConstraintRigidBody)), &CallbackFunctor::constrainRigidBodyRigidBody); | 
| 11 |  |  | } | 
| 12 |  |  | void CallbackFunctor::registerFunction(const KeyType& key, MappedType f){ | 
| 13 |  |  | ddMap[key] = f; | 
| 14 |  |  | } | 
| 15 |  |  |  | 
| 16 |  |  | int CallbackFunctor::operator()(ConstraintPair* consPair){ | 
| 17 |  |  | DoubleDispatchMap::iterator foundResult; | 
| 18 |  |  | curPair = consPair; | 
| 19 |  |  |  | 
| 20 | tim | 1234 | //typeid must operate on reference, otherwise it return the type_info of base class | 
| 21 |  |  | foundResult = ddMap.find(KeyType(typeid(*(consPair->firstElem)), typeid(*(consPair->secondElem)))); | 
| 22 | tim | 1232 |  | 
| 23 |  |  | if(foundResult != ddMap.end()){ | 
| 24 |  |  | return (this->*(foundResult->second))(consPair->firstElem, consPair->secondElem); | 
| 25 |  |  | } | 
| 26 |  |  | else | 
| 27 |  |  | //can not found appropriate function to handle (ce1, ce2) | 
| 28 |  |  | return -1; | 
| 29 |  |  |  | 
| 30 |  |  | } | 
| 31 |  |  |  | 
| 32 |  |  | int CallbackFunctor::constrainAtomAtom(ConstraintElement* ce1, ConstraintElement* ce2){ | 
| 33 |  |  | return (*this)((ConstraintAtom*)ce1, (ConstraintAtom*)ce2); | 
| 34 |  |  | } | 
| 35 |  |  |  | 
| 36 |  |  | int CallbackFunctor::constrainAtomRigidBody(ConstraintElement* ce1, ConstraintElement* ce2){ | 
| 37 |  |  | return (*this)((ConstraintAtom*)ce1, (ConstraintRigidBody*)ce2); | 
| 38 |  |  |  | 
| 39 |  |  | } | 
| 40 |  |  |  | 
| 41 |  |  | int CallbackFunctor::constrainRigidBodyAtom(ConstraintElement* ce1, ConstraintElement* ce2){ | 
| 42 |  |  | return constrainAtomRigidBody(ce2, ce1); | 
| 43 |  |  | } | 
| 44 |  |  |  | 
| 45 |  |  | int CallbackFunctor::constrainRigidBodyRigidBody(ConstraintElement* ce1, ConstraintElement* ce2){ | 
| 46 |  |  | return (*this)((ConstraintRigidBody*)ce1, (ConstraintRigidBody*)ce2); | 
| 47 |  |  | } |