From 0fc58a0e8624931ca02c276a511345e35ab4c666 Mon Sep 17 00:00:00 2001 From: syntheticpp Date: Mon, 7 Nov 2005 12:06:43 +0000 Subject: [PATCH] change lifetime policy DieOrder to a msvc7.1 compilable version. Make this the default lifetime for SmallObject git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@353 7ec92016-0320-0410-acc4-a06ded1c099a --- include/loki/Function.h | 16 +- include/loki/Singleton.h | 75 ++++--- include/loki/SmallObj.h | 37 ++-- test/Factory/Factory.cpp | 21 +- test/Singleton/Dependencies.cpp | 270 ++++++++++++++++---------- test/Singleton/make.msvc.bat | 2 + test/SmallObj/Makefile | 7 +- test/SmallObj/SmallSingleton.cpp | 324 +++++++++---------------------- test/SmallObj/make.msvc.bat | 9 +- 9 files changed, 363 insertions(+), 398 deletions(-) diff --git a/include/loki/Function.h b/include/loki/Function.h index c85761f..905be0b 100755 --- a/include/loki/Function.h +++ b/include/loki/Function.h @@ -18,14 +18,14 @@ namespace Loki { - //////////////////////////////////////////////////////////////////////////////// - /// \struct Function - /// - /// \ingroup FunctorGroup - /// Allows a boost/TR1 like usage of Functor. - /// - /// e.g. Functor becomes Function - //////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////// + /// \struct Function + /// + /// \ingroup FunctorGroup + /// Allows a boost/TR1 like usage of Functor. + /// + /// e.g. Functor becomes Function + //////////////////////////////////////////////////////////////////////////////// template struct Function : public Functor { diff --git a/include/loki/Singleton.h b/include/loki/Singleton.h index 5ceddcb..b61f668 100644 --- a/include/loki/Singleton.h +++ b/include/loki/Singleton.h @@ -426,41 +426,66 @@ namespace Loki static void OnDeadReference() {} }; - - template - class SingletonFixedLongevity - { - public: - static void ScheduleDestruction(T* pObj, atexit_pfn_t pFun) - { - Private::Adapter adapter = { pFun }; - SetLongevity(pObj, Longevity , adapter); - } - - static void OnDeadReference() - { throw std::logic_error("Dead Reference Detected"); } - }; + //////////////////////////////////////////////////////////////////////////////// - /// \struct DieOrder - /// + /// \defgroup LongevityLifetimeGroup LongevityLifetime /// \ingroup LifetimeGroup - /// Lifetime policy to handle lifetime dependencies + /// + /// \namespace LongevityLifetime + /// + /// \ingroup LongevityLifetimeGroup + /// \brief In this namespace are special lifetime policies to manage lifetime + /// dependencies. //////////////////////////////////////////////////////////////////////////////// - struct DieOrder + namespace LongevityLifetime { - /// \struct Last - /// Die after the singleton with the DieOrder::First lifetime + //////////////////////////////////////////////////////////////////////////////// + /// \struct SingletonFixedLongevity + /// + /// \ingroup LongevityLifetimeGroup + /// Add your own lifetimes into the namespace 'LongevityLifetime' + /// with your prefered lifetime by adding a struct like this: + /// + /// template + /// struct MyLifetime : SingletonFixedLongevity< MyLifetimeNumber ,T> {} + //////////////////////////////////////////////////////////////////////////////// + template + class SingletonFixedLongevity + { + public: + static void ScheduleDestruction(T* pObj, atexit_pfn_t pFun) + { + Private::Adapter adapter = { pFun }; + SetLongevity(pObj, Longevity , adapter); + } + + static void OnDeadReference() + { throw std::logic_error("Dead Reference Detected"); } + }; + + /// \struct DieLast + /// \ingroup LongevityLifetimeGroup + /// \brief Longest possible SingletonWithLongevity lifetime: 0xFFFFFFFF template - struct Last : public SingletonFixedLongevity<0xFFFFFFFF ,T> + struct DieLast : SingletonFixedLongevity<0xFFFFFFFF ,T> {}; - /// \struct First - /// Die before the singleton with the DieOrder::Last lifetime + /// \struct DieDirectlyBeforeLast + /// \ingroup LongevityLifetimeGroup + /// \brief Lifetime is a one less than DieLast: 0xFFFFFFFF-1 template - struct First : public SingletonFixedLongevity<0xFFFFFFFF-1,T> + struct DieDirectlyBeforeLast : SingletonFixedLongevity<0xFFFFFFFF-1 ,T> {}; - }; + + /// \struct DieFirst + /// \ingroup LongevityLifetimeGroup + /// \brief Shortest possible SingletonWithLongevity lifetime: 0 + template + struct DieFirst : SingletonFixedLongevity<0,T> + {}; + + }//namespace LongevityLifetime //////////////////////////////////////////////////////////////////////////////// /// \class FollowIntoDeath diff --git a/include/loki/SmallObj.h b/include/loki/SmallObj.h index d135f6b..09ff428 100644 --- a/include/loki/SmallObj.h +++ b/include/loki/SmallObj.h @@ -36,18 +36,8 @@ #define LOKI_DEFAULT_OBJECT_ALIGNMENT 4 #endif - -//#define LOKI_DEFAULT_SMALLOBJ_LIFETIME DefaultLifetime - #ifndef LOKI_DEFAULT_SMALLOBJ_LIFETIME - -#if defined(_MSC_VER) && (_MSC_VER<1400) -// msvc 7.1 is faulty and can't handle the FollowIntoDeath and DieOrder lifetime policies -#define LOKI_DEFAULT_SMALLOBJ_LIFETIME NoDestroy -#else -#define LOKI_DEFAULT_SMALLOBJ_LIFETIME FollowIntoDeath::With::AsMasterLifetime -#endif - +#define LOKI_DEFAULT_SMALLOBJ_LIFETIME LongevityLifetime::DieAsSmallObjectParent #endif #if defined(LOKI_SMALL_OBJECT_USE_NEW_ARRAY) && defined(_MSC_VER) @@ -63,6 +53,28 @@ namespace Loki { + namespace LongevityLifetime + { + /** @struct DieAsSmallObjectParent + @ingroup SmallObjectGroup + Lifetime policy to manage lifetime dependencies of + SmallObject base and child classes. + The Base class should have this lifetime + */ + template + struct DieAsSmallObjectParent : DieLast {}; + + /** @struct DieAsSmallObjectChild + @ingroup SmallObjectGroup + Lifetime policy to manage lifetime dependencies of + SmallObject base and child classes. + The Child class should have this lifetime + */ + template + struct DieAsSmallObjectChild : DieDirectlyBeforeLast {}; + + } + class FixedAllocator; /** @class SmallObjAllocator @@ -540,6 +552,9 @@ namespace Loki // Nov. 26, 2004: re-implemented by Rich Sposato. // // $Log$ +// Revision 1.22 2005/11/07 12:06:43 syntheticpp +// change lifetime policy DieOrder to a msvc7.1 compilable version. Make this the default lifetime for SmallObject +// // Revision 1.21 2005/11/05 17:43:55 syntheticpp // disable FollowIntoDeath/DieOrder lifetime policies when using the msvc 7.1 compiler, bug article: 839821 'Microsoft has confirmed that this is a problem..' // diff --git a/test/Factory/Factory.cpp b/test/Factory/Factory.cpp index eeaaaec..6ee4549 100755 --- a/test/Factory/Factory.cpp +++ b/test/Factory/Factory.cpp @@ -52,10 +52,8 @@ public: typedef SingletonHolder < Factory< AbstractProduct, int >, - CreateUsingNew -#if !defined(_MSC_VER) || (_MSC_VER>=1400) - ,FollowIntoDeath::AfterMaster::Impl::ObjAllocatorSingleton>::IsDestroyed -#endif + CreateUsingNew, + Loki::LongevityLifetime::DieAsSmallObjectChild > PFactoryNull; @@ -70,10 +68,8 @@ typedef SingletonHolder #else Factory< AbstractProduct, int, Seq< int, int > >, #endif - CreateUsingNew -#if !defined(_MSC_VER) || (_MSC_VER>=1400) - ,FollowIntoDeath::AfterMaster::Impl::ObjAllocatorSingleton>::IsDestroyed -#endif + CreateUsingNew, + Loki::LongevityLifetime::DieAsSmallObjectChild > PFactory; @@ -171,10 +167,8 @@ SingletonHolder #else Factory< AbstractProduct, int,Seq >, #endif - CreateUsingNew -#if !defined(_MSC_VER) || (_MSC_VER>=1400) - ,FollowIntoDeath::AfterMaster::Impl::ObjAllocatorSingleton>::IsDestroyed -#endif + CreateUsingNew, + Loki::LongevityLifetime::DieAsSmallObjectChild > PFactoryFunctorParm; @@ -259,6 +253,9 @@ int main(int argc, char *argv[]) } // $Log$ +// Revision 1.8 2005/11/07 12:06:43 syntheticpp +// change lifetime policy DieOrder to a msvc7.1 compilable version. Make this the default lifetime for SmallObject +// // Revision 1.7 2005/11/05 17:43:55 syntheticpp // disable FollowIntoDeath/DieOrder lifetime policies when using the msvc 7.1 compiler, bug article: 839821 'Microsoft has confirmed that this is a problem..' // diff --git a/test/Singleton/Dependencies.cpp b/test/Singleton/Dependencies.cpp index 8b22ec1..8648d13 100755 --- a/test/Singleton/Dependencies.cpp +++ b/test/Singleton/Dependencies.cpp @@ -18,8 +18,156 @@ using namespace Loki; + +//////////////////////////////////////////////////////////////////////////////////// +// +// Data object for all singletons +// +//////////////////////////////////////////////////////////////////////////////////// + +template