| 1 | 
tim | 
1232 | 
#include "CallbackFunctor.hpp" | 
| 2 | 
  | 
  | 
#include "ConstraintPair.hpp" | 
| 3 | 
  | 
  | 
#include "SimInfo.hpp" | 
| 4 | 
  | 
  | 
#include "ConstraintPair.hpp" | 
| 5 | 
  | 
  | 
 | 
| 6 | 
  | 
  | 
CallbackFunctor:: CallbackFunctor(SimInfo* rhs) : info(rhs){ | 
| 7 | 
  | 
  | 
  registerFunction(KeyType(typeid(ConstraintElement), typeid(ConstraintElement)), &CallbackFunctor::constrainAtomAtom); | 
| 8 | 
  | 
  | 
  registerFunction(KeyType(typeid(ConstraintElement), typeid(ConstraintRigidBody)), &CallbackFunctor::constrainAtomRigidBody); | 
| 9 | 
  | 
  | 
  registerFunction(KeyType(typeid(ConstraintRigidBody), typeid(ConstraintElement)), &CallbackFunctor::constrainRigidBodyAtom); | 
| 10 | 
  | 
  | 
  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 | 
  | 
  | 
  foundResult = ddMap.find(KeyType(typeid(consPair->firstElem), typeid(consPair->secondElem))); | 
| 21 | 
  | 
  | 
   | 
| 22 | 
  | 
  | 
  if(foundResult != ddMap.end()){ | 
| 23 | 
  | 
  | 
    return (this->*(foundResult->second))(consPair->firstElem, consPair->secondElem); | 
| 24 | 
  | 
  | 
  } | 
| 25 | 
  | 
  | 
  else | 
| 26 | 
  | 
  | 
    //can not found appropriate function to handle (ce1, ce2) | 
| 27 | 
  | 
  | 
    return -1; | 
| 28 | 
  | 
  | 
   | 
| 29 | 
  | 
  | 
} | 
| 30 | 
  | 
  | 
 | 
| 31 | 
  | 
  | 
int CallbackFunctor::constrainAtomAtom(ConstraintElement* ce1, ConstraintElement* ce2){ | 
| 32 | 
  | 
  | 
  return (*this)((ConstraintAtom*)ce1, (ConstraintAtom*)ce2); | 
| 33 | 
  | 
  | 
} | 
| 34 | 
  | 
  | 
 | 
| 35 | 
  | 
  | 
int CallbackFunctor::constrainAtomRigidBody(ConstraintElement* ce1, ConstraintElement* ce2){ | 
| 36 | 
  | 
  | 
  return (*this)((ConstraintAtom*)ce1, (ConstraintRigidBody*)ce2); | 
| 37 | 
  | 
  | 
 | 
| 38 | 
  | 
  | 
} | 
| 39 | 
  | 
  | 
 | 
| 40 | 
  | 
  | 
int CallbackFunctor::constrainRigidBodyAtom(ConstraintElement* ce1, ConstraintElement* ce2){ | 
| 41 | 
  | 
  | 
  return constrainAtomRigidBody(ce2, ce1); | 
| 42 | 
  | 
  | 
} | 
| 43 | 
  | 
  | 
 | 
| 44 | 
  | 
  | 
int CallbackFunctor::constrainRigidBodyRigidBody(ConstraintElement* ce1, ConstraintElement* ce2){ | 
| 45 | 
  | 
  | 
  return (*this)((ConstraintRigidBody*)ce1, (ConstraintRigidBody*)ce2); | 
| 46 | 
  | 
  | 
} |