diff --git a/src/core/singleton/NullType.h b/src/core/singleton/NullType.h deleted file mode 100644 index cf92f32f9e38eaac3d3b2e7cc9e5ef5447c086ad..0000000000000000000000000000000000000000 --- a/src/core/singleton/NullType.h +++ /dev/null @@ -1,37 +0,0 @@ -//====================================================================================================================== -// -// This file is part of waLBerla. waLBerla is free software: you can -// redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of -// the License, or (at your option) any later version. -// -// waLBerla is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -// for more details. -// -// You should have received a copy of the GNU General Public License along -// with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. -// -//! \file NullType.h -//! \ingroup core -//! \author Klaus Iglberger -//! \author Florian Schornbaum <florian.schornbaum@fau.de> -// -//====================================================================================================================== - -#pragma once - - - -///\cond internal -namespace walberla { -namespace singleton { - - -struct NullType{}; - - -} // namespace singleton -} // namespace walberla -///\endcond diff --git a/src/core/singleton/Singleton.h b/src/core/singleton/Singleton.h index 3522210b0d2c1b388c26b7d62ad26a08747851b8..36a7ea5f8149d37744020c0c94f3f427bad59d99 100644 --- a/src/core/singleton/Singleton.h +++ b/src/core/singleton/Singleton.h @@ -22,8 +22,6 @@ #pragma once -#include "NullType.h" -#include "TypeList.h" #include "core/DataTypes.h" #include "core/NonCopyable.h" @@ -37,376 +35,6 @@ namespace singleton { -#ifdef WALBERLA_CXX_COMPILER_IS_GNU -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-local-typedefs" -#endif - -#ifdef WALBERLA_CXX_COMPILER_IS_CLANG -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunused-local-typedefs" -#endif - - - -//********************************************************************************************************************** -/*!\brief Helper macro for macro concatenation. -// -// The following code was borrowed from the Boost C++ framework (www.boost.org). This piece of -// macro magic joins the two arguments together, even when one of the arguments is itself a -// macro (see 16.3.1 in C++ standard). The key is that macro expansion of macro arguments does -// not occur in WALBERLA_DO_JOIN2 but does in WALBERLA_DO_JOIN. -*/ -#define WALBERLA_JOIN( X, Y ) WALBERLA_DO_JOIN( X, Y ) -#define WALBERLA_DO_JOIN( X, Y ) WALBERLA_DO_JOIN2(X,Y) -#define WALBERLA_DO_JOIN2( X, Y ) X##Y -//********************************************************************************************************************** - - - -//====================================================================================================================== -// -// NAMESPACE FORWARD DECLARATIONS -// -//====================================================================================================================== - -template< typename T, typename TL, bool C > struct HasCyclicDependency; - - - -//====================================================================================================================== -// -// CLASS HASCYCLICDEPENDENCYHELPER -// -//====================================================================================================================== - -//********************************************************************************************************************** -/*!\brief Auxiliary helper struct for the HasCyclicDependency class template. -// -// -// Helper template class for the HasCyclicDependency template class to resolve all lifetime -// dependencies represented by means of a dependency type list. - */ -template< typename TL // Type list of checked lifetime dependencies - , typename D // Type list of lifetime dependencies to check - , size_t N = Length<D>::value > // Length of the dependency type list -struct HasCyclicDependencyHelper; -//********************************************************************************************************************** - - - -//********************************************************************************************************************** -/*!\brief Specialization of the HasCyclicDependencyHelper class template. -// -// This specialization of the HasCyclicDependencyHelper class is selected in case the given -// dependency type list is empty. In this case no cyclic lifetime dependency could be detected. - */ -template< typename TL // Type list of checked lifetime dependencies - , size_t N > // Length of the dependency type list -struct HasCyclicDependencyHelper<TL,NullType,N> -{ - enum { value = 0 }; -}; -//********************************************************************************************************************** - - - -//********************************************************************************************************************** -/*!\brief Specialization of the HasCyclicDependencyHelper class template. -// -// This specialization of the HasCyclicDependencyHelper class is selected in case the length -// of the given type list is 1. - */ -template< typename TL // Type list of checked lifetime dependencies - , typename D > // Type list of lifetime dependencies to check -struct HasCyclicDependencyHelper<TL,D,1> -{ - typedef typename TypeAt<D,0>::Result D1; - - enum { value = HasCyclicDependency<D1,TL,Contains<TL,D1>::value>::value }; -}; -//********************************************************************************************************************** - - - -//********************************************************************************************************************** -/*!\brief Specialization of the HasCyclicDependencyHelper class template. -// -// This specialization of the HasCyclicDependencyHelper class is selected in case the length -// of the given type list is 2. - */ -template< typename TL // Type list of checked lifetime dependencies - , typename D > // Type list of lifetime dependencies to check -struct HasCyclicDependencyHelper<TL,D,2> -{ - typedef typename TypeAt<D,0>::Result D1; - typedef typename TypeAt<D,1>::Result D2; - - enum { value = HasCyclicDependency<D1,TL,Contains<TL,D1>::value>::value || - HasCyclicDependency<D2,TL,Contains<TL,D2>::value>::value }; -}; -//********************************************************************************************************************** - - - -//********************************************************************************************************************** -/*!\brief Specialization of the HasCyclicDependencyHelper class template. -// -// This specialization of the HasCyclicDependencyHelper class is selected in case the length -// of the given type list is 3. - */ -template< typename TL // Type list of checked lifetime dependencies - , typename D > // Type list of lifetime dependencies to check -struct HasCyclicDependencyHelper<TL,D,3> -{ - typedef typename TypeAt<D,0>::Result D1; - typedef typename TypeAt<D,1>::Result D2; - typedef typename TypeAt<D,2>::Result D3; - - enum { value = HasCyclicDependency<D1,TL,Contains<TL,D1>::value>::value || - HasCyclicDependency<D2,TL,Contains<TL,D2>::value>::value || - HasCyclicDependency<D3,TL,Contains<TL,D3>::value>::value }; -}; -//********************************************************************************************************************** - - - -//********************************************************************************************************************** -/*!\brief Specialization of the HasCyclicDependencyHelper class template. -// -// This specialization of the HasCyclicDependencyHelper class is selected in case the length -// of the given type list is 4. - */ -template< typename TL // Type list of checked lifetime dependencies - , typename D > // Type list of lifetime dependencies to check -struct HasCyclicDependencyHelper<TL,D,4> -{ - typedef typename TypeAt<D,0>::Result D1; - typedef typename TypeAt<D,1>::Result D2; - typedef typename TypeAt<D,2>::Result D3; - typedef typename TypeAt<D,3>::Result D4; - - enum { value = HasCyclicDependency<D1,TL,Contains<TL,D1>::value>::value || - HasCyclicDependency<D2,TL,Contains<TL,D2>::value>::value || - HasCyclicDependency<D3,TL,Contains<TL,D3>::value>::value || - HasCyclicDependency<D4,TL,Contains<TL,D4>::value>::value }; -}; -//********************************************************************************************************************** - - - -//********************************************************************************************************************** -/*!\brief Specialization of the HasCyclicDependencyHelper class template. -// -// This specialization of the HasCyclicDependencyHelper class is selected in case the length -// of the given type list is 5. - */ -template< typename TL // Type list of checked lifetime dependencies - , typename D > // Type list of lifetime dependencies to check -struct HasCyclicDependencyHelper<TL,D,5> -{ - typedef typename TypeAt<D,0>::Result D1; - typedef typename TypeAt<D,1>::Result D2; - typedef typename TypeAt<D,2>::Result D3; - typedef typename TypeAt<D,3>::Result D4; - typedef typename TypeAt<D,4>::Result D5; - - enum { value = HasCyclicDependency<D1,TL,Contains<TL,D1>::value>::value || - HasCyclicDependency<D2,TL,Contains<TL,D2>::value>::value || - HasCyclicDependency<D3,TL,Contains<TL,D3>::value>::value || - HasCyclicDependency<D4,TL,Contains<TL,D4>::value>::value || - HasCyclicDependency<D5,TL,Contains<TL,D5>::value>::value }; -}; -//********************************************************************************************************************** - - - -//********************************************************************************************************************** -/*!\brief Specialization of the HasCyclicDependencyHelper class template. -// -// This specialization of the HasCyclicDependencyHelper class is selected in case the length -// of the given type list is 6. - */ -template< typename TL // Type list of checked lifetime dependencies - , typename D > // Type list of lifetime dependencies to check -struct HasCyclicDependencyHelper<TL,D,6> -{ - typedef typename TypeAt<D,0>::Result D1; - typedef typename TypeAt<D,1>::Result D2; - typedef typename TypeAt<D,2>::Result D3; - typedef typename TypeAt<D,3>::Result D4; - typedef typename TypeAt<D,4>::Result D5; - typedef typename TypeAt<D,5>::Result D6; - - enum { value = HasCyclicDependency<D1,TL,Contains<TL,D1>::value>::value || - HasCyclicDependency<D2,TL,Contains<TL,D2>::value>::value || - HasCyclicDependency<D3,TL,Contains<TL,D3>::value>::value || - HasCyclicDependency<D4,TL,Contains<TL,D4>::value>::value || - HasCyclicDependency<D5,TL,Contains<TL,D5>::value>::value || - HasCyclicDependency<D6,TL,Contains<TL,D6>::value>::value }; -}; -//********************************************************************************************************************** - - - -//********************************************************************************************************************** -/*!\brief Specialization of the HasCyclicDependencyHelper class template. -// -// This specialization of the HasCyclicDependencyHelper class is selected in case the length -// of the given type list is 7. - */ -template< typename TL // Type list of checked lifetime dependencies - , typename D > // Type list of lifetime dependencies to check -struct HasCyclicDependencyHelper<TL,D,7> -{ - typedef typename TypeAt<D,0>::Result D1; - typedef typename TypeAt<D,1>::Result D2; - typedef typename TypeAt<D,2>::Result D3; - typedef typename TypeAt<D,3>::Result D4; - typedef typename TypeAt<D,4>::Result D5; - typedef typename TypeAt<D,5>::Result D6; - typedef typename TypeAt<D,6>::Result D7; - - enum { value = HasCyclicDependency<D1,TL,Contains<TL,D1>::value>::value || - HasCyclicDependency<D2,TL,Contains<TL,D2>::value>::value || - HasCyclicDependency<D3,TL,Contains<TL,D3>::value>::value || - HasCyclicDependency<D4,TL,Contains<TL,D4>::value>::value || - HasCyclicDependency<D5,TL,Contains<TL,D5>::value>::value || - HasCyclicDependency<D6,TL,Contains<TL,D6>::value>::value || - HasCyclicDependency<D7,TL,Contains<TL,D7>::value>::value }; -}; -//********************************************************************************************************************** - - - -//********************************************************************************************************************** -/*!\brief Specialization of the HasCyclicDependencyHelper class template. -// -// This specialization of the HasCyclicDependencyHelper class is selected in case the length -// of the given type list is 8. - */ -template< typename TL // Type list of checked lifetime dependencies - , typename D > // Type list of lifetime dependencies to check -struct HasCyclicDependencyHelper<TL,D,8> -{ - typedef typename TypeAt<D,0>::Result D1; - typedef typename TypeAt<D,1>::Result D2; - typedef typename TypeAt<D,2>::Result D3; - typedef typename TypeAt<D,3>::Result D4; - typedef typename TypeAt<D,4>::Result D5; - typedef typename TypeAt<D,5>::Result D6; - typedef typename TypeAt<D,6>::Result D7; - typedef typename TypeAt<D,7>::Result D8; - - enum { value = HasCyclicDependency<D1,TL,Contains<TL,D1>::value>::value || - HasCyclicDependency<D2,TL,Contains<TL,D2>::value>::value || - HasCyclicDependency<D3,TL,Contains<TL,D3>::value>::value || - HasCyclicDependency<D4,TL,Contains<TL,D4>::value>::value || - HasCyclicDependency<D5,TL,Contains<TL,D5>::value>::value || - HasCyclicDependency<D6,TL,Contains<TL,D6>::value>::value || - HasCyclicDependency<D7,TL,Contains<TL,D7>::value>::value || - HasCyclicDependency<D8,TL,Contains<TL,D8>::value>::value }; -}; -//********************************************************************************************************************** - - - -//====================================================================================================================== -// -// CLASS HASCYCLICDEPENDENCY -// -//====================================================================================================================== - -//********************************************************************************************************************** -/*!\brief Class template for the detection of cyclic lifetime dependencies. -// -// This class template checks the given type \a T for cyclic lifetime dependencies. In case a -// cyclic lifetime dependency is detected, the \a value member enumeration is set to 1. Otherwise -// it is set to 0. - */ -template< typename T // The type to be checked for cyclic lifetime dependencies - , typename TL // Type list of checked lifetime dependencies - , bool C=Contains<TL,T>::value > // Flag to indicate whether T is contained in TL -struct HasCyclicDependency -{ - typedef typename Append<TL,T>::Result ETL; - enum { value = HasCyclicDependencyHelper<ETL,typename T::Dependencies>::value }; -}; -//********************************************************************************************************************** - - - -//********************************************************************************************************************** -/*!\brief Specialization of the HasCyclicDependency class template. -// -// This specialization of the HasCyclicDependency class is selected in case the given type \a T -// is contained in the given lifetime dependency type list \a TL. In this case a cyclic lifetime -// dependency was detected and the \a value member enumeration is set to 1. - */ -template< typename T // The type to be checked for cyclic lifetime dependencies - , typename TL > // Type list of checked lifetime dependencies -struct HasCyclicDependency<T,TL,true> -{ - enum { value = 1 }; -}; -//********************************************************************************************************************** - - - -//====================================================================================================================== -// -// CLASS CYCLIC_LIFETIME_DEPENDENCY_TEST -// -//====================================================================================================================== - -//********************************************************************************************************************** -/*!\brief Compile time constraint wrapper class. -// -// Helper class for the pe::CYCLIC_LIFETIME_DEPENDENCY_DETECTED class template. This class is -// used as a wrapper for the instantiation of the pe::CYCLIC_LIFETIME_DEPENDENCY_DETECTED -// constraint class. It serves the purpose to force the instantiation of either the defined -// specialization or the undefined basic template during the compilation. In case the compile -// time condition is met, the type pe::CYCLIC_LIFETIME_DEPENDENCY_TEST<1> is defined. - */ -template< int > struct CYCLIC_LIFETIME_DEPENDENCY_TEST {}; -//********************************************************************************************************************** - - - -//====================================================================================================================== -// -// DETECT_CYCLIC_LIFETIME_DEPENDENCY CONSTRAINT -// -//====================================================================================================================== - -//********************************************************************************************************************** -/*!\brief Compile time constraint. -// -// Helper template class for the compile time constraint enforcement. Based on the compile time -// constant expression used for the template instantiation, either the undefined basic template -// or the specialization is selected. If the undefined basic template is selected, a compilation -// error is created. - */ -template< bool > struct CYCLIC_LIFETIME_DEPENDENCY_DETECTED; -template<> struct CYCLIC_LIFETIME_DEPENDENCY_DETECTED<false> { enum { value = 1 }; }; -//********************************************************************************************************************** - - - -//********************************************************************************************************************** -/*!\brief Constraint on the data type. -// -// In case the given data type \a T is not an integral data type, a compilation error is created. - */ -#define WALBERLA_DETECT_CYCLIC_LIFETIME_DEPENDENCY(T) \ - typedef \ - walberla::singleton::CYCLIC_LIFETIME_DEPENDENCY_TEST< \ - walberla::singleton::CYCLIC_LIFETIME_DEPENDENCY_DETECTED< walberla::singleton::HasCyclicDependency<T,walberla::singleton::NullType>::value >::value > \ - WALBERLA_JOIN( DETECT_CYCLIC_LIFETIME_DEPENDENCY_TYPEDEF, __LINE__ ) -//********************************************************************************************************************** - - - //====================================================================================================================== // // BEFRIEND_SINGLETON MACRO @@ -420,11 +48,11 @@ template<> struct CYCLIC_LIFETIME_DEPENDENCY_DETECTED<false> { enum { value = 1 // class deriving from Singleton. */ #define WALBERLA_BEFRIEND_SINGLETON \ - template< typename, typename, typename, typename, typename, typename,typename, typename, typename > friend class walberla::singleton::Singleton; \ - template< typename, typename, bool > friend struct walberla::singleton::HasCyclicDependency + template< typename > friend class walberla::singleton::Singleton //********************************************************************************************************************** + //====================================================================================================================== // // CLASS SINGLETON @@ -432,24 +60,9 @@ template<> struct CYCLIC_LIFETIME_DEPENDENCY_DETECTED<false> { enum { value = 1 //====================================================================================================================== //********************************************************************************************************************** -/// Base class for all lifetime managed singletons. -template< typename T // Type of the singleton (CRTP pattern) - , typename D1 = NullType // Type of the first lifetime dependency - , typename D2 = NullType // Type of the second lifetime dependency - , typename D3 = NullType // Type of the third lifetime dependency - , typename D4 = NullType // Type of the fourth lifetime dependency - , typename D5 = NullType // Type of the fifth lifetime dependency - , typename D6 = NullType // Type of the sixth lifetime dependency - , typename D7 = NullType // Type of the seventh lifetime dependency - , typename D8 = NullType > // Type of the eighth lifetime dependency +template< typename T > // Type of the singleton class Singleton : private NonCopyable { -public: - //**Type definitions**************************************************************************** - //! Type list of all lifetime dependencies. - typedef WALBERLA_TYPELIST_8( D1, D2, D3, D4, D5, D6, D7, D8 ) Dependencies; - //******************************************************************************************************************* - protected: //**Constructor****************************************************************************************************** /*!\brief Constructor for the Singleton class. @@ -457,119 +70,9 @@ protected: // In case a cyclic lifetime dependency is detected, a compilation error is created. */ explicit Singleton() - : dependency1_( D1::instance() ) // Handle to the first lifetime dependency - , dependency2_( D2::instance() ) // Handle to the second lifetime dependency - , dependency3_( D3::instance() ) // Handle to the third lifetime dependency - , dependency4_( D4::instance() ) // Handle to the fourth lifetime dependency - , dependency5_( D5::instance() ) // Handle to the fifth lifetime dependency - , dependency6_( D6::instance() ) // Handle to the sixth lifetime dependency - , dependency7_( D7::instance() ) // Handle to the seventh lifetime dependency - , dependency8_( D8::instance() ) // Handle to the eighth lifetime dependency - { - WALBERLA_DETECT_CYCLIC_LIFETIME_DEPENDENCY( D1 ); - WALBERLA_DETECT_CYCLIC_LIFETIME_DEPENDENCY( D2 ); - WALBERLA_DETECT_CYCLIC_LIFETIME_DEPENDENCY( D3 ); - WALBERLA_DETECT_CYCLIC_LIFETIME_DEPENDENCY( D4 ); - WALBERLA_DETECT_CYCLIC_LIFETIME_DEPENDENCY( D5 ); - WALBERLA_DETECT_CYCLIC_LIFETIME_DEPENDENCY( D6 ); - WALBERLA_DETECT_CYCLIC_LIFETIME_DEPENDENCY( D7 ); - WALBERLA_DETECT_CYCLIC_LIFETIME_DEPENDENCY( D8 ); - } - //******************************************************************************************************************* - - //**Destructor******************************************************************************************************* - /*!\brief Destructor for the Singleton class. - */ - ~Singleton() {} //******************************************************************************************************************* -public: - //**Instance function*************************************************************************** - /*!\name Instance function */ - //@{ - static const shared_ptr<T>& instance() - { - std::lock_guard<std::mutex> lock( instanceMutex_ ); - static shared_ptr<T> object( new T() ); - isInstantiated_ = true; - return object; - } - //@} - //******************************************************************************************************************* - - static bool isInstantiated() { return isInstantiated_; } - -private: - //**Member variables**************************************************************************** - /*!\name Member variables */ - //@{ - shared_ptr<D1> dependency1_; //!< Handle to the first lifetime dependency. - shared_ptr<D2> dependency2_; //!< Handle to the second lifetime dependency. - shared_ptr<D3> dependency3_; //!< Handle to the third lifetime dependency. - shared_ptr<D4> dependency4_; //!< Handle to the fourth lifetime dependency. - shared_ptr<D5> dependency5_; //!< Handle to the fifth lifetime dependency. - shared_ptr<D6> dependency6_; //!< Handle to the sixth lifetime dependency. - shared_ptr<D7> dependency7_; //!< Handle to the seventh lifetime dependency. - shared_ptr<D8> dependency8_; //!< Handle to the eighth lifetime dependency. - - static std::mutex instanceMutex_; //!< Synchronization mutex for access to the singleton. - - static bool isInstantiated_; - //@} - //******************************************************************************************************************* -}; -//********************************************************************************************************************** - - -//====================================================================================================================== -// -// SINGLETON SPECIALIZATION (7 LIFETIME DEPENDENCIES) -// -//====================================================================================================================== - -//********************************************************************************************************************** -template< typename T // Type of the singleton (CRTP pattern) - , typename D1 // Type of the first lifetime dependency - , typename D2 // Type of the second lifetime dependency - , typename D3 // Type of the third lifetime dependency - , typename D4 // Type of the fourth lifetime dependency - , typename D5 // Type of the fifth lifetime dependency - , typename D6 // Type of the sixth lifetime dependency - , typename D7 > // Type of the eighth lifetime dependency -class Singleton<T,D1,D2,D3,D4,D5,D6,D7,NullType> : private NonCopyable -{ -public: - //**Type definitions**************************************************************************** - //! Type list of all lifetime dependencies. - typedef WALBERLA_TYPELIST_7( D1, D2, D3, D4, D5, D6, D7 ) Dependencies; - //******************************************************************************************************************* - -protected: - //**Constructor****************************************************************************************************** - /*!\brief Constructor for the Singleton class. - // - // In case a cyclic lifetime dependency is detected, a compilation error is created. - */ - explicit Singleton() - : dependency1_( D1::instance() ) // Handle to the first lifetime dependency - , dependency2_( D2::instance() ) // Handle to the second lifetime dependency - , dependency3_( D3::instance() ) // Handle to the third lifetime dependency - , dependency4_( D4::instance() ) // Handle to the fourth lifetime dependency - , dependency5_( D5::instance() ) // Handle to the fifth lifetime dependency - , dependency6_( D6::instance() ) // Handle to the sixth lifetime dependency - , dependency7_( D7::instance() ) // Handle to the seventh lifetime dependency - { - WALBERLA_DETECT_CYCLIC_LIFETIME_DEPENDENCY( D1 ); - WALBERLA_DETECT_CYCLIC_LIFETIME_DEPENDENCY( D2 ); - WALBERLA_DETECT_CYCLIC_LIFETIME_DEPENDENCY( D3 ); - WALBERLA_DETECT_CYCLIC_LIFETIME_DEPENDENCY( D4 ); - WALBERLA_DETECT_CYCLIC_LIFETIME_DEPENDENCY( D5 ); - WALBERLA_DETECT_CYCLIC_LIFETIME_DEPENDENCY( D6 ); - WALBERLA_DETECT_CYCLIC_LIFETIME_DEPENDENCY( D7 ); - } - //******************************************************************************************************************* - //**Destructor******************************************************************************************************* /*!\brief Destructor for the Singleton class. */ @@ -597,16 +100,8 @@ private: //**Member variables**************************************************************************** /*!\name Member variables */ //@{ - shared_ptr<D1> dependency1_; //!< Handle to the first lifetime dependency. - shared_ptr<D2> dependency2_; //!< Handle to the second lifetime dependency. - shared_ptr<D3> dependency3_; //!< Handle to the third lifetime dependency. - shared_ptr<D4> dependency4_; //!< Handle to the fourth lifetime dependency. - shared_ptr<D5> dependency5_; //!< Handle to the fifth lifetime dependency. - shared_ptr<D6> dependency6_; //!< Handle to the sixth lifetime dependency. - shared_ptr<D7> dependency7_; //!< Handle to the seventh lifetime dependency. - static std::mutex instanceMutex_; //!< Synchronization mutex for access to the singleton. - + static bool isInstantiated_; //@} //******************************************************************************************************************* @@ -617,615 +112,17 @@ private: //====================================================================================================================== // -// SINGLETON SPECIALIZATION (6 LIFETIME DEPENDENCIES) +// DEFINITION AND INITIALIZATION OF THE STATIC MEMBER VARIABLES // //====================================================================================================================== -//********************************************************************************************************************** -template< typename T // Type of the singleton (CRTP pattern) - , typename D1 // Type of the first lifetime dependency - , typename D2 // Type of the second lifetime dependency - , typename D3 // Type of the third lifetime dependency - , typename D4 // Type of the fourth lifetime dependency - , typename D5 // Type of the fifth lifetime dependency - , typename D6 > // Type of the eighth lifetime dependency -class Singleton<T,D1,D2,D3,D4,D5,D6,NullType,NullType> : private NonCopyable -{ -public: - //**Type definitions**************************************************************************** - //! Type list of all lifetime dependencies. - typedef WALBERLA_TYPELIST_6( D1, D2, D3, D4, D5, D6 ) Dependencies; - //******************************************************************************************************************* - -protected: - //**Constructor****************************************************************************************************** - /*!\brief Constructor for the Singleton class. - // - // In case a cyclic lifetime dependency is detected, a compilation error is created. - */ - explicit Singleton() - : dependency1_( D1::instance() ) // Handle to the first lifetime dependency - , dependency2_( D2::instance() ) // Handle to the second lifetime dependency - , dependency3_( D3::instance() ) // Handle to the third lifetime dependency - , dependency4_( D4::instance() ) // Handle to the fourth lifetime dependency - , dependency5_( D5::instance() ) // Handle to the fifth lifetime dependency - , dependency6_( D6::instance() ) // Handle to the sixth lifetime dependency - { - WALBERLA_DETECT_CYCLIC_LIFETIME_DEPENDENCY( D1 ); - WALBERLA_DETECT_CYCLIC_LIFETIME_DEPENDENCY( D2 ); - WALBERLA_DETECT_CYCLIC_LIFETIME_DEPENDENCY( D3 ); - WALBERLA_DETECT_CYCLIC_LIFETIME_DEPENDENCY( D4 ); - WALBERLA_DETECT_CYCLIC_LIFETIME_DEPENDENCY( D5 ); - WALBERLA_DETECT_CYCLIC_LIFETIME_DEPENDENCY( D6 ); - } - //******************************************************************************************************************* - - //**Destructor******************************************************************************************************* - /*!\brief Destructor for the Singleton class. - */ - ~Singleton() - {} - //******************************************************************************************************************* - -public: - //**Instance function*************************************************************************** - /*!\name Instance function */ - //@{ - static const shared_ptr<T>& instance() - { - std::lock_guard<std::mutex> lock( instanceMutex_ ); - static shared_ptr<T> object( new T() ); - isInstantiated_ = true; - return object; - } - //@} - //******************************************************************************************************************* - - static bool isInstantiated() { return isInstantiated_; } - -private: - //**Member variables**************************************************************************** - /*!\name Member variables */ - //@{ - shared_ptr<D1> dependency1_; //!< Handle to the first lifetime dependency. - shared_ptr<D2> dependency2_; //!< Handle to the second lifetime dependency. - shared_ptr<D3> dependency3_; //!< Handle to the third lifetime dependency. - shared_ptr<D4> dependency4_; //!< Handle to the fourth lifetime dependency. - shared_ptr<D5> dependency5_; //!< Handle to the fifth lifetime dependency. - shared_ptr<D6> dependency6_; //!< Handle to the sixth lifetime dependency. - - static std::mutex instanceMutex_; //!< Synchronization mutex for access to the singleton. - - static bool isInstantiated_; - //@} - //******************************************************************************************************************* -}; -//********************************************************************************************************************** - - - -//====================================================================================================================== -// -// SINGLETON SPECIALIZATION (5 LIFETIME DEPENDENCIES) -// -//====================================================================================================================== - -//********************************************************************************************************************** -template< typename T // Type of the singleton (CRTP pattern) - , typename D1 // Type of the first lifetime dependency - , typename D2 // Type of the second lifetime dependency - , typename D3 // Type of the third lifetime dependency - , typename D4 // Type of the fourth lifetime dependency - , typename D5 > // Type of the fifth lifetime dependency -class Singleton<T,D1,D2,D3,D4,D5,NullType,NullType,NullType> : private NonCopyable -{ -public: - //**Type definitions**************************************************************************** - //! Type list of all lifetime dependencies. - typedef WALBERLA_TYPELIST_5( D1, D2, D3, D4, D5 ) Dependencies; - //******************************************************************************************************************* - -protected: - //**Constructor****************************************************************************************************** - /*!\brief Constructor for the Singleton class. - // - // In case a cyclic lifetime dependency is detected, a compilation error is created. - */ - explicit Singleton() - : dependency1_( D1::instance() ) // Handle to the first lifetime dependency - , dependency2_( D2::instance() ) // Handle to the second lifetime dependency - , dependency3_( D3::instance() ) // Handle to the third lifetime dependency - , dependency4_( D4::instance() ) // Handle to the fourth lifetime dependency - , dependency5_( D5::instance() ) // Handle to the fifth lifetime dependency - { - WALBERLA_DETECT_CYCLIC_LIFETIME_DEPENDENCY( D1 ); - WALBERLA_DETECT_CYCLIC_LIFETIME_DEPENDENCY( D2 ); - WALBERLA_DETECT_CYCLIC_LIFETIME_DEPENDENCY( D3 ); - WALBERLA_DETECT_CYCLIC_LIFETIME_DEPENDENCY( D4 ); - WALBERLA_DETECT_CYCLIC_LIFETIME_DEPENDENCY( D5 ); - } - //******************************************************************************************************************* - - //**Destructor******************************************************************************************************* - /*!\brief Destructor for the Singleton class. - */ - ~Singleton() - {} - //******************************************************************************************************************* - -public: - //**Instance function*************************************************************************** - /*!\name Instance function */ - //@{ - static const shared_ptr<T>& instance() - { - std::lock_guard<std::mutex> lock( instanceMutex_ ); - static shared_ptr<T> object( new T() ); - isInstantiated_ = true; - return object; - } - //@} - //******************************************************************************************************************* - - static bool isInstantiated() { return isInstantiated_; } - -private: - //**Member variables**************************************************************************** - /*!\name Member variables */ - //@{ - shared_ptr<D1> dependency1_; //!< Handle to the first lifetime dependency. - shared_ptr<D2> dependency2_; //!< Handle to the second lifetime dependency. - shared_ptr<D3> dependency3_; //!< Handle to the third lifetime dependency. - shared_ptr<D4> dependency4_; //!< Handle to the fourth lifetime dependency. - shared_ptr<D5> dependency5_; //!< Handle to the fifth lifetime dependency. - - static std::mutex instanceMutex_; //!< Synchronization mutex for access to the singleton. - - static bool isInstantiated_; - //@} - //******************************************************************************************************************* -}; -//********************************************************************************************************************** - - - -//====================================================================================================================== -// -// SINGLETON SPECIALIZATION (4 LIFETIME DEPENDENCIES) -// -//====================================================================================================================== - -//********************************************************************************************************************** -template< typename T // Type of the singleton (CRTP pattern) - , typename D1 // Type of the first lifetime dependency - , typename D2 // Type of the second lifetime dependency - , typename D3 // Type of the third lifetime dependency - , typename D4 > // Type of the fourth lifetime dependency -class Singleton<T,D1,D2,D3,D4,NullType,NullType,NullType,NullType> : private NonCopyable -{ -public: - //**Type definitions**************************************************************************** - //! Type list of all lifetime dependencies. - typedef WALBERLA_TYPELIST_4( D1, D2, D3, D4 ) Dependencies; - //******************************************************************************************************************* - -protected: - //**Constructor****************************************************************************************************** - /*!\brief Constructor for the Singleton class. - // - // In case a cyclic lifetime dependency is detected, a compilation error is created. - */ - explicit Singleton() - : dependency1_( D1::instance() ) // Handle to the first lifetime dependency - , dependency2_( D2::instance() ) // Handle to the second lifetime dependency - , dependency3_( D3::instance() ) // Handle to the third lifetime dependency - , dependency4_( D4::instance() ) // Handle to the fourth lifetime dependency - { - WALBERLA_DETECT_CYCLIC_LIFETIME_DEPENDENCY( D1 ); - WALBERLA_DETECT_CYCLIC_LIFETIME_DEPENDENCY( D2 ); - WALBERLA_DETECT_CYCLIC_LIFETIME_DEPENDENCY( D3 ); - WALBERLA_DETECT_CYCLIC_LIFETIME_DEPENDENCY( D4 ); - } - //******************************************************************************************************************* - - //**Destructor******************************************************************************************************* - /*!\brief Destructor for the Singleton class. - */ - ~Singleton() - {} - //******************************************************************************************************************* - -public: - //**Instance function*************************************************************************** - /*!\name Instance function */ - //@{ - static const shared_ptr<T>& instance() - { - std::lock_guard<std::mutex> lock( instanceMutex_ ); - static shared_ptr<T> object( new T() ); - isInstantiated_ = true; - return object; - } - //@} - //******************************************************************************************************************* - - static bool isInstantiated() { return isInstantiated_; } - -private: - //**Member variables**************************************************************************** - /*!\name Member variables */ - //@{ - shared_ptr<D1> dependency1_; //!< Handle to the first lifetime dependency. - shared_ptr<D2> dependency2_; //!< Handle to the second lifetime dependency. - shared_ptr<D3> dependency3_; //!< Handle to the third lifetime dependency. - shared_ptr<D4> dependency4_; //!< Handle to the fourth lifetime dependency. - - static std::mutex instanceMutex_; //!< Synchronization mutex for access to the singleton. - - static bool isInstantiated_; - //@} - //******************************************************************************************************************* -}; -//********************************************************************************************************************** - - - -//====================================================================================================================== -// -// SINGLETON SPECIALIZATION (3 LIFETIME DEPENDENCIES) -// -//====================================================================================================================== - -//********************************************************************************************************************** -template< typename T // Type of the singleton (CRTP pattern) - , typename D1 // Type of the first lifetime dependency - , typename D2 // Type of the second lifetime dependency - , typename D3 > // Type of the third lifetime dependency -class Singleton<T,D1,D2,D3,NullType,NullType,NullType,NullType,NullType> : private NonCopyable -{ -public: - //**Type definitions**************************************************************************** - //! Type list of all lifetime dependencies. - typedef WALBERLA_TYPELIST_3( D1, D2, D3 ) Dependencies; - //******************************************************************************************************************* - -protected: - //**Constructor****************************************************************************************************** - /*!\brief Constructor for the Singleton class. - // - // In case a cyclic lifetime dependency is detected, a compilation error is created. - */ - explicit Singleton() - : dependency1_( D1::instance() ) // Handle to the first lifetime dependency - , dependency2_( D2::instance() ) // Handle to the second lifetime dependency - , dependency3_( D3::instance() ) // Handle to the third lifetime dependency - { - WALBERLA_DETECT_CYCLIC_LIFETIME_DEPENDENCY( D1 ); - WALBERLA_DETECT_CYCLIC_LIFETIME_DEPENDENCY( D2 ); - WALBERLA_DETECT_CYCLIC_LIFETIME_DEPENDENCY( D3 ); - } - //******************************************************************************************************************* - - //**Destructor******************************************************************************************************* - /*!\brief Destructor for the Singleton class. - */ - ~Singleton() - {} - //******************************************************************************************************************* - -public: - //**Instance function*************************************************************************** - /*!\name Instance function */ - //@{ - static const shared_ptr<T>& instance() - { - std::lock_guard<std::mutex> lock( instanceMutex_ ); - static shared_ptr<T> object( new T() ); - isInstantiated_ = true; - return object; - } - //@} - //******************************************************************************************************************* - - static bool isInstantiated() { return isInstantiated_; } - -private: - //**Member variables**************************************************************************** - /*!\name Member variables */ - //@{ - shared_ptr<D1> dependency1_; //!< Handle to the first lifetime dependency. - shared_ptr<D2> dependency2_; //!< Handle to the second lifetime dependency. - shared_ptr<D3> dependency3_; //!< Handle to the third lifetime dependency. - - static std::mutex instanceMutex_; //!< Synchronization mutex for access to the singleton. - - static bool isInstantiated_; - //@} - //******************************************************************************************************************* -}; -//********************************************************************************************************************** - - - -//====================================================================================================================== -// -// SINGLETON SPECIALIZATION (2 LIFETIME DEPENDENCIES) -// -//====================================================================================================================== - -//********************************************************************************************************************** -template< typename T // Type of the singleton (CRTP pattern) - , typename D1 // Type of the first lifetime dependency - , typename D2 > // Type of the second lifetime dependency -class Singleton<T,D1,D2,NullType,NullType,NullType,NullType,NullType,NullType> : private NonCopyable -{ -public: - //**Type definitions**************************************************************************** - //! Type list of all lifetime dependencies. - typedef WALBERLA_TYPELIST_2( D1, D2 ) Dependencies; - //******************************************************************************************************************* - -protected: - //**Constructor****************************************************************************************************** - /*!\brief Constructor for the Singleton class. - // - // In case a cyclic lifetime dependency is detected, a compilation error is created. - */ - explicit Singleton() - : dependency1_( D1::instance() ) // Handle to the first lifetime dependency - , dependency2_( D2::instance() ) // Handle to the second lifetime dependency - { - WALBERLA_DETECT_CYCLIC_LIFETIME_DEPENDENCY( D1 ); - WALBERLA_DETECT_CYCLIC_LIFETIME_DEPENDENCY( D2 ); - } - //******************************************************************************************************************* - - //**Destructor******************************************************************************************************* - /*!\brief Destructor for the Singleton class. - */ - ~Singleton() - {} - //******************************************************************************************************************* - -public: - //**Instance function*************************************************************************** - /*!\name Instance function */ - //@{ - static const shared_ptr<T>& instance() - { - std::lock_guard<std::mutex> lock( instanceMutex_ ); - static shared_ptr<T> object( new T() ); - isInstantiated_ = true; - return object; - } - //@} - //******************************************************************************************************************* - - static bool isInstantiated() { return isInstantiated_; } - -private: - //**Member variables**************************************************************************** - /*!\name Member variables */ - //@{ - shared_ptr<D1> dependency1_; //!< Handle to the first lifetime dependency. - shared_ptr<D2> dependency2_; //!< Handle to the second lifetime dependency. - - static std::mutex instanceMutex_; //!< Synchronization mutex for access to the singleton. - - static bool isInstantiated_; - //@} - //******************************************************************************************************************* -}; -//********************************************************************************************************************** - - - -//====================================================================================================================== -// -// SINGLETON SPECIALIZATION (1 LIFETIME DEPENDENCY) -// -//====================================================================================================================== - -//********************************************************************************************************************** -template< typename T // Type of the singleton (CRTP pattern) - , typename D1 > // Type of the lifetime dependency -class Singleton<T,D1,NullType,NullType,NullType,NullType,NullType,NullType,NullType> : private NonCopyable -{ -public: - //**Type definitions**************************************************************************** - //! Type list of all lifetime dependencies. - typedef WALBERLA_TYPELIST_1( D1 ) Dependencies; - //******************************************************************************************************************* - -protected: - //**Constructor****************************************************************************************************** - /*!\brief Constructor for the Singleton class. - // - // In case a cyclic lifetime dependency is detected, a compilation error is created. - */ - explicit Singleton() - : dependency1_( D1::instance() ) // Handle to the lifetime dependency - { - WALBERLA_DETECT_CYCLIC_LIFETIME_DEPENDENCY( D1 ); - } - //******************************************************************************************************************* - - //**Destructor******************************************************************************************************* - /*!\brief Destructor for the Singleton class. - */ - ~Singleton() - {} - //******************************************************************************************************************* - -public: - //**Instance function*************************************************************************** - /*!\name Instance function */ - //@{ - static const shared_ptr<T>& instance() - { - std::lock_guard<std::mutex> lock( instanceMutex_ ); - static shared_ptr<T> object( new T() ); - isInstantiated_ = true; - return object; - } - //@} - //******************************************************************************************************************* - - static bool isInstantiated() { return isInstantiated_; } - -private: - //**Member variables**************************************************************************** - /*!\name Member variables */ - //@{ - shared_ptr<D1> dependency1_; //!< Handle to the lifetime dependency. - - static std::mutex instanceMutex_; //!< Synchronization mutex for access to the singleton. - - static bool isInstantiated_; - //@} - //******************************************************************************************************************* -}; -//********************************************************************************************************************** - - -#undef WALBERLA_DETECT_CYCLIC_LIFETIME_DEPENDENCY -#undef WALBERLA_JOIN -#undef WALBERLA_DO_JOIN -#undef WALBERLA_DO_JOIN2 - - -//====================================================================================================================== -// -// SINGLETON SPECIALIZATION (0 LIFETIME DEPENDENCIES) -// -//====================================================================================================================== - -//********************************************************************************************************************** -template< typename T > // Type of the singleton (CRTP pattern) -class Singleton<T,NullType,NullType,NullType,NullType,NullType,NullType,NullType,NullType> : private NonCopyable -{ -public: - //**Type definitions**************************************************************************** - //! Type list of all lifetime dependencies. - typedef NullType Dependencies; - //******************************************************************************************************************* - -protected: - //**Constructor****************************************************************************************************** - /*!\brief Constructor for the Singleton class. - // - // In case a cyclic lifetime dependency is detected, a compilation error is created. - */ - explicit Singleton() - {} - //******************************************************************************************************************* - - //**Destructor******************************************************************************************************* - /*!\brief Destructor for the Singleton class. - */ - ~Singleton() - {} - //******************************************************************************************************************* - -public: - //**Instance function*************************************************************************** - /*!\name Instance function */ - //@{ - static const shared_ptr<T>& instance() - { - std::lock_guard<std::mutex> lock( instanceMutex_ ); - static shared_ptr<T> object( new T() ); - isInstantiated_ = true; - return object; - } - //@} - //******************************************************************************************************************* - - static bool isInstantiated() { return isInstantiated_; } - -private: - //**Member variables**************************************************************************** - /*!\name Member variables */ - //@{ - static std::mutex instanceMutex_; //!< Synchronization mutex for access to the singleton. - - static bool isInstantiated_; - //@} - //******************************************************************************************************************* -}; -//********************************************************************************************************************** - - - -//====================================================================================================================== -// -// DEFINITION AND INITIALIZATION OF THE STATIC MEMBER VARIABLES -// -//====================================================================================================================== - -template< typename T, typename A, typename B, typename C, typename D, typename E, typename F, typename G, typename H > -std::mutex Singleton<T,A,B,C,D,E,F,G,H>::instanceMutex_; - -template< typename T, typename A, typename B, typename C, typename D, typename E, typename F, typename G, typename H > -bool Singleton<T,A,B,C,D,E,F,G,H>::isInstantiated_ = false; - -template< typename T, typename A, typename B, typename C, typename D, typename E, typename F, typename G > -std::mutex Singleton<T,A,B,C,D,E,F,G,NullType>::instanceMutex_; - -template< typename T, typename A, typename B, typename C, typename D, typename E, typename F, typename G > -bool Singleton<T,A,B,C,D,E,F,G,NullType>::isInstantiated_ = false; - -template< typename T, typename A, typename B, typename C, typename D, typename E, typename F > -std::mutex Singleton<T,A,B,C,D,E,F,NullType,NullType>::instanceMutex_; - -template< typename T, typename A, typename B, typename C, typename D, typename E, typename F > -bool Singleton<T,A,B,C,D,E,F,NullType,NullType>::isInstantiated_ = false; - -template< typename T, typename A, typename B, typename C, typename D, typename E > -std::mutex Singleton<T,A,B,C,D,E,NullType,NullType,NullType>::instanceMutex_; - -template< typename T, typename A, typename B, typename C, typename D, typename E > -bool Singleton<T,A,B,C,D,E,NullType,NullType,NullType>::isInstantiated_ = false; - -template< typename T, typename A, typename B, typename C, typename D > -std::mutex Singleton<T,A,B,C,D,NullType,NullType,NullType,NullType>::instanceMutex_; - -template< typename T, typename A, typename B, typename C, typename D > -bool Singleton<T,A,B,C,D,NullType,NullType,NullType,NullType>::isInstantiated_ = false; - -template< typename T, typename A, typename B, typename C > -std::mutex Singleton<T,A,B,C,NullType,NullType,NullType,NullType,NullType>::instanceMutex_; - -template< typename T, typename A, typename B, typename C > -bool Singleton<T,A,B,C,NullType,NullType,NullType,NullType,NullType>::isInstantiated_ = false; - -template< typename T, typename A, typename B > -std::mutex Singleton<T,A,B,NullType,NullType,NullType,NullType,NullType,NullType>::instanceMutex_; - -template< typename T, typename A, typename B > -bool Singleton<T,A,B,NullType,NullType,NullType,NullType,NullType,NullType>::isInstantiated_ = false; - -template< typename T, typename A > -std::mutex Singleton<T,A,NullType,NullType,NullType,NullType,NullType,NullType,NullType>::instanceMutex_; - -template< typename T, typename A > -bool Singleton<T,A,NullType,NullType,NullType,NullType,NullType,NullType,NullType>::isInstantiated_ = false; - -template< typename T > -std::mutex Singleton<T,NullType,NullType,NullType,NullType,NullType,NullType,NullType,NullType>::instanceMutex_; +template< typename T > +std::mutex Singleton<T>::instanceMutex_; template< typename T > -bool Singleton<T,NullType,NullType,NullType,NullType,NullType,NullType,NullType,NullType>::isInstantiated_ = false; - - +bool Singleton<T>::isInstantiated_ = false; -#ifdef WALBERLA_CXX_COMPILER_IS_GNU -#pragma GCC diagnostic pop -#endif -#ifdef WALBERLA_CXX_COMPILER_IS_CLANG -#pragma clang diagnostic pop -#endif } // namespace singleton } // namespace walberla diff --git a/src/core/singleton/TypeList.h b/src/core/singleton/TypeList.h deleted file mode 100644 index 53dc703e67541b634b1579d92a9252b9a90aae77..0000000000000000000000000000000000000000 --- a/src/core/singleton/TypeList.h +++ /dev/null @@ -1,743 +0,0 @@ -//====================================================================================================================== -// -// This file is part of waLBerla. waLBerla is free software: you can -// redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of -// the License, or (at your option) any later version. -// -// waLBerla is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -// for more details. -// -// You should have received a copy of the GNU General Public License along -// with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. -// -//! \file TypeList.h -//! \ingroup core -//! \author Klaus Iglberger -// -//====================================================================================================================== - -#pragma once - -#include "NullType.h" - -#include <cstdlib> - - -namespace walberla { -namespace singleton { - - - -//====================================================================================================================== -// -// CLASS TYPELIST -// -//====================================================================================================================== - -//********************************************************************************************************************** -/*!\brief Implementation of a type list. -// -// Type lists provide the functionality to create lists of data types. In contrast to lists -// of data values (as for instance the std::list class template), type lists are created at -// compile time, not at run time. This type list implementation closely resembles the original -// implementation of Andrei Alexandrescu (taken from his book Modern C++, ISBN: 0201704315). -// The following example demonstrates, how type lists are created and manipulated: - -\code -// Creating a type list consisting of two fundamental floating point data types -typedef WALBERLA_TYPELIST_2( float, double ) Tmp; - -// Appending a type to the type list -typedef walberla::singleton::Append< Tmp, long double >::Result Floats; // Type list containing all floating point data types - -// Calculating the length of the type list (at compile time!) -const int length = Length< Floats >::value; // Value evaluates to 3 - -// Accessing a specific type of the type list via indexing -typedef walberla::singleton::TypeAt< Floats, 0 >::Result Index0; - -// Searching the type list for a specific type -const int index1 = walberla::singleton::Contains< Floats, double >::value; // Value evaluates to 1 -const int index2 = walberla::singleton::Contains< Floats, int >::value; // Value evaluates to 0 - -// Determining the index of a specific type in the type list -const int index3 = walberla::singleton::IndexOf< Floats, double >::value; // Value evaluates to 1 -const int index4 = walberla::singleton::IndexOf< Floats, int >::value; // Value evaluates to -1 -\endcode - -// The type list merely consists of the two data types \a Head and \a Tail. In order to create -// type lists of more data types, the TypeList class is used recursively: - -\code -// Type list containing the three fundamental floating point data types -TypeList< float, TypeList< double, TypeList< long double, NullType > > > -\endcode - -// The NullType data type is used to terminate a type list.\n -// In order to create a type list, one of the predefined setup macros should be used: - -\code -// Creating a type list consisting of the three fundamental data types -typedef WALBERLA_TYPELIST_3( float, double, long double ) Floats; -\endcode - */ -template< typename H // Head of the type list - , typename T > // Tail of the type list -struct TypeList -{ - //**Type definitions**************************************************************************** - typedef H Head; //!< Type of the head of the type list. - typedef T Tail; //!< Type of the tail of the type list. - //******************************************************************************************************************* -}; -//********************************************************************************************************************** - - - -//====================================================================================================================== -// -// TYPE LIST GENERATION MACROS -// -//====================================================================================================================== - -//********************************************************************************************************************** -/*!\brief Type list generation macro. -// -// This macro creates a type list only consisting of the type \a T1. The terminating type for -// the type list is the NullType. The following example demonstrates the use of this macro: - -\code -// Definition of a new type list consisting of a single data type -typedef WALBERLA_TYPELIST_1( int ) MyTypes; - -// Calculating the length of the type list -const int length = Length<MyTypes>::value; -\endcode - */ -#define WALBERLA_TYPELIST_1( T1 ) \ -TypeList< T1, NullType > -//********************************************************************************************************************** - - - -//********************************************************************************************************************** -/*!\brief Type list generation macro. -// -// This macro creates a type list consisting of the two types \a T1 and \a T2. The terminating -// type for the type list is the NullType. The following example demonstrates the use of this -// macro: - -\code -// Definition of a new type list consisting of two data types -typedef WALBERLA_TYPELIST_2( int, unsigned int ) MyTypes; - -// Calculating the length of the type list -const int length = Length<MyTypes>::value; -\endcode - */ -#define WALBERLA_TYPELIST_2( T1, T2 ) \ -TypeList< T1, WALBERLA_TYPELIST_1( T2 ) > -//********************************************************************************************************************** - - - -//********************************************************************************************************************** -/*!\brief Type list generation macro. -// -// This macro creates a type list consisting of the three types \a T1, \a T2 and \a T3. The -// terminating type for the type list is the NullType. The following example demonstrates -// the use of this macro: - -\code -// Definition of a new type list consisting of three data types -typedef WALBERLA_TYPELIST_3( float, double, long double ) MyTypes; - -// Calculating the length of the type list -const int length = Length<MyTypes>::value; -\endcode - */ -#define WALBERLA_TYPELIST_3( T1, T2, T3 ) \ -TypeList< T1, WALBERLA_TYPELIST_2( T2, T3 ) > -//********************************************************************************************************************** - - - -//********************************************************************************************************************** -/*!\brief Type list generation macro. -// -// This macro creates a type list consisting of the four types \a T1, \a T2, \a T3 and \a T4. -// The terminating type for the type list is the NullType. The following example demonstrates -// the use of this macro: - -\code -// Definition of a new type list consisting of four data types -typedef WALBERLA_TYPELIST_4( unsigned char, signed char, char, wchar_t ) MyTypes; - -// Calculating the length of the type list -const int length = Length<MyTypes>::value; -\endcode - */ -#define WALBERLA_TYPELIST_4( T1, T2, T3, T4 ) \ -TypeList< T1, WALBERLA_TYPELIST_3( T2, T3, T4 ) > -//********************************************************************************************************************** - - - -//********************************************************************************************************************** -/*!\brief Type list generation macro. -// -// This macro creates a type list consisting of the five types \a T1, \a T2, \a T3, \a T4 -// and \a T5. The terminating type for the type list is the NullType. The following example -// demonstrates the use of this macro: - -\code -// Definition of a new type list consisting of five data types -typedef WALBERLA_TYPELIST_5( char, short, int, long, float ) MyTypes; - -// Calculating the length of the type list -const int length = Length<MyTypes>::value; -\endcode - */ -#define WALBERLA_TYPELIST_5( T1, T2, T3, T4, T5 ) \ -TypeList< T1, WALBERLA_TYPELIST_4( T2, T3, T4, T5 ) > -//********************************************************************************************************************** - - - -//********************************************************************************************************************** -/*!\brief Type list generation macro. -// -// This macro creates a type list consisting of the six types \a T1, \a T2, \a T3, \a T4, \a T5 -// and \a T6. The terminating type for the type list is the NullType. The following example -// demonstrates the use of this macro: - -\code -// Definition of a new type list consisting of six data types -typedef WALBERLA_TYPELIST_6( char, short, int, long, float, double ) MyTypes; - -// Calculating the length of the type list -const int length = Length<MyTypes>::value; -\endcode - */ -#define WALBERLA_TYPELIST_6( T1, T2, T3, T4, T5, T6 ) \ -TypeList< T1, WALBERLA_TYPELIST_5( T2, T3, T4, T5, T6 ) > -//********************************************************************************************************************** - - - -//********************************************************************************************************************** -/*!\brief Type list generation macro. -// -// This macro creates a type list consisting of the seven types \a T1, \a T2, \a T3, \a T4, -// \a T5, \a T6 and \a T7. The terminating type for the type list is the NullType. The -// following example demonstrates the use of this macro: - -\code -// Definition of a new type list consisting of seven data types -typedef WALBERLA_TYPELIST_7( char, short, int, long, float, double, long double ) MyTypes; - -// Calculating the length of the type list -const int length = Length<MyTypes>::value; -\endcode - */ -#define WALBERLA_TYPELIST_7( T1, T2, T3, T4, T5, T6, T7 ) \ -TypeList< T1, WALBERLA_TYPELIST_6( T2, T3, T4, T5, T6, T7 ) > -//********************************************************************************************************************** - - - -//********************************************************************************************************************** -/*!\brief Type list generation macro. -// -// This macro creates a type list consisting of the eight types \a T1, \a T2, \a T3, \a T4, -// \a T5, \a T6, \a T7 and \a T8. The terminating type for the type list is the NullType. -// The following example demonstrates the use of this macro: - -\code -// Definition of a new type list consisting of eight data types -typedef WALBERLA_TYPELIST_8( char, wchar_t, short, int, long, float, double, long double ) MyTypes; - -// Calculating the length of the type list -const int length = Length<MyTypes>::value; -\endcode - */ -#define WALBERLA_TYPELIST_8( T1, T2, T3, T4, T5, T6, T7, T8 ) \ -TypeList< T1, WALBERLA_TYPELIST_7( T2, T3, T4, T5, T6, T7, T8 ) > -//********************************************************************************************************************** - - - -//********************************************************************************************************************** -/*!\brief Type list generation macro. -// -// This macro creates a type list consisting of the nine types \a T1, \a T2, \a T3, \a T4, -// \a T5, \a T6, \a T7, \a T8 and \a T9. The terminating type for the type list is the NullType. -// The following example demonstrates the use of this macro: - -\code -// Definition of a new type list consisting of nine data types -typedef WALBERLA_TYPELIST_9( char, signed char, wchar_t, short, int, long, float, double, long double ) MyTypes; - -// Calculating the length of the type list -const int length = Length<MyTypes>::value; -\endcode - */ -#define WALBERLA_TYPELIST_9( T1, T2, T3, T4, T5, T6, T7, T8, T9 ) \ -TypeList< T1, WALBERLA_TYPELIST_8( T2, T3, T4, T5, T6, T7, T8, T9 ) > -//********************************************************************************************************************** - - - -//********************************************************************************************************************** -/*!\brief Type list generation macro. -// -// This macro creates a type list consisting of the ten types \a T1, \a T2, \a T3, \a T4, -// \a T5, \a T6, \a T7, \a T8, \a T9 and \a T10. The terminating type for the type list is -// the NullType. The following example demonstrates the use of this macro: - -\code -// Definition of a new type list consisting of ten data types -typedef WALBERLA_TYPELIST_10( unsigned char, signed char, char, wchar_t, unsigned short, -short, unsigned int, int, unsigned long, long ) MyTypes; - -// Calculating the length of the type list -const int length = Length<MyTypes>::value; -\endcode - */ -#define WALBERLA_TYPELIST_10( T1, T2, T3, T4, T5, T6, T7, T8, T9, T10 ) \ -TypeList< T1, WALBERLA_TYPELIST_9( T2, T3, T4, T5, T6, T7, T8, T9, T10 ) > -//********************************************************************************************************************** - - - -//====================================================================================================================== -// -// LENGTH OF A TYPE LIST -// -//====================================================================================================================== - -//********************************************************************************************************************** -/*!\class Length -// \brief Calculating the length of a type list. -// -// The Length class can be used to obtain the length of a type list (i.e. the number -// contained types). In order to obtain the length of a type list, the Length class -// has to be instantiated for a particular type list. The length of the type list can -// be obtained using the member enumeration \a value. The following example gives an -// impression of the use of the Length class: - -\code -typedef WALBERLA_TYPELIST_3( float, double, long double ) Floats; // Defining a new type list -const int length = walberla::singleton::Length< Floats >::value; // The length of the type list -\endcode - */ -template< typename TList > // Type of the type list -struct Length; -//********************************************************************************************************************** - - - -//********************************************************************************************************************** -/// Spezialization of the Length class for empty type lists. -template<> -struct Length< NullType > -{ - //**Member enumeration************************************************************************** - enum { value = 0 }; - //******************************************************************************************************************* -}; -//********************************************************************************************************************** - - - -//********************************************************************************************************************** -/// Specialization of the Length class for general type lists. -template< typename Head // Type of the head of the type list - , typename Tail > // Type of the tail of the type list -struct Length< TypeList<Head,Tail> > -{ - //**Member enumeration************************************************************************** - enum { value = 1 + Length<Tail>::value }; - //******************************************************************************************************************* -}; -//********************************************************************************************************************** - - - -//====================================================================================================================== -// -// INDEXED ACCESS -// -//====================================================================================================================== - -//********************************************************************************************************************** -/*!\class TypeAt -// \brief Indexing a type list. -// -// The TypeAt class can be used to access a type list at a specified position to query the -// according type. In order to index a type list, the TypeAt class has to be instantiated -// for a particular type list and an index value. The indexed type is available via the -// member type definition \a Result. The following example gives an impression of the use -// of the TypeAt class: - -\code -typedef WALBERLA_TYPELIST_3( float, double, long double ) Floats; // Defining a new type list -typedef walberla::singleton::TypeAt< Floats, 0 >::Result Index0; // Indexing of the type list at index 0 -\endcode - -// \b Note: The access index is zero based! - */ -template< typename TList // Type of the type list - , size_t Index > // Type list access index -struct TypeAt; -//********************************************************************************************************************** - - - -//********************************************************************************************************************** -/// Specialization of the TypeAt class for an index of 0. -template< typename Head // Type of the head of the type list - , typename Tail > // Type of the tail of the type list -struct TypeAt< TypeList<Head,Tail>, 0 > -{ - //**Member enumeration************************************************************************** - typedef Head Result; //!< Data type at index 0. - //******************************************************************************************************************* -}; -//********************************************************************************************************************** - - - -//********************************************************************************************************************** -/// Specialization of the TypeAt class for a general index. -template< typename Head // Type of the head of the type list - , typename Tail // Type of the tail of the type list - , size_t Index > // Type list access index -struct TypeAt< TypeList<Head,Tail>, Index > -{ - //**Member enumeration************************************************************************** - typedef typename TypeAt< Tail, Index-1 >::Result Result; //!< Data type at indexed position. - //******************************************************************************************************************* -}; -//********************************************************************************************************************** - - - -//====================================================================================================================== -// -// TYPE LIST SEARCH -// -//====================================================================================================================== - -//********************************************************************************************************************** -/*!\class Contains -// \brief Searching a type list. -// -// The Contains class can be used to search the type list for a particular type \a Type. In -// contrast to the IndexOf class, the Contains class does not evaluate the index of the type -// but only checks whether or not the type is contained in the type list. Additionally, in -// contrast to the ContainsRelated class, the Contains class strictly searches for the given -// type \a Type and not for a related data type. In case the type is contained in the type -// list, the \a value member enumeration is set to 1, else it is set to 0. In order to check -// whether a type is part of a type list, the Contains class has to be instantiated for a -// particular type list and another type. The following example gives an impression of the -// use of the Contains class: - -\code -typedef WALBERLA_TYPELIST_3( float, double, long double ) Floats; // Defining a new type list -const int index1 = walberla::singleton::Contains< Floats, double >::value; // Value evaluates to 1 -const int index2 = walberla::singleton::Contains< Floats, int >::value; // Value evaluates to 0 -\endcode - */ -template< typename TList // Type of the type list - , typename Type > // The search type -struct Contains; -//********************************************************************************************************************** - - - -//********************************************************************************************************************** -/// Specialization of the Contains class for the terminating NullType. -template< typename Type > // The search type -struct Contains< NullType, Type > -{ - //**Member enumeration************************************************************************** - enum { value = 0 }; //!< \a Type is not contained in the type list. - //******************************************************************************************************************* -}; -//********************************************************************************************************************** - - - -//********************************************************************************************************************** -/// Specialization of the Contains class for a successful search. -template< typename Tail // Type of the tail of the type list - , typename Type > // The search type -struct Contains< TypeList<Type,Tail>, Type > -{ - //**Member enumeration************************************************************************** - enum { value = 1 }; //!< \a Type is the head of the type list. - //******************************************************************************************************************* -}; -//********************************************************************************************************************** - - - -//********************************************************************************************************************** -/// Specialization of the Contains class for a general type list. -template< typename Head // Type of the head of the type list - , typename Tail // Type of the tail of the type list - , typename Type > // The search type -struct Contains< TypeList<Head,Tail>, Type > -{ - //**Member enumeration************************************************************************** - enum { value = Contains<Tail,Type>::value }; //!< Search result for type \a Type. - //******************************************************************************************************************* -}; -//********************************************************************************************************************** - - - -//********************************************************************************************************************** -/*!\class ContainsRelated -// \brief Searching a type list. -// -// The ContainsRelated class can be used to search the type list for a type related to \a Type. -// In contrast to the Contains class, the ContainsRelated class only searches for a type the -// given data type \a Type can be converted to. In case a related type is found in the type -// list, the \a value member enumeration is set to 1, else it is set to 0. In order to check -// whether a related type is contained in the type list, the ContainsRelated class has to be -// instantiated for a particular type list and another type. The following example gives an -// impression of the use of the ContainsRelated class: - -\code -class A {}; -class B : public A {}; -class C {}; -class D {}; - -// Defining a new type list -typedef WALBERLA_TYPELIST_2( A, C ) Types; - -// Searching for the type A in the type list -const int a = walberla::singleton::ContainsRelated< Types, A >::value; // Evaluates to 1, type A is found - -// Searching for the derived type B in the type list -const int b = walberla::singleton::ContainsRelated< Types, B >::value; // Evaluates to 1, base type A is found - -// Searching for the type C in the type list -const int c = walberla::singleton::ContainsRelated< Types, D >::value; // Evaluates to 0, no related type found -\endcode - */ -template< typename TList // Type of the type list - , typename Type > // The search type -struct ContainsRelated; -//********************************************************************************************************************** - - - -//********************************************************************************************************************** -/// Spezialization of the ContainsRelated class for the terminating NullType. -template< typename Type > // The search type -struct ContainsRelated< NullType, Type > -{ - //**Member enumeration************************************************************************** - enum { value = 0 }; //!< No related type of \a Type is contained in the type list. - //******************************************************************************************************************* -}; -//********************************************************************************************************************** - - - -//********************************************************************************************************************** -/// Spezialization of the ContainsRelated class for a general type list. -template< typename Head // Type of the head of the type list - , typename Tail // Type of the tail of the type list - , typename Type > // The search type -struct ContainsRelated< TypeList<Head,Tail>, Type > -{ -private: - //******************************************************************************************************************* - class No {}; - class Yes { No no[2]; }; - //******************************************************************************************************************* - - //******************************************************************************************************************* - static Yes test( Head ); - static No test( ... ); - static Type createType(); - //******************************************************************************************************************* - - //**Member enumeration************************************************************************** - enum { tmp = sizeof( test( createType() ) ) == sizeof( Yes ) ? 1 : 0 }; //!< Relationship evaluation. - //******************************************************************************************************************* - -public: - //**Member enumeration************************************************************************** - enum { value = tmp == 1 ? 1 : ( ContainsRelated<Tail,Type>::value ) }; //!< Search result for type \a Type. - //******************************************************************************************************************* -}; -//********************************************************************************************************************** - - - -//********************************************************************************************************************** -/*!\class IndexOf -// \brief Searching a type list. -// -// The IndexOf class can be used to search the type list for a particular type \a Type. In -// contrast to the Contains and the ContainsRelated classes, the IndexOf class evaluates the -// index of the given type in the type list. In case the type is contained in the type list, -// the \a value member represents the index of the queried type. Otherwise the \a value member -// is set to -1. In order to search for a type, the IndexOf class has to be instantiated for -// a particular type list and a search type. The following example gives an impression of the -// use of the IndexOf class: - -\code -typedef WALBERLA_TYPELIST_3( float, double, long double ) Floats; // Defining a new type list -const int index1 = walberla::singleton::IndexOf< Floats, double >::value; // Value evaluates to 1 -const int index2 = walberla::singleton::IndexOf< Floats, int >::value; // Value evaluates to -1 -\endcode - */ -template< typename TList // Type of the type list - , typename Type > // The search type -struct IndexOf; -//********************************************************************************************************************** - - - -//********************************************************************************************************************** -/// Spezialization of the IndexOf class for the terminating NullType. -template< typename Type > // The search type -struct IndexOf< NullType, Type > -{ - //**Member enumeration************************************************************************** - enum { value = -1 }; //!< \a Type is not contained in the type list. - //******************************************************************************************************************* -}; -//********************************************************************************************************************** - - - -//********************************************************************************************************************** -/// Spezialization of the IndexOf class for a successful search. -template< typename Tail // Type of the tail of the type list - , typename Type > // The search type -struct IndexOf< TypeList<Type,Tail>, Type > -{ - //**Member enumeration************************************************************************** - enum { value = 0 }; //!< \a Type is the head of the type list. - //******************************************************************************************************************* -}; -//********************************************************************************************************************** - - - -//********************************************************************************************************************** -/// Spezialization of the IndexOf class for a general type list. -template< typename Head // Type of the head of the type list - , typename Tail // Type of the tail of the type list - , typename Type > // The search type -struct IndexOf< TypeList<Head,Tail>, Type > -{ -private: - //**Member enumeration************************************************************************** - enum { tmp = IndexOf<Tail,Type>::value }; //!< Index of \a Type in the tail of the type list. - //******************************************************************************************************************* - -public: - //**Member enumeration************************************************************************** - enum { value = tmp == -1 ? -1 : 1 + tmp }; //!< Index of \a Type in the entire type list. - //******************************************************************************************************************* -}; -//********************************************************************************************************************** - - - -//====================================================================================================================== -// -// APPENDING TO TYPE LISTS -// -//====================================================================================================================== - -//********************************************************************************************************************** -/*!\class Append -// \brief Appending a type to a type list. -// -// The Append class can be used to append the data type \a Type to a type list \a TList. In -// order to append a data type, the Append class has to be instantiated for a particular type -// list and another type. The following example gives an impression of the use of the Append -// class: - -\code -typedef WALBERLA_TYPELIST_3( float, double ) Temp; // Defining a temporary type list -typedef walberla::singleton::Append<Temp,long double>::Result Floats; // Type list contained all floating point data types -\endcode - */ -template< typename TList // Type of the type list - , typename Type > // The type to be appended to the type list -struct Append; -//********************************************************************************************************************** - - - -//********************************************************************************************************************** -/// Spezialization of the Append class for appending the NullType. -template<> -struct Append< NullType, NullType > -{ - //**Type definitions**************************************************************************** - typedef NullType Result; //!< The resulting data type. - //******************************************************************************************************************* -}; -//********************************************************************************************************************** - - - -//********************************************************************************************************************** -/// Spezialization of the Append class for appending a general type to the NullType. -template< typename Type > // The type to be appended to the type list -struct Append< NullType, Type > -{ - //**Type definitions**************************************************************************** - typedef WALBERLA_TYPELIST_1( Type ) Result; //!< The resulting data type. - //******************************************************************************************************************* -}; -//********************************************************************************************************************** - - - -//********************************************************************************************************************** -/// Spezialization of the Append class for appending a type list to the NullType. -template< typename Head // Type of the head of the type list - , typename Tail > // Type of the tail of the type list -struct Append< NullType, TypeList<Head,Tail> > -{ - //**Type definitions**************************************************************************** - typedef TypeList<Head,Tail> Result; //!< The resulting data type. - //******************************************************************************************************************* -}; -//********************************************************************************************************************** - - - -//********************************************************************************************************************** -/// Spezialization of the Append class for appending a general type to a type list. -template< typename Head // Type of the head of the type list - , typename Tail // Type of the tail of the type list - , typename Type > // The type to be appended to the type list -struct Append< TypeList<Head,Tail>, Type > -{ - //**Type definitions**************************************************************************** - typedef TypeList< Head, typename Append<Tail,Type>::Result > Result; //!< The resulting data type. - //******************************************************************************************************************* -}; -//********************************************************************************************************************** - - - -} // namespace singleton -} // namespace walberla