35#ifndef _BLAZE_UTIL_SINGLETON_SINGLETON_H_
36#define _BLAZE_UTIL_SINGLETON_SINGLETON_H_
61template<
typename >
class Dependency;
83 ,
size_t N = Length_v<D> >
84struct HasCyclicDependencyHelper;
99struct HasCyclicDependencyHelper<TL,
NullType,N>
101 static constexpr bool value =
false;
117struct HasCyclicDependencyHelper<TL,D,1>
137struct HasCyclicDependencyHelper<TL,D,2>
139 using D1 = TypeAt_t<D,0>;
140 using D2 = TypeAt_t<D,1>;
142 static constexpr bool value = ( HasCyclicDependency<D1,TL,Contains_v<TL,D1>>::value ||
143 HasCyclicDependency<D2,TL,Contains_v<TL,D2>>::value );
159struct HasCyclicDependencyHelper<TL,D,3>
161 using D1 = TypeAt_t<D,0>;
162 using D2 = TypeAt_t<D,1>;
163 using D3 = TypeAt_t<D,2>;
165 static constexpr bool value = ( HasCyclicDependency<D1,TL,Contains_v<TL,D1>>::value ||
166 HasCyclicDependency<D2,TL,Contains_v<TL,D2>>::value ||
167 HasCyclicDependency<D3,TL,Contains_v<TL,D3>>::value );
183struct HasCyclicDependencyHelper<TL,D,4>
185 using D1 = TypeAt_t<D,0>;
186 using D2 = TypeAt_t<D,1>;
187 using D3 = TypeAt_t<D,2>;
188 using D4 = TypeAt_t<D,3>;
190 static constexpr bool value = ( HasCyclicDependency<D1,TL,Contains_v<TL,D1>>::value ||
191 HasCyclicDependency<D2,TL,Contains_v<TL,D2>>::value ||
192 HasCyclicDependency<D3,TL,Contains_v<TL,D3>>::value ||
193 HasCyclicDependency<D4,TL,Contains_v<TL,D4>>::value );
209struct HasCyclicDependencyHelper<TL,D,5>
211 using D1 = TypeAt_t<D,0>;
212 using D2 = TypeAt_t<D,1>;
213 using D3 = TypeAt_t<D,2>;
214 using D4 = TypeAt_t<D,3>;
215 using D5 = TypeAt_t<D,4>;
217 static constexpr bool value = ( HasCyclicDependency<D1,TL,Contains_v<TL,D1>>::value ||
218 HasCyclicDependency<D2,TL,Contains_v<TL,D2>>::value ||
219 HasCyclicDependency<D3,TL,Contains_v<TL,D3>>::value ||
220 HasCyclicDependency<D4,TL,Contains_v<TL,D4>>::value ||
221 HasCyclicDependency<D5,TL,Contains_v<TL,D5>>::value );
237struct HasCyclicDependencyHelper<TL,D,6>
239 using D1 = TypeAt_t<D,0>;
240 using D2 = TypeAt_t<D,1>;
241 using D3 = TypeAt_t<D,2>;
242 using D4 = TypeAt_t<D,3>;
243 using D5 = TypeAt_t<D,4>;
244 using D6 = TypeAt_t<D,5>;
246 static constexpr bool value = ( HasCyclicDependency<D1,TL,Contains_v<TL,D1>>::value ||
247 HasCyclicDependency<D2,TL,Contains_v<TL,D2>>::value ||
248 HasCyclicDependency<D3,TL,Contains_v<TL,D3>>::value ||
249 HasCyclicDependency<D4,TL,Contains_v<TL,D4>>::value ||
250 HasCyclicDependency<D5,TL,Contains_v<TL,D5>>::value ||
251 HasCyclicDependency<D6,TL,Contains_v<TL,D6>>::value );
267struct HasCyclicDependencyHelper<TL,D,7>
269 using D1 = TypeAt_t<D,0>;
270 using D2 = TypeAt_t<D,1>;
271 using D3 = TypeAt_t<D,2>;
272 using D4 = TypeAt_t<D,3>;
273 using D5 = TypeAt_t<D,4>;
274 using D6 = TypeAt_t<D,5>;
275 using D7 = TypeAt_t<D,6>;
277 static constexpr bool value = ( HasCyclicDependency<D1,TL,Contains_v<TL,D1>>::value ||
278 HasCyclicDependency<D2,TL,Contains_v<TL,D2>>::value ||
279 HasCyclicDependency<D3,TL,Contains_v<TL,D3>>::value ||
280 HasCyclicDependency<D4,TL,Contains_v<TL,D4>>::value ||
281 HasCyclicDependency<D5,TL,Contains_v<TL,D5>>::value ||
282 HasCyclicDependency<D6,TL,Contains_v<TL,D6>>::value ||
283 HasCyclicDependency<D7,TL,Contains_v<TL,D7>>::value );
299struct HasCyclicDependencyHelper<TL,D,8>
301 using D1 = TypeAt_t<D,0>;
302 using D2 = TypeAt_t<D,1>;
303 using D3 = TypeAt_t<D,2>;
304 using D4 = TypeAt_t<D,3>;
305 using D5 = TypeAt_t<D,4>;
306 using D6 = TypeAt_t<D,5>;
307 using D7 = TypeAt_t<D,6>;
308 using D8 = TypeAt_t<D,7>;
310 static constexpr bool value = ( HasCyclicDependency<D1,TL,Contains_v<TL,D1>>::value ||
311 HasCyclicDependency<D2,TL,Contains_v<TL,D2>>::value ||
312 HasCyclicDependency<D3,TL,Contains_v<TL,D3>>::value ||
313 HasCyclicDependency<D4,TL,Contains_v<TL,D4>>::value ||
314 HasCyclicDependency<D5,TL,Contains_v<TL,D5>>::value ||
315 HasCyclicDependency<D6,TL,Contains_v<TL,D6>>::value ||
316 HasCyclicDependency<D7,TL,Contains_v<TL,D7>>::value ||
317 HasCyclicDependency<D8,TL,Contains_v<TL,D8>>::value );
342 ,
bool C = Contains_v<TL,T> >
343struct HasCyclicDependency
344 :
public BoolConstant< HasCyclicDependencyHelper<Append_t<TL,T>,typename T::Dependencies>::value >
361struct HasCyclicDependency<T,TL,true>
382#define BLAZE_DETECT_CYCLIC_LIFETIME_DEPENDENCY(T) \
383 static_assert( ( !blaze::HasCyclicDependency<T,blaze::NullType>::value ), "Cyclic dependency detected" )
402#define BLAZE_BEFRIEND_SINGLETON \
403 template< typename, typename, typename, typename, typename, typename, typename, typename, typename > friend class blaze::Singleton; \
404 template< typename, typename, bool > friend struct blaze::HasCyclicDependency; \
405 template< typename > friend class blaze::Dependency;
552 ,
typename D1 = NullType
553 ,
typename D2 = NullType
554 ,
typename D3 = NullType
555 ,
typename D4 = NullType
556 ,
typename D5 = NullType
557 ,
typename D6 = NullType
558 ,
typename D7 = NullType
559 ,
typename D8 = NullType >
619 static std::shared_ptr<T> instance()
621 static std::shared_ptr<T> object(
new T() );
725 static std::shared_ptr<T> instance()
727 static std::shared_ptr<T> object(
new T() );
774class Singleton<T,D1,D2,D3,D4,D5,D6,NullType,NullType>
775 :
private NonCopyable
780 using SingletonType = Singleton<T,D1,D2,D3,D4,D5,D6,NullType,NullType>;
783 using Dependencies = TypeList< D1, D2, D3, D4, D5, D6 >;
827 static std::shared_ptr<T> instance()
829 static std::shared_ptr<T> object(
new T() );
874class Singleton<T,D1,D2,D3,D4,D5,NullType,NullType,NullType>
875 :
private NonCopyable
880 using SingletonType = Singleton<T,D1,D2,D3,D4,D5,NullType,NullType,NullType>;
924 static std::shared_ptr<T> instance()
926 static std::shared_ptr<T> object(
new T() );
969class Singleton<T,D1,D2,D3,D4,NullType,NullType,NullType,NullType>
970 :
private NonCopyable
975 using SingletonType = Singleton<T,D1,D2,D3,D4,NullType,NullType,NullType,NullType>;
1016 static std::shared_ptr<T> instance()
1018 static std::shared_ptr<T> object(
new T() );
1059class Singleton<T,D1,D2,D3,NullType,NullType,NullType,NullType,NullType>
1060 :
private NonCopyable
1065 using SingletonType = Singleton<T,D1,D2,D3,NullType,NullType,NullType,NullType,NullType>;
1103 static std::shared_ptr<T> instance()
1105 static std::shared_ptr<T> object(
new T() );
1144class Singleton<T,D1,D2,NullType,NullType,NullType,NullType,NullType,NullType>
1145 :
private NonCopyable
1150 using SingletonType = Singleton<T,D1,D2,NullType,NullType,NullType,NullType,NullType,NullType>;
1185 static std::shared_ptr<T> instance()
1187 static std::shared_ptr<T> object(
new T() );
1224class Singleton<T,D1,NullType,NullType,NullType,NullType,NullType,NullType,NullType>
1225 :
private NonCopyable
1230 using SingletonType = Singleton<T,D1,NullType,NullType,NullType,NullType,NullType,NullType,NullType>;
1262 static std::shared_ptr<T> instance()
1264 static std::shared_ptr<T> object(
new T() );
1298template<
typename T >
1299class Singleton<T,NullType,NullType,NullType,NullType,NullType,NullType,NullType,NullType>
1300 :
private NonCopyable
1305 using SingletonType = Singleton<T,NullType,NullType,NullType,NullType,NullType,NullType,NullType,NullType>;
1334 static std::shared_ptr<T> instance()
1336 static std::shared_ptr<T> object(
new T() );
Constraint on the inheritance relationship of a data type.
Header file for the IntegralConstant class template.
Base class for non-copyable class instances.
Utility type for generic codes.
Header file for compile time constraints.
Header file for the type list functionality.
Base class for non-copyable class instances.
Definition: NonCopyable.h:64
Utility type for generic codes.
Definition: NullType.h:55
Base class for all lifetime managed singletons.
Definition: Singleton.h:562
Singleton()
Constructor for the Singleton class.
Definition: Singleton.h:578
std::shared_ptr< D6 > dependency6_
Handle to the sixth lifetime dependency.
Definition: Singleton.h:636
std::shared_ptr< D1 > dependency1_
Handle to the first lifetime dependency.
Definition: Singleton.h:631
std::shared_ptr< D7 > dependency7_
Handle to the seventh lifetime dependency.
Definition: Singleton.h:637
std::shared_ptr< D2 > dependency2_
Handle to the second lifetime dependency.
Definition: Singleton.h:632
TypeList< D1, D2, D3, D4, D5, D6, D7, D8 > Dependencies
Type list of all lifetime dependencies.
Definition: Singleton.h:569
Singleton< T, D1, D2, D3, D4, D5, D6, D7, D8 > SingletonType
Type of this Singleton instance.
Definition: Singleton.h:566
std::shared_ptr< D4 > dependency4_
Handle to the fourth lifetime dependency.
Definition: Singleton.h:634
std::shared_ptr< D8 > dependency8_
Handle to the eighth lifetime dependency.
Definition: Singleton.h:638
std::shared_ptr< D5 > dependency5_
Handle to the fifth lifetime dependency.
Definition: Singleton.h:635
std::shared_ptr< D3 > dependency3_
Handle to the third lifetime dependency.
Definition: Singleton.h:633
~Singleton()
Destructor for the Singleton class.
Definition: Singleton.h:611
#define BLAZE_CONSTRAINT_MUST_BE_DERIVED_FROM(D, B)
Constraint on the inheritance relationship of a data type.
Definition: DerivedFrom.h:60
#define BLAZE_DETECT_CYCLIC_LIFETIME_DEPENDENCY(T)
Constraint on the data type.
Definition: Singleton.h:382
typename TypeAt< TL, Index >::Type TypeAt_t
Auxiliary alias declaration for the TypeAt class template.
Definition: TypeAt.h:139
BoolConstant< true > TrueType
Type traits base class.
Definition: IntegralConstant.h:132
IntegralConstant< bool, B > BoolConstant
Generic wrapper for a compile time constant boolean value.
Definition: IntegralConstant.h:110
Definition: Singleton.h:62
Implementation of a type list.
Definition: TypeList.h:120