35 #ifndef _BLAZE_UTIL_SINGLETON_SINGLETON_H_
36 #define _BLAZE_UTIL_SINGLETON_SINGLETON_H_
43 #include <boost/shared_ptr.hpp>
44 #include <boost/thread/mutex.hpp>
60 template<
typename >
class Dependency;
83 struct HasCyclicDependencyHelper;
98 struct HasCyclicDependencyHelper<TL,
NullType,N>
114 template<
typename TL
116 struct HasCyclicDependencyHelper<TL,D,1>
118 typedef typename TypeAt<D,0>::Result D1;
120 enum { value = HasCyclicDependency<D1,TL,Contains<TL,D1>::value>::value };
134 template<
typename TL
136 struct HasCyclicDependencyHelper<TL,D,2>
138 typedef typename TypeAt<D,0>::Result D1;
139 typedef typename TypeAt<D,1>::Result D2;
141 enum { value = HasCyclicDependency<D1,TL,Contains<TL,D1>::value>::value ||
142 HasCyclicDependency<D2,TL,Contains<TL,D2>::value>::value };
156 template<
typename TL
158 struct HasCyclicDependencyHelper<TL,D,3>
160 typedef typename TypeAt<D,0>::Result D1;
161 typedef typename TypeAt<D,1>::Result D2;
162 typedef typename TypeAt<D,2>::Result D3;
164 enum { value = HasCyclicDependency<D1,TL,Contains<TL,D1>::value>::value ||
165 HasCyclicDependency<D2,TL,Contains<TL,D2>::value>::value ||
166 HasCyclicDependency<D3,TL,Contains<TL,D3>::value>::value };
180 template<
typename TL
182 struct HasCyclicDependencyHelper<TL,D,4>
184 typedef typename TypeAt<D,0>::Result D1;
185 typedef typename TypeAt<D,1>::Result D2;
186 typedef typename TypeAt<D,2>::Result D3;
187 typedef typename TypeAt<D,3>::Result D4;
189 enum { value = HasCyclicDependency<D1,TL,Contains<TL,D1>::value>::value ||
190 HasCyclicDependency<D2,TL,Contains<TL,D2>::value>::value ||
191 HasCyclicDependency<D3,TL,Contains<TL,D3>::value>::value ||
192 HasCyclicDependency<D4,TL,Contains<TL,D4>::value>::value };
206 template<
typename TL
208 struct HasCyclicDependencyHelper<TL,D,5>
210 typedef typename TypeAt<D,0>::Result D1;
211 typedef typename TypeAt<D,1>::Result D2;
212 typedef typename TypeAt<D,2>::Result D3;
213 typedef typename TypeAt<D,3>::Result D4;
214 typedef typename TypeAt<D,4>::Result D5;
216 enum { value = HasCyclicDependency<D1,TL,Contains<TL,D1>::value>::value ||
217 HasCyclicDependency<D2,TL,Contains<TL,D2>::value>::value ||
218 HasCyclicDependency<D3,TL,Contains<TL,D3>::value>::value ||
219 HasCyclicDependency<D4,TL,Contains<TL,D4>::value>::value ||
220 HasCyclicDependency<D5,TL,Contains<TL,D5>::value>::value };
234 template<
typename TL
236 struct HasCyclicDependencyHelper<TL,D,6>
238 typedef typename TypeAt<D,0>::Result D1;
239 typedef typename TypeAt<D,1>::Result D2;
240 typedef typename TypeAt<D,2>::Result D3;
241 typedef typename TypeAt<D,3>::Result D4;
242 typedef typename TypeAt<D,4>::Result D5;
243 typedef typename TypeAt<D,5>::Result D6;
245 enum { value = HasCyclicDependency<D1,TL,Contains<TL,D1>::value>::value ||
246 HasCyclicDependency<D2,TL,Contains<TL,D2>::value>::value ||
247 HasCyclicDependency<D3,TL,Contains<TL,D3>::value>::value ||
248 HasCyclicDependency<D4,TL,Contains<TL,D4>::value>::value ||
249 HasCyclicDependency<D5,TL,Contains<TL,D5>::value>::value ||
250 HasCyclicDependency<D6,TL,Contains<TL,D6>::value>::value };
264 template<
typename TL
266 struct HasCyclicDependencyHelper<TL,D,7>
268 typedef typename TypeAt<D,0>::Result D1;
269 typedef typename TypeAt<D,1>::Result D2;
270 typedef typename TypeAt<D,2>::Result D3;
271 typedef typename TypeAt<D,3>::Result D4;
272 typedef typename TypeAt<D,4>::Result D5;
273 typedef typename TypeAt<D,5>::Result D6;
274 typedef typename TypeAt<D,6>::Result D7;
276 enum { value = HasCyclicDependency<D1,TL,Contains<TL,D1>::value>::value ||
277 HasCyclicDependency<D2,TL,Contains<TL,D2>::value>::value ||
278 HasCyclicDependency<D3,TL,Contains<TL,D3>::value>::value ||
279 HasCyclicDependency<D4,TL,Contains<TL,D4>::value>::value ||
280 HasCyclicDependency<D5,TL,Contains<TL,D5>::value>::value ||
281 HasCyclicDependency<D6,TL,Contains<TL,D6>::value>::value ||
282 HasCyclicDependency<D7,TL,Contains<TL,D7>::value>::value };
296 template<
typename TL
298 struct HasCyclicDependencyHelper<TL,D,8>
300 typedef typename TypeAt<D,0>::Result D1;
301 typedef typename TypeAt<D,1>::Result D2;
302 typedef typename TypeAt<D,2>::Result D3;
303 typedef typename TypeAt<D,3>::Result D4;
304 typedef typename TypeAt<D,4>::Result D5;
305 typedef typename TypeAt<D,5>::Result D6;
306 typedef typename TypeAt<D,6>::Result D7;
307 typedef typename TypeAt<D,7>::Result D8;
309 enum { value = HasCyclicDependency<D1,TL,Contains<TL,D1>::value>::value ||
310 HasCyclicDependency<D2,TL,Contains<TL,D2>::value>::value ||
311 HasCyclicDependency<D3,TL,Contains<TL,D3>::value>::value ||
312 HasCyclicDependency<D4,TL,Contains<TL,D4>::value>::value ||
313 HasCyclicDependency<D5,TL,Contains<TL,D5>::value>::value ||
314 HasCyclicDependency<D6,TL,Contains<TL,D6>::value>::value ||
315 HasCyclicDependency<D7,TL,Contains<TL,D7>::value>::value ||
316 HasCyclicDependency<D8,TL,Contains<TL,D8>::value>::value };
341 ,
bool C=Contains<TL,T>::value >
342 struct HasCyclicDependency
344 typedef typename Append<TL,T>::Result ETL;
345 enum { value = HasCyclicDependencyHelper<ETL,typename T::Dependencies>::value };
362 struct HasCyclicDependency<T,TL,true>
389 template<
int >
struct CYCLIC_LIFETIME_DEPENDENCY_TEST {};
412 template<
bool >
struct CYCLIC_LIFETIME_DEPENDENCY_DETECTED;
413 template<>
struct CYCLIC_LIFETIME_DEPENDENCY_DETECTED<false> {
enum { value = 1 }; };
424 #define BLAZE_DETECT_CYCLIC_LIFETIME_DEPENDENCY(T) \
426 blaze::CYCLIC_LIFETIME_DEPENDENCY_TEST< \
427 blaze::CYCLIC_LIFETIME_DEPENDENCY_DETECTED< blaze::HasCyclicDependency<T,blaze::NullType>::value >::value > \
428 BLAZE_JOIN( DETECT_CYCLIC_LIFETIME_DEPENDENCY_TYPEDEF, __LINE__ )
447 #define BLAZE_BEFRIEND_SINGLETON \
448 template< typename, typename, typename, typename, typename, typename, typename, typename, typename > friend class blaze::Singleton; \
449 template< typename, typename, bool > friend struct blaze::HasCyclicDependency; \
450 template< typename > friend class blaze::Dependency;
598 ,
typename D1 = NullType
599 ,
typename D2 = NullType
600 ,
typename D3 = NullType
601 ,
typename D4 = NullType
602 ,
typename D5 = NullType
603 ,
typename D6 = NullType
604 ,
typename D7 = NullType
605 ,
typename D8 = NullType >
664 static boost::shared_ptr<T> instance()
667 static boost::shared_ptr<T> object(
new T() );
778 static boost::shared_ptr<T> instance()
781 static boost::shared_ptr<T> object(
new T() );
836 class Singleton<T,D1,D2,D3,D4,D5,D6,NullType,NullType> :
private NonCopyable
841 typedef Singleton<T,D1,D2,D3,D4,D5,D6,NullType,NullType>
SingletonType;
888 static boost::shared_ptr<T> instance()
891 static boost::shared_ptr<T> object(
new T() );
944 class Singleton<T,D1,D2,D3,D4,D5,NullType,NullType,NullType> :
private NonCopyable
949 typedef Singleton<T,D1,D2,D3,D4,D5,NullType,NullType,NullType>
SingletonType;
993 static boost::shared_ptr<T> instance()
996 static boost::shared_ptr<T> object(
new T() );
1042 template<
typename T
1047 class Singleton<T,D1,D2,D3,D4,NullType,NullType,NullType,NullType> :
private NonCopyable
1052 typedef Singleton<T,D1,D2,D3,D4,NullType,NullType,NullType,NullType>
SingletonType;
1093 static boost::shared_ptr<T> instance()
1096 static boost::shared_ptr<T> object(
new T() );
1141 template<
typename T
1145 class Singleton<T,D1,D2,D3,NullType,NullType,NullType,NullType,NullType> :
private NonCopyable
1150 typedef Singleton<T,D1,D2,D3,NullType,NullType,NullType,NullType,NullType>
SingletonType;
1188 static boost::shared_ptr<T> instance()
1191 static boost::shared_ptr<T> object(
new T() );
1235 template<
typename T
1238 class Singleton<T,D1,D2,NullType,NullType,NullType,NullType,NullType,NullType> :
private NonCopyable
1243 typedef Singleton<T,D1,D2,NullType,NullType,NullType,NullType,NullType,NullType>
SingletonType;
1278 static boost::shared_ptr<T> instance()
1281 static boost::shared_ptr<T> object(
new T() );
1324 template<
typename T
1326 class Singleton<T,D1,NullType,NullType,NullType,NullType,NullType,NullType,NullType> :
private NonCopyable
1331 typedef Singleton<T,D1,NullType,NullType,NullType,NullType,NullType,NullType,NullType>
SingletonType;
1363 static boost::shared_ptr<T> instance()
1366 static boost::shared_ptr<T> object(
new T() );
1408 template<
typename T >
1409 class Singleton<T,NullType,NullType,NullType,NullType,NullType,NullType,NullType,NullType> :
private NonCopyable
1414 typedef Singleton<T,NullType,NullType,NullType,NullType,NullType,NullType,NullType,NullType>
SingletonType;
1417 typedef NullType Dependencies;
1443 static boost::shared_ptr<T> instance()
1446 static boost::shared_ptr<T> object(
new T() );
1472 template<
typename T
1481 boost::mutex Singleton<T,A,B,C,D,E,F,G,H>::instanceMutex_;
1483 template<
typename T
1491 boost::mutex Singleton<T,A,B,C,D,E,F,G,NullType>::instanceMutex_;
1493 template<
typename T
1500 boost::mutex Singleton<T,A,B,C,D,E,F,NullType,NullType>::instanceMutex_;
1502 template<
typename T
1508 boost::mutex Singleton<T,A,B,C,D,E,NullType,NullType,NullType>::instanceMutex_;
1510 template<
typename T
1515 boost::mutex Singleton<T,A,B,C,D,NullType,NullType,NullType,NullType>::instanceMutex_;
1517 template<
typename T
1521 boost::mutex Singleton<T,A,B,C,NullType,NullType,NullType,NullType,NullType>::instanceMutex_;
1523 template<
typename T
1526 boost::mutex Singleton<T,A,B,NullType,NullType,NullType,NullType,NullType,NullType>::instanceMutex_;
1528 template<
typename T
1530 boost::mutex Singleton<T,A,NullType,NullType,NullType,NullType,NullType,NullType,NullType>::instanceMutex_;
1532 template<
typename T >
1533 boost::mutex Singleton<T,NullType,NullType,NullType,NullType,NullType,NullType,NullType,NullType>::instanceMutex_;
boost::shared_ptr< D1 > dependency1_
Handle to the first lifetime dependency.
Definition: Singleton.h:677
#define BLAZE_TYPELIST_3(T1, T2, T3)
Type list generation macro.This macro creates a type list consisting of the three types T1...
Definition: TypeList.h:191
boost::shared_ptr< D3 > dependency3_
Handle to the third lifetime dependency.
Definition: Singleton.h:679
Utility type for generic codes.
#define BLAZE_TYPELIST_6(T1, T2, T3, T4, T5, T6)
Type list generation macro.This macro creates a type list consisting of the six types T1...
Definition: TypeList.h:254
boost::shared_ptr< D2 > dependency2_
Handle to the second lifetime dependency.
Definition: Singleton.h:678
Base class for non-copyable class instances.
static boost::mutex instanceMutex_
Synchronization mutex for access to the singleton.
Definition: Singleton.h:692
typedef BLAZE_TYPELIST_8(D1, D2, D3, D4, D5, D6, D7, D8) Dependencies
Type list of all lifetime dependencies.
boost::shared_ptr< D4 > dependency4_
Handle to the fourth lifetime dependency.
Definition: Singleton.h:680
~Singleton()
Destructor for the Singleton class.
Definition: Singleton.h:656
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
#define BLAZE_TYPELIST_1(T1)
Type list generation macro.This macro creates a type list only consisting of the type T1...
Definition: TypeList.h:149
#define BLAZE_TYPELIST_7(T1, T2, T3, T4, T5, T6, T7)
Type list generation macro.This macro creates a type list consisting of the seven types T1...
Definition: TypeList.h:275
#define BLAZE_CONSTRAINT_MUST_BE_DERIVED_FROM(D, B)
Constraint on the inheritance relationship of a data type.In case D is not derived from B...
Definition: DerivedFrom.h:78
#define BLAZE_TYPELIST_2(T1, T2)
Type list generation macro.This macro creates a type list consisting of the two types T1 and T2...
Definition: TypeList.h:170
Base class for non-copyable class instances.The NonCopyable class is intended to work as a base class...
Definition: NonCopyable.h:63
Constraint on the inheritance relationship of a data type.
boost::shared_ptr< D5 > dependency5_
Handle to the fifth lifetime dependency.
Definition: Singleton.h:681
Calculating the length of a type list.The Length class can be used to obtain the length of a type lis...
Definition: TypeList.h:369
boost::shared_ptr< D7 > dependency7_
Handle to the seventh lifetime dependency.
Definition: Singleton.h:683
Base class for all lifetime managed singletons.The Singleton class represents the base class for all ...
Definition: Singleton.h:606
boost::shared_ptr< D6 > dependency6_
Handle to the sixth lifetime dependency.
Definition: Singleton.h:682
#define BLAZE_TYPELIST_5(T1, T2, T3, T4, T5)
Type list generation macro.This macro creates a type list consisting of the five types T1...
Definition: TypeList.h:233
Header file for a type list implementation.
Utility type for generic codes.The NullType class represents an invalid or terminating data type for ...
Definition: NullType.h:54
Singleton< T, D1, D2, D3, D4, D5, D6, D7, D8 > SingletonType
Type of this Singleton instance.
Definition: Singleton.h:611
boost::shared_ptr< D8 > dependency8_
Handle to the eighth lifetime dependency.
Definition: Singleton.h:684
#define BLAZE_TYPELIST_4(T1, T2, T3, T4)
Type list generation macro.This macro creates a type list consisting of the four types T1...
Definition: TypeList.h:212
Definition: Singleton.h:61
#define BLAZE_DETECT_CYCLIC_LIFETIME_DEPENDENCY(T)
Constraint on the data type.In case the given data type T is not an integral data type...
Definition: Singleton.h:424
Singleton()
Constructor for the Singleton class.
Definition: Singleton.h:623
Header file for compile time constraints.