// BEGIN functor
// see
// http://www.newty.de/CCPP/functor/functor.html#chapter4
//
// chapter 5 of andrei ignored, since it is far too complicated
// for what is needed here.

// generic functor
// implementation class inherits from this, but this is passed to functions
class TFunctor
{
public:
  virtual void operator()(TreeNode<double> *inNode) = 0;
};

// implementation class, the constructor takes a pointer to an object (pricing)
// and acts as a bridge between the iterator listener callback and
// the visitStock provided by one of the derivative classes (which is stored inside
// pricing)

template <class TClass> class TSpecificFunctor : public TFunctor
{
private:
  void (TClass::*fpt)(unsigned int depth, unsigned int c, double inStockValue);
  TClass *ptr2Object;
  
public:
  TSpecificFunctor(TClass *inPtr2Object, void (TClass::*_fpt)(unsigned int depth, unsigned int c,
							      double inStockValue))
  {
    ptr2Object = inPtr2Object;
    fpt = _fpt;
  }
  
  virtual void operator()(TreeNode<double> *inNode)
  {
    // translate the call from the callback from the iterator to the format
    // expected by one of the derivative classes
    (*ptr2Object.*fpt)(inNode->depth, inNode->childNum, inNode->value);
  }
};
// END functor
