// Procedural.h -- Procedural binder and adapter template classes // (c) Copyright Schlumberger Technology Corp., unpublished work, created // 1999. This computer program includes Confidential, Proprietary // Information and is a Trade Secret of Schlumberger Technology Corp. All // use, disclosure, and/or reproduction is prohibited unless authorized // in writing. All Rights Reserved. #if !defined(SLBCSP_PROCEDURAL_H) #define SLBCSP_PROCEDURAL_H #include // Template classes that support composition of procedure objects // (proctors). Proctors are like functors (function objects) but // don't return a value (void). The template classes defined here // follow C++ member function binders and adapters. /////////////////////////// BINDERS ///////////////////////////////// template struct UnaryProcedure : public std::unary_function {}; template struct BinaryProcedure : public std::binary_function {}; template class ProcedureBinder2nd : public UnaryProcedure { public: ProcedureBinder2nd(BinaryProc const &rproc, BinaryProc::second_argument_type const &rarg) : m_proc(rproc), m_arg2(rarg) {} void operator()(argument_type const &arg1) const { m_proc(arg1, m_arg2); } protected: BinaryProc m_proc; BinaryProc::second_argument_type m_arg2; }; template ProcedureBinder2nd ProcedureBind2nd(BinaryProc const &rProc, T const &rv) { return ProcedureBinder2nd(rProc, BinaryProc::second_argument_type(rv)); }; //////////////////// MEMBER PROCEDURE ADAPTERS ////////////////////////// template class MemberProcedureType : public UnaryProcedure { public: // Types // C'tors/D'tors explicit MemberProcedureType(void (T::* p)()) : m_pmp(p) {} // Operators void operator()(T *p) const { (p->*m_pmp)(); } // Operations // Access // Predicates protected: // Types // C'tors/D'tors // Operators // Operations // Access // Predicates // Variables private: // Types // C'tors/D'tors // Operators // Operations // Access // Predicates // Variables void (T::* m_pmp)(); }; template MemberProcedureType MemberProcedure(void (T::* p)()) { return MemberProcedureType(p); }; //////////////////// POINTER TO PROCEDURE ADAPTERS /////////////////////// template class PointerToBinaryProcedure : public BinaryProcedure { public: // Types // C'tors/D'tors explicit PointerToBinaryProcedure(void (*p)(T1, T2)) : m_p(p) {} // Operators void operator()(T1 arg1, T2 arg2) const { m_p(arg1, arg2); } // Operations // Access // Predicates protected: // Types // C'tors/D'tors // Operators // Operations // Access // Predicates // Variables void (*m_p)(T1, T2); private: // Types // C'tors/D'tors // Operators // Operations // Access // Predicates // Variables }; template PointerToBinaryProcedure PointerProcedure(void (*p)(T1, T2)) { return PointerToBinaryProcedure(p); }; template class PointerToUnaryProcedure : public UnaryProcedure { public: // Types // C'tors/D'tors explicit PointerToUnaryProcedure(void (*p)(T)) : m_p(p) {} // Operators void operator()(T arg) const { m_p(arg); } // Operations // Access // Predicates protected: // Types // C'tors/D'tors // Operators // Operations // Access // Predicates // Variables void (*m_p)(T); private: // Types // C'tors/D'tors // Operators // Operations // Access // Predicates // Variables }; template PointerToUnaryProcedure PointerProcedure(void (*p)(T)) { return PointerToUnaryProcedure(p); } #endif // SLBCSP_PROCEDURAL_H