From a17791f2c84b8dad58cdd1ccb1c068a2fecb9517 Mon Sep 17 00:00:00 2001 From: syntheticpp Date: Tue, 1 Nov 2005 11:15:22 +0000 Subject: [PATCH] test program for lifetime policies FollowIntoDeath and DieOrder git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@339 7ec92016-0320-0410-acc4-a06ded1c099a --- test/Makefile | 8 +- test/Singleton/Dependencies.cpp | 411 +++++++++++++++++++++++++++ test/Singleton/Makefile-Dependencies | 32 +++ 3 files changed, 450 insertions(+), 1 deletion(-) create mode 100755 test/Singleton/Dependencies.cpp create mode 100755 test/Singleton/Makefile-Dependencies diff --git a/test/Makefile b/test/Makefile index a40ee00..56e2c88 100755 --- a/test/Makefile +++ b/test/Makefile @@ -36,7 +36,8 @@ sub-SafeFormat: FORCE sub-Singleton: FORCE cd Singleton && \ $(MAKE) -f $(MAKEFILE)-DeletableSingleton && \ - $(MAKE) -f $(MAKEFILE)-Phoenix + $(MAKE) -f $(MAKEFILE)-Phoenix && \ + $(MAKE) -f $(MAKEFILE)-Dependencies @cd .. sub-SmallObj: FORCE @@ -78,6 +79,11 @@ clean: cd SmallObj && \ $(MAKE) -f $(MAKEFILE) clean @cd .. + + cd Singleton && \ + $(MAKE) -f $(MAKEFILE)-DeletableSingleton clean&& \ + $(MAKE) -f $(MAKEFILE)-Phoenix clean && \ + $(MAKE) -f $(MAKEFILE)-Dependencies clean diff --git a/test/Singleton/Dependencies.cpp b/test/Singleton/Dependencies.cpp new file mode 100755 index 0000000..1cf66cf --- /dev/null +++ b/test/Singleton/Dependencies.cpp @@ -0,0 +1,411 @@ + + +#include + +#include "loki/SmallObj.h" +#include "loki/Function.h" + + +using namespace Loki; + + +//////////////////////////////////////////////////////////////////////////////////// +// +// How to use FollowIntoDeath with SmallObjects? +// +//////////////////////////////////////////////////////////////////////////////////// + +typedef Loki::SmallObject +< + LOKI_DEFAULT_THREADING_NO_OBJ_LEVEL, + LOKI_DEFAULT_CHUNK_SIZE, + LOKI_MAX_SMALL_OBJECT_SIZE, + LOKI_DEFAULT_OBJECT_ALIGNMENT, + FollowIntoDeath::With::AsMasterLifetime +> +MySmallObjectBase; + +struct MySmallObject : public MySmallObjectBase +{ +}; + +typedef SingletonHolder +< + MySmallObject, + CreateUsingNew, + FollowIntoDeath::AfterMaster::IsDestroyed +> +Singleton_of_with_a_MySmallObject; + +//////////////////////////////////////////////////////////////////////////////////// +// +// How to use FollowIntoDeath with classes containing a Functor/Function? +// +//////////////////////////////////////////////////////////////////////////////////// + +struct MyFunctionObject +{ + MyFunctionObject() + { + functor = Functor (this, &MyFunctionObject::f); + function = Function< void()>(this, &MyFunctionObject::f); + } + + void f(){} + Functor functor; + Function function; + +}; + +typedef SingletonHolder +< + MyFunctionObject, + CreateUsingNew, + FollowIntoDeath::AfterMaster::Impl::ObjAllocatorSingleton + >::IsDestroyed +> +Singleton_MyFunctionObject1; + +typedef SingletonHolder +< + MyFunctionObject, + CreateUsingNew, + FollowIntoDeath::AfterMaster::Impl::ObjAllocatorSingleton + >::IsDestroyed +> +Singleton_MyFunctionObject2; + +//////////////////////////////////////////////////////////////////////////////////// +// +// Data object for all singletons +// +//////////////////////////////////////////////////////////////////////////////////// + +template