//////////////////////////////////////////////////////////////////////////////// // The Loki Library // Copyright (c) 2005 Peter Kümmel // Permission to use, copy, modify, distribute and sell this software for any // purpose is hereby granted without fee, provided that the above copyright // notice appear in all copies and that both that copyright notice and this // permission notice appear in supporting documentation. // The author makes no representations about the // suitability of this software for any purpose. It is provided "as is" // without express or implied warranty. //////////////////////////////////////////////////////////////////////////////// #ifndef LOKI_FUNCTION_INC_ #define LOKI_FUNCTION_INC_ // $Id: Function.h 841 2008-03-24 23:58:28Z rich_sposato $ #define LOKI_ENABLE_FUNCTION #include #include #include namespace Loki { //////////////////////////////////////////////////////////////////////////////// /// \struct Function /// /// \ingroup FunctorGroup /// Allows a boost/TR1 like usage of Functor. /// /// \par Usage /// /// - free functions: e.g. \code Function f(&freeFunction); /// \endcode /// - member functions: e.g \code Function f(&object,&ObjectType::memberFunction); /// \endcode /// /// see also test/Function/FunctionTest.cpp (the modified test program from boost) //////////////////////////////////////////////////////////////////////////////// template struct Function; template struct Function : public Functor { typedef Functor FBase; Function() : FBase() {} Function(const Function& func) : FBase() { if ( !func.empty()) FBase::operator=(func); } // test on emptiness template Function(Function func) : FBase() { if (!func.empty()) FBase::operator=(func); } // clear by '= 0' Function(const int i) : FBase() { if (i == 0) FBase::clear(); else throw std::runtime_error("Loki::Function(const int i): i!=0"); } template Function(Func func) : FBase(func) {} template Function(const Host& host, const Func& func) : FBase(host, func) {} }; //////////////////////////////////////////////////////////////////////////////// // macros for the repetitions //////////////////////////////////////////////////////////////////////////////// #define LOKI_FUNCTION_BODY \ \ Function() : FBase() {} \ \ Function(const Function& func) : FBase() \ { \ if( !func.empty()) \ FBase::operator=(func); \ } \ \ Function(const int i) : FBase() \ { \ if(i==0) \ FBase::clear(); \ else \ throw std::runtime_error( \ "Loki::Function(const int i): i!=0"); \ } \ \ template \ Function(Func func) : FBase(func) {} \ \ template \ Function(const Host& host, const Func& func): FBase(host,func) {} #define LOKI_FUNCTION_R2_CTOR_BODY \ \ : FBase() \ { \ if(!func.empty()) \ FBase::operator=(func); \ } //////////////////////////////////////////////////////////////////////////////// // repetitions //////////////////////////////////////////////////////////////////////////////// template<> struct Function<> : public Loki::Functor<> { typedef Functor<> FBase; template Function(Function func) LOKI_FUNCTION_R2_CTOR_BODY LOKI_FUNCTION_BODY // if compilation breaks here then // Function.h was not included before // Functor.h, check your include order // or define LOKI_ENABLE_FUNCTION }; template struct Function : public Loki::Functor > { typedef Functor > FBase; template Function(Function func) LOKI_FUNCTION_R2_CTOR_BODY LOKI_FUNCTION_BODY }; template struct Function : public Functor > { typedef Functor > FBase; template Function(Function func) LOKI_FUNCTION_R2_CTOR_BODY LOKI_FUNCTION_BODY }; template struct Function : public Functor > { typedef Functor > FBase; template Function(Function func) LOKI_FUNCTION_R2_CTOR_BODY LOKI_FUNCTION_BODY }; template struct Function : public Functor > { typedef Functor > FBase; template Function(Function func) LOKI_FUNCTION_R2_CTOR_BODY LOKI_FUNCTION_BODY }; template struct Function : public Functor > { typedef Functor > FBase; template Function(Function func) LOKI_FUNCTION_R2_CTOR_BODY LOKI_FUNCTION_BODY }; template < class R, class P01, class P02, class P03, class P04, class P05, class P06 > struct Function : public Functor > { typedef Functor > FBase; template < class R2, class Q01, class Q02, class Q03, class Q04, class Q05, class Q06 > Function(Function func) LOKI_FUNCTION_R2_CTOR_BODY LOKI_FUNCTION_BODY }; template < class R, class P01, class P02, class P03, class P04, class P05, class P06, class P07 > struct Function : public Functor > { typedef Functor > FBase; template < class R2, class Q01, class Q02, class Q03, class Q04, class Q05, class Q06, class Q07 > Function(Function func) LOKI_FUNCTION_R2_CTOR_BODY LOKI_FUNCTION_BODY }; template < class R, class P01, class P02, class P03, class P04, class P05, class P06, class P07, class P08 > struct Function : public Functor > { typedef Functor > FBase; template < class R2, class Q01, class Q02, class Q03, class Q04, class Q05, class Q06, class Q07, class Q08 > Function(Function func) LOKI_FUNCTION_R2_CTOR_BODY LOKI_FUNCTION_BODY }; template < class R, class P01, class P02, class P03, class P04, class P05, class P06, class P07, class P08, class P09 > struct Function : public Functor > { typedef Functor > FBase; template < class R2, class Q01, class Q02, class Q03, class Q04, class Q05, class Q06, class Q07, class Q08, class Q09 > Function(Function func) LOKI_FUNCTION_R2_CTOR_BODY LOKI_FUNCTION_BODY }; template < class R, class P01, class P02, class P03, class P04, class P05, class P06, class P07, class P08, class P09, class P10 > struct Function : public Functor > { typedef Functor > FBase; template < class R2, class Q01, class Q02, class Q03, class Q04, class Q05, class Q06, class Q07, class Q08, class Q09, class Q10 > Function(Function func) LOKI_FUNCTION_R2_CTOR_BODY LOKI_FUNCTION_BODY }; template < class R, class P01, class P02, class P03, class P04, class P05, class P06, class P07, class P08, class P09, class P10, class P11 > struct Function : public Functor > { typedef Functor >FBase; template < class R2, class Q01, class Q02, class Q03, class Q04, class Q05, class Q06, class Q07, class Q08, class Q09, class Q10, class Q11 > Function(Function func) LOKI_FUNCTION_R2_CTOR_BODY LOKI_FUNCTION_BODY }; template < class R, class P01, class P02, class P03, class P04, class P05, class P06, class P07, class P08, class P09, class P10, class P11, class P12 > struct Function : public Functor > { typedef Functor > FBase; template < class R2, class Q01, class Q02, class Q03, class Q04, class Q05, class Q06, class Q07, class Q08, class Q09, class Q10, class Q11, class Q12 > Function(Function func) LOKI_FUNCTION_R2_CTOR_BODY LOKI_FUNCTION_BODY }; template < class R, class P01, class P02, class P03, class P04, class P05, class P06, class P07, class P08, class P09, class P10, class P11, class P12, class P13 > struct Function : public Functor > { typedef Functor > FBase; template < class R2, class Q01, class Q02, class Q03, class Q04, class Q05, class Q06, class Q07, class Q08, class Q09, class Q10, class Q11, class Q12, class Q13 > Function(Function func) LOKI_FUNCTION_R2_CTOR_BODY LOKI_FUNCTION_BODY }; template < class R, class P01, class P02, class P03, class P04, class P05, class P06, class P07, class P08, class P09, class P10, class P11, class P12, class P13, class P14 > struct Function : public Functor > { typedef Functor > FBase; template < class R2, class Q01, class Q02, class Q03, class Q04, class Q05, class Q06, class Q07, class Q08, class Q09, class Q10, class Q11, class Q12, class Q13, class Q14 > Function(Function func) LOKI_FUNCTION_R2_CTOR_BODY LOKI_FUNCTION_BODY }; template < class R, class P01, class P02, class P03, class P04, class P05, class P06, class P07, class P08, class P09, class P10, class P11, class P12, class P13, class P14, class P15 > struct Function : public Functor > { typedef Functor > FBase; template < class R2, class Q01, class Q02, class Q03, class Q04, class Q05, class Q06, class Q07, class Q08, class Q09, class Q10, class Q11, class Q12, class Q13, class Q14, class Q15 > Function(Function func) LOKI_FUNCTION_R2_CTOR_BODY LOKI_FUNCTION_BODY }; }// namespace Loki #endif // end file guardian