/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or * its licensors. * * For complete copyright and license terms please see the LICENSE at the root of this * distribution (the "License"). All use of this software is governed by the License, * or, if provided, by the license below or the license accompanying this file. Do not * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ // Original file Copyright Crytek GMBH or its affiliates, used under license. // Description : User header for multi DLL functors. #ifndef CRYINCLUDE_CRYCOMMON_SFUNCTOR_H #define CRYINCLUDE_CRYCOMMON_SFUNCTOR_H #pragma once #include "FunctorBaseFunction.h" #include "FunctorBaseMember.h" // Needed for CryFont to compile. // Maybe for others too. #include "smartptr.h" struct SFunctor { public: // Calls the functor method. // returns true, if a functor is registered, false otherwise. bool Call() { if (!m_pFunctor) { return false; } m_pFunctor->Call(); return true; } // Sets a new functor, common function, void return type, no arguments. // Parameters: the function pointer. template void Set(tCallback pCallback) { typedef TFunctor TType; m_pFunctor = new TType(pCallback); } // Sets a new functor, common function, void return type, 1 argument. // Parameters: the function pointer, the argument to be passed to the function. template void Set(tCallback pCallback, const tArgument1& Argument1) { typedef TFunctor TType; m_pFunctor = new TType(pCallback, Argument1); } // Sets a new functor, common function, void return type, 2 arguments. // Parameters: the function pointer, the 2 arguments to be passed to the function. template void Set(tCallback pCallback, const tArgument1& Argument1, const tArgument2& Argument2) { typedef TFunctor TType; m_pFunctor = new TType(pCallback, Argument1, Argument2); } // Sets a new functor, common function, void return type, no arguments. // Parameters: the function pointer, the 2 arguments to be passed to the function. template void Set(tCallee* pCallee, void (tCallee::* pCallback)()) { typedef TFunctor TType; m_pFunctor = new TType(pCallee, pCallback); } // Sets a new functor, common function, void return type, 1 argument. // Parameters: the function pointer, the 2 arguments to be passed to the function, the argument. template void Set(tCallee* pCallee, void (tCallee::* pCallback)(tArgument1), const tArgument1& Argument1) { typedef TFunctor TType; m_pFunctor = new TType(pCallee, pCallback, Argument1); } // Sets a new functor, common function, void return type, 2 arguments. // Parameters: the function pointer, the 2 arguments to be passed to the function, the 2 arguments. template void Set(tCallee* pCallee, void (tCallee::* pCallback)(tArgument1, tArgument2), const tArgument1& Argument1, const tArgument2& Argument2) { typedef TFunctor TType; m_pFunctor = new TType(pCallee, pCallback, Argument1, Argument2); } // Used to compare equality between 2 IFunctors. bool operator==(const SFunctor& rOther) { return m_pFunctor == rOther.m_pFunctor; } // Used order to IFunctors (needed for some containers, like map). bool operator<(const SFunctor& rOther) { return m_pFunctor < rOther.m_pFunctor; } protected: _smart_ptr m_pFunctor; }; #endif // CRYINCLUDE_CRYCOMMON_SFUNCTOR_H