diff --git a/daemon/libs/utilspp/singleton/CreationStatic.hpp b/daemon/libs/utilspp/singleton/CreationStatic.hpp deleted file mode 100644 index 27570f5308802c89614944ae3ab97b7fafdf7c8f..0000000000000000000000000000000000000000 --- a/daemon/libs/utilspp/singleton/CreationStatic.hpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) <2002-2004> <Jean-Philippe Barrette-LaPierre> - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files - * (cURLpp), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, - * publish, distribute, sublicense, and/or sell copies of the Software, - * and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -#ifndef CREATION_STATIC_HPP -#define CREATION_STATIC_HPP - -/** - * This class is a creation policy for the utilspp::singleton_holder. The - * policy is creating the singleton by a static memory. The constructor is - * called the first time we call the utilspp::creation_static::create() - * function. - * - * Note don't use this class because it's not complete, and at this time it's - * not REALY complyant with the lifetime policy. - */ -namespace utilspp -{ - template< typename T > - class CreationStatic - { - public: - static T* create(); - static void destroy( T* obj ); - }; -}; - -#include "CreationStatic.inl" - -#endif diff --git a/daemon/libs/utilspp/singleton/CreationStatic.inl b/daemon/libs/utilspp/singleton/CreationStatic.inl deleted file mode 100644 index 9572e5eca75f2d2e054cb7ea12d68a2cb33677b4..0000000000000000000000000000000000000000 --- a/daemon/libs/utilspp/singleton/CreationStatic.inl +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) <2002-2004> <Jean-Philippe Barrette-LaPierre> - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files - * (cURLpp), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, - * publish, distribute, sublicense, and/or sell copies of the Software, - * and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -#ifndef CREATION_STATIC_INL -#define CREATION_STATIC_INL - -template< typename T > -T* -utilspp::CreationStatic::create() -{ - static T mObj; - return new(&mObj) T; -}; - -template< typename T > -void -utilspp::CreationStatic::destroy( T* obj ) -{ - obj->~T(); -} - - -#endif \ No newline at end of file diff --git a/daemon/libs/utilspp/singleton/LifetimeLibrary.cpp b/daemon/libs/utilspp/singleton/LifetimeLibrary.cpp deleted file mode 100644 index 6e71baddaad90bc1922457fcae4791c3b53cea3d..0000000000000000000000000000000000000000 --- a/daemon/libs/utilspp/singleton/LifetimeLibrary.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#include "SingletonHolder.hpp" -#include "LifetimeLibrary.hpp" - -utilspp::LifetimeLibraryImpl::LifetimeLibraryImpl() - : - mTrackerArray (NULL), - mNbElements (0) {} - -utilspp::LifetimeLibraryImpl::~LifetimeLibraryImpl() { - terminate(); -} - -void -utilspp::LifetimeLibraryImpl::add (utilspp::PrivateMembers::LifetimeTracker *tracker) { - utilspp::PrivateMembers::TrackerArray newArray = static_cast< - utilspp::PrivateMembers::TrackerArray > (std::realloc (mTrackerArray, - mNbElements + 1)); - - if (newArray == NULL) { - throw std::bad_alloc(); - } - - mTrackerArray = newArray; - - utilspp::PrivateMembers::TrackerArray pos = - std::upper_bound (mTrackerArray, - mTrackerArray + mNbElements, - tracker, - &utilspp::PrivateMembers::LifetimeTracker::compare); - std::copy_backward (pos, - mTrackerArray + mNbElements, - mTrackerArray + mNbElements + 1); - - *pos = tracker; - mNbElements++; -}; - -void -utilspp::LifetimeLibraryImpl::terminate() { - //The number of elements MUST always be equal or over zero. - assert (mNbElements >= 0); - - while (mNbElements > 0) { - //At this point the mTrackerArray MUST not be NULL. - assert (mTrackerArray != NULL); - - //Pick the element at the top of the stack. - utilspp::PrivateMembers::LifetimeTracker* top = - mTrackerArray[mNbElements - 1]; - - //Remove that object off the stack. - //Don't check errors-realloc with less memory, cause that can't fail. - mTrackerArray = - static_cast< utilspp::PrivateMembers::TrackerArray > - (std::realloc (mTrackerArray, --mNbElements)); - - //Destroy the element. - delete top; - } -} - -unsigned int -utilspp::getLongevity (utilspp::LifetimeLibraryImpl *) { - return 0; -} - diff --git a/daemon/libs/utilspp/singleton/LifetimeLibrary.hpp b/daemon/libs/utilspp/singleton/LifetimeLibrary.hpp deleted file mode 100644 index 27f62ad75066e919c1a212da8a85ea467ea44d7a..0000000000000000000000000000000000000000 --- a/daemon/libs/utilspp/singleton/LifetimeLibrary.hpp +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) <2002-2004> <Jean-Philippe Barrette-LaPierre> - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files - * (cURLpp), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, - * publish, distribute, sublicense, and/or sell copies of the Software, - * and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -#ifndef LIFETIME_LIBRARY_HPP -#define LIFETIME_LIBRARY_HPP - -#include <cassert> -#include <algorithm> -#include "PrivateMembers.hpp" -#include "CreationUsingNew.hpp" - -namespace utilspp -{ - - template< typename T > - unsigned int getLongevity( T *p ); - - /** - * Assigns an object a longevity. Ensures ordered destructions of objects - * registered thusly during the exit sequence of the application. - */ - template< typename T, typename TDestroyer > - void setLibraryLongevity( - T *obj, - unsigned int longevity, - TDestroyer d = utilspp::PrivateMembers::Deleter< T >::deleteObject - ); - - /** - * This class is a lifetime policy for the singleton. This - * class allow you to terminate the singleton explicitly. - * You can terminate by calling: - * - * LifetimeLibrarySingleton::instance().terminate() - * - * This singleton use the utilspp::LifetimeWithLongevity policy. - */ - template< typename T > - struct LifetimeLibrary - { - static void scheduleDestruction( T *obj, void (*func)() ); - static void onDeadReference(); - }; - - class LifetimeLibraryImpl - { - public: - LifetimeLibraryImpl(); - ~LifetimeLibraryImpl(); - - void add( utilspp::PrivateMembers::LifetimeTracker *tracker ); - void terminate(); - - private: - utilspp::PrivateMembers::TrackerArray mTrackerArray; - int mNbElements; - }; - - unsigned int getLongevity( utilspp::LifetimeLibraryImpl *p ); - - typedef utilspp::SingletonHolder< - utilspp::LifetimeLibraryImpl, - utilspp::CreationUsingNew, - utilspp::LifetimeWithLongevity - > LifetimeLibrarySingleton; - - /** - * This class will ensure that - * - * LifetimeLibraryImpl::terminate() - * - * is called. - */ - template< typename T = utilspp::LifetimeLibrarySingleton > - class LifetimeLibraryGuard - { - public: - ~LifetimeLibraryGuard(); - }; -}; - -#include "LifetimeLibrary.inl" - -#endif diff --git a/daemon/libs/utilspp/singleton/LifetimeLibrary.inl b/daemon/libs/utilspp/singleton/LifetimeLibrary.inl deleted file mode 100644 index b7ab8e6d66d2bb38719e8b0b6d163636f33bcdbd..0000000000000000000000000000000000000000 --- a/daemon/libs/utilspp/singleton/LifetimeLibrary.inl +++ /dev/null @@ -1,33 +0,0 @@ -template< typename T, typename TDestroyer > -void -utilspp::setLibraryLongevity( T *obj, unsigned int longevity, TDestroyer d ) -{ - using namespace utilspp::PrivateMembers; - - LifetimeTracker *p = new ConcreteLifetimeTracker< T, TDestroyer >( - obj, longevity, d); - - utilspp::LifetimeLibrarySingleton::instance().add( p ); -}; - -template< typename T > -void -utilspp::LifetimeLibrary< T >::scheduleDestruction( T *obj, void (*func)() ) -{ - utilspp::PrivateMembers::adapter<T> adapter = { func }; - utilspp::setLibraryLongevity( obj, getLongevity( obj ), adapter ); -} - -template< typename T > -void -utilspp::LifetimeLibrary< T >::onDeadReference() -{ - throw std::logic_error("Dead reference detected"); -} - -template< typename T > -utilspp::LifetimeLibraryGuard< T >::~LifetimeLibraryGuard() -{ - T::instance().terminate(); -} - diff --git a/daemon/libs/utilspp/singleton/LifetimeWithLongevity.hpp b/daemon/libs/utilspp/singleton/LifetimeWithLongevity.hpp deleted file mode 100644 index c7749d43f5fe51a7b313eb6b37bfb986fee97184..0000000000000000000000000000000000000000 --- a/daemon/libs/utilspp/singleton/LifetimeWithLongevity.hpp +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) <2002-2004> <Jean-Philippe Barrette-LaPierre> - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files - * (cURLpp), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, - * publish, distribute, sublicense, and/or sell copies of the Software, - * and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -#ifndef LIFETIME_WITH_LONGEVITY_HPP -#define LIFETIME_WITH_LONGEVITY_HPP - -#include <cassert> -#include "PrivateMembers.hpp" -#include <algorithm> - -namespace utilspp -{ - - template< typename T > - unsigned int getLongevity( T *p ); - - /** - * Assigns an object a longevity. Ensures ordered destructions of objects - * registered thusly during the exit sequence of the application. - */ - template< typename T, typename TDestroyer > - void setLongevity(T *obj, - unsigned int longevity, - TDestroyer d = utilspp::PrivateMembers::Deleter< T >::deleteObject); - - template< typename T > - struct LifetimeWithLongevity - { - static void scheduleDestruction( T *obj, void (*func)() ); - static void onDeadReference(); - }; -} - -#include "LifetimeWithLongevity.inl" - -#endif diff --git a/daemon/libs/utilspp/singleton/LifetimeWithLongevity.inl b/daemon/libs/utilspp/singleton/LifetimeWithLongevity.inl deleted file mode 100644 index 6b8f3eb32f5b0cc80d4fd15213546b56c901f774..0000000000000000000000000000000000000000 --- a/daemon/libs/utilspp/singleton/LifetimeWithLongevity.inl +++ /dev/null @@ -1,56 +0,0 @@ -template< typename T, typename TDestroyer > -void -utilspp::setLongevity( T *obj, unsigned int longevity, TDestroyer d ) -{ - using namespace utilspp::PrivateMembers; - - TrackerArray newArray = static_cast< TrackerArray >( - std::realloc(mTrackerArray, mNbElements + 1)); - if( newArray == NULL ) - { - throw std::bad_alloc(); - } - - LifetimeTracker *p = - new ConcreteLifetimeTracker< T, TDestroyer >(obj, longevity, d); - - mTrackerArray = newArray; - - TrackerArray pos = std::upper_bound( - mTrackerArray, - mTrackerArray + mNbElements, - p, - &LifetimeTracker::compare); - std::copy_backward( - pos, - mTrackerArray + mNbElements, - mTrackerArray + mNbElements + 1); - - *pos = p; - mNbElements++; - std::atexit( &atExitFunc ); -} - -template< typename T > -void -utilspp::LifetimeWithLongevity< T >::scheduleDestruction( T *obj, void (*func)() ) -{ - utilspp::PrivateMembers::adapter<T> adapter = { func }; - utilspp::setLongevity( obj, getLongevity( obj ), adapter ); -} - -template< typename T > -void -utilspp::LifetimeWithLongevity< T >::onDeadReference() -{ - throw std::logic_error("Dead reference detected"); -} - -template< typename T > -unsigned int -utilspp::getLongevity( T * ) -{ - return 1000; -} - - diff --git a/daemon/libs/utilspp/singleton/Makefile.am b/daemon/libs/utilspp/singleton/Makefile.am index 0488bfec1b67429864f4fac8f0f6bb12fa91a521..66fdc6f012b1dc9be7b4ac50838245119b801f90 100644 --- a/daemon/libs/utilspp/singleton/Makefile.am +++ b/daemon/libs/utilspp/singleton/Makefile.am @@ -1,12 +1,8 @@ noinst_LTLIBRARIES = libsingleton.la libsingleton_la_SOURCES = \ - CreationStatic.hpp CreationStatic.inl \ CreationUsingNew.hpp CreationUsingNew.inl \ LifetimeDefault.hpp LifetimeDefault.inl \ - LifetimeLibrary.cpp LifetimeLibrary.hpp LifetimeLibrary.inl \ - LifetimeWithLongevity.hpp LifetimeWithLongevity.inl \ - PrivateMembers.cpp PrivateMembers.hpp PrivateMembers.inl \ SingletonHolder.hpp SingletonHolder.inl diff --git a/daemon/libs/utilspp/singleton/PrivateMembers.cpp b/daemon/libs/utilspp/singleton/PrivateMembers.cpp deleted file mode 100644 index a033e0c54c6255fca5144b7963c50ea2ace9ab07..0000000000000000000000000000000000000000 --- a/daemon/libs/utilspp/singleton/PrivateMembers.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include <cstdlib> - -#include "PrivateMembers.hpp" - -utilspp::PrivateMembers::TrackerArray -utilspp::PrivateMembers::mTrackerArray = NULL; - -int utilspp::PrivateMembers::mNbElements = 0; - -utilspp::PrivateMembers::LifetimeTracker::LifetimeTracker (unsigned int - longevity) - : - mLongevity (longevity) {} - -utilspp::PrivateMembers::LifetimeTracker::~LifetimeTracker() {} - -bool -utilspp::PrivateMembers::LifetimeTracker::compare ( - const LifetimeTracker *l, - const LifetimeTracker *r -) { - return l->mLongevity < r->mLongevity; -} - -void -utilspp::PrivateMembers::atExitFunc() { - assert ( (mTrackerArray != NULL) && - (mNbElements > 0)); - - //Pick the element at the top of the stack. - LifetimeTracker* top = mTrackerArray[mNbElements - 1]; - - //Remove that object off the stack. - //Don't check errors-realloc with less memory, cause that can't fail. - mTrackerArray = static_cast< - utilspp::PrivateMembers::TrackerArray > (std::realloc (mTrackerArray, - --mNbElements)); - - //Destroy the element. - delete top; -} - diff --git a/daemon/libs/utilspp/singleton/PrivateMembers.hpp b/daemon/libs/utilspp/singleton/PrivateMembers.hpp deleted file mode 100644 index 05079eff5c051817e5e23d884e14787ddd18a523..0000000000000000000000000000000000000000 --- a/daemon/libs/utilspp/singleton/PrivateMembers.hpp +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (c) <2002-2004> <Jean-Philippe Barrette-LaPierre> - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files - * (cURLpp), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, - * publish, distribute, sublicense, and/or sell copies of the Software, - * and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -#ifndef PRIVATE_MEMBERS_HPP -#define PRIVATE_MEMBERS_HPP - -#include <cassert> - -namespace utilspp -{ - namespace PrivateMembers - { - /** - * Helper class for utils::setLongevity - */ - class LifetimeTracker - { - public: - LifetimeTracker( unsigned int longevity ); - virtual ~LifetimeTracker(); - static bool compare( - const LifetimeTracker *l, - const LifetimeTracker *r - ); - - private: - unsigned int mLongevity; - }; - - typedef LifetimeTracker** TrackerArray; - - extern TrackerArray mTrackerArray; - extern int mNbElements; - - /** - * Helper class for Destroyer - */ - template< typename T > - struct Deleter - { - void deleteObject( T *obj ); - }; - - /** - * Concrete lifetime tracker for objects of type T - */ - template< typename T, typename TDestroyer > - class ConcreteLifetimeTracker : public LifetimeTracker - { - public: - ConcreteLifetimeTracker(T *obj, unsigned int longevity, TDestroyer d); - - ~ConcreteLifetimeTracker(); - - private: - T* mTracked; - TDestroyer mDestroyer; - }; - - void atExitFunc(); - - template <class T> - struct adapter - { - void operator()(T*); - void (*mFunc)(); - }; - } -} - -#include "PrivateMembers.inl" - -#endif diff --git a/daemon/libs/utilspp/singleton/PrivateMembers.inl b/daemon/libs/utilspp/singleton/PrivateMembers.inl deleted file mode 100644 index 8f3609416cd2e78a4995ab0594b62c0a73729237..0000000000000000000000000000000000000000 --- a/daemon/libs/utilspp/singleton/PrivateMembers.inl +++ /dev/null @@ -1,30 +0,0 @@ - -template< typename T > -void -utilspp::PrivateMembers::Deleter< T >::deleteObject( T *obj ) -{ - delete obj; -} - -template< typename T, typename TDestroyer > -utilspp::PrivateMembers::ConcreteLifetimeTracker< T, TDestroyer >::ConcreteLifetimeTracker( - T *obj, unsigned int longevity, TDestroyer d) -: LifetimeTracker( longevity ) -, mTracked( obj ) -, mDestroyer( d ) -{} - -template< typename T, typename TDestroyer > -utilspp::PrivateMembers::ConcreteLifetimeTracker< T, TDestroyer >::~ConcreteLifetimeTracker() -{ - mDestroyer( mTracked ); -} - - -template < typename T > -void -utilspp::PrivateMembers::adapter< T >::operator()(T*) -{ - return (*mFunc)(); -} - diff --git a/daemon/libs/utilspp/singleton/SingletonHolder.hpp b/daemon/libs/utilspp/singleton/SingletonHolder.hpp index d773cd8c42532536b2e5210c008173f4ec0ed172..da62bc08385cd597d13a22d5f0561014c2d181df 100644 --- a/daemon/libs/utilspp/singleton/SingletonHolder.hpp +++ b/daemon/libs/utilspp/singleton/SingletonHolder.hpp @@ -28,7 +28,6 @@ #include "CreationUsingNew.hpp" #include "LifetimeDefault.hpp" -#include "LifetimeWithLongevity.hpp" #include "../ThreadingSingle.hpp" namespace utilspp