diff --git a/utilspp/creation_using_new.hpp b/utilspp/creation_using_new.hpp deleted file mode 100644 index b653a19398b7e0c1113a579dd086edaf0d0a9ffd..0000000000000000000000000000000000000000 --- a/utilspp/creation_using_new.hpp +++ /dev/null @@ -1,55 +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_USING_NEW_HPP -#define CREATION_USING_NEW_HPP - -/** - * This class is a creation policy for the utilspp::singleton_holder. The - * policy is creating the singleton by a "new" call. - */ -namespace utilspp -{ - template< typename T > - struct creation_using_new - { - static T *create(); - static void destroy( T *obj ); - }; -}; - -template< typename T > -T * -utilspp::creation_using_new< T >::create() -{ - return new T; -} - -template< typename T > -void -utilspp::creation_using_new< T >::destroy( T *obj ) -{ - delete obj; -} - -#endif diff --git a/utilspp/lifetime_default.hpp b/utilspp/lifetime_default.hpp deleted file mode 100644 index b0815c60aeb36ac3387baed9ec5d4491d8e4a13c..0000000000000000000000000000000000000000 --- a/utilspp/lifetime_default.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_DEFAULT_HPP -#define LIFETIME_DEFAULT_HPP - -#include <stdexcept> -#include <cstdlib> - -namespace utilspp -{ - template< typename T > - class lifetime_default - { - public: - static void schedule_destruction( T *obj, void (*func)() ); - static void on_dead_reference(); - }; -}; - -template< typename T > -void -utilspp::lifetime_default< T >::schedule_destruction( T *, void (*func)() ) -{ - std::atexit(func); -} - -template< typename T > -void -utilspp::lifetime_default< T >::on_dead_reference() -{ - throw std::logic_error( "Dead reference detected" ); -} - -#endif - diff --git a/utilspp/lifetime_with_longevity.hpp b/utilspp/lifetime_with_longevity.hpp deleted file mode 100644 index eb75a87f428e93f446f6cf582114439d2d23dd7a..0000000000000000000000000000000000000000 --- a/utilspp/lifetime_with_longevity.hpp +++ /dev/null @@ -1,59 +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 "private_members.hpp" - -namespace utilspp -{ - - template< typename T > - unsigned int get_longevity( 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 T_destroyer > - void set_longevity( - T *obj, - unsigned int longevity, - T_destroyer d = utilspp::private_members::deleter< T >::delete_object - ); - - template< typename T > - struct lifetime_with_longevity - { - static void schedule_destruction( T *obj, void (*func)() ); - static void on_dead_reference(); - }; -}; - -#include "lifetime_with_longevity.inl" - -#endif - diff --git a/utilspp/lifetime_with_longevity.inl b/utilspp/lifetime_with_longevity.inl deleted file mode 100644 index 66e78172558ad441f1f6965c55e2503b6a68bdbb..0000000000000000000000000000000000000000 --- a/utilspp/lifetime_with_longevity.inl +++ /dev/null @@ -1,67 +0,0 @@ -template< typename T, typename T_destroyer > -void -utilspp::set_longevity( T *obj, unsigned int longevity, T_destroyer d ) -{ - using namespace utilspp::private_members; - - tracker_array new_array = static_cast< tracker_array >( - std::realloc( - m_tracker_array, - m_nb_elements + 1 - ) - ); - if( new_array == NULL ) - { - throw std::bad_alloc(); - } - - lifetime_tracker *p = new concrete_lifetime_tracker< T, T_destroyer >( - obj, - longevity, - d - ); - - m_tracker_array = new_array; - - tracker_array pos = std::upper_bound( - m_tracker_array, - m_tracker_array + m_nb_elements, - p, - &lifetime_tracker::compare - ); - std::copy_backward( - pos, - m_tracker_array + m_nb_elements, - m_tracker_array + m_nb_elements + 1 - ); - - *pos = p; - m_nb_elements++; - std::atexit( &at_exit_func ); -}; - -template< typename T > -void -utilspp::lifetime_with_longevity< T >::schedule_destruction( T *obj, void (*func)() ) -{ - utilspp::private_members::adapter<T> adapter = { func }; - utilspp::set_longevity( obj, get_longevity( obj ), adapter ); -} - -template< typename T > -void -utilspp::lifetime_with_longevity< T >::on_dead_reference() -{ - throw std::logic_error("Dead reference detected"); -} - -template< typename T > -unsigned int -utilspp::get_longevity( T * ) -{ - return 1000; -} - - - - diff --git a/utilspp/null_type.hpp b/utilspp/null_type.hpp deleted file mode 100644 index f294ef24264c2f7db94de007bfeb61cf0e391ede..0000000000000000000000000000000000000000 --- a/utilspp/null_type.hpp +++ /dev/null @@ -1,33 +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 NULL_TYPE_HPP -#define NULL_TYPE_HPP - -namespace utilspp -{ - class null_type; -}; - -#endif - diff --git a/utilspp/private_members.hpp b/utilspp/private_members.hpp deleted file mode 100644 index 192f0901459b835b98c5579e87956eae5ed4b880..0000000000000000000000000000000000000000 --- a/utilspp/private_members.hpp +++ /dev/null @@ -1,98 +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 private_members - { - /** - * Helper class for utils::set_longevity - */ - class lifetime_tracker - { - public: - lifetime_tracker( unsigned int longevity ); - virtual ~lifetime_tracker(); - static bool compare( - const lifetime_tracker *l, - const lifetime_tracker *r - ); - - private: - unsigned int m_longevity; - }; - - typedef lifetime_tracker** tracker_array; - - extern tracker_array m_tracker_array; - extern int m_nb_elements; - - /** - * Helper class for Destroyer - */ - template< typename T > - struct deleter - { - void delete_object( T *obj ); - }; - - /** - * Concrete lifetime tracker for objects of type T - */ - template< typename T, typename T_destroyer > - class concrete_lifetime_tracker : public lifetime_tracker - { - public: - concrete_lifetime_tracker( - T *obj, - unsigned int longevity, - T_destroyer d - ); - - ~concrete_lifetime_tracker(); - - private: - T* m_tracked; - T_destroyer m_destroyer; - }; - - void at_exit_func(); - - template <class T> - struct adapter - { - void operator()(T*); - void (*m_func)(); - }; - }; -}; - -#include "private_members.inl" - -#endif - diff --git a/utilspp/private_members.inl b/utilspp/private_members.inl deleted file mode 100644 index d4c453918011ece563dcfffa34d7aad4c340f079..0000000000000000000000000000000000000000 --- a/utilspp/private_members.inl +++ /dev/null @@ -1,31 +0,0 @@ -template< typename T > -void -utilspp::private_members::deleter< T >::delete_object( T *obj ) -{ - delete obj; -} - -template< typename T, typename T_destroyer > -utilspp::private_members::concrete_lifetime_tracker< T, T_destroyer >::concrete_lifetime_tracker( - T *obj, - unsigned int longevity, - T_destroyer d - ) -: lifetime_tracker( longevity ) -, m_tracked( obj ) -, m_destroyer( d ) -{} - -template< typename T, typename T_destroyer > -utilspp::private_members::concrete_lifetime_tracker< T, T_destroyer >::~concrete_lifetime_tracker() -{ - m_destroyer( m_tracked ); -} - - -template < typename T > -void -utilspp::private_members::adapter< T >::operator()(T*) -{ - return (*m_func)(); -} diff --git a/utilspp/singleton.hpp b/utilspp/singleton.hpp deleted file mode 100644 index f51b336b802be90929064963a0a037134810b434..0000000000000000000000000000000000000000 --- a/utilspp/singleton.hpp +++ /dev/null @@ -1,2 +0,0 @@ -#include "singleton_holder.hpp" -#include "lifetime_library.hpp" diff --git a/utilspp/singleton_holder.hpp b/utilspp/singleton_holder.hpp deleted file mode 100644 index 730e4cee18cddd750c12f31fc90f59487d5282b3..0000000000000000000000000000000000000000 --- a/utilspp/singleton_holder.hpp +++ /dev/null @@ -1,65 +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 SINGLETON_HOLDER_HPP -#define SINGLETON_HOLDER_HPP - -#include <cassert> - -#include "creation_using_new.hpp" -#include "lifetime_default.hpp" -#include "threading_single.hpp" - -namespace utilspp -{ - template - < - class T, - template < class > class T_creation_policy = utilspp::creation_using_new, - template < class > class T_lifetime_policy = utilspp::lifetime_default, - template < class > class T_threading_model = utilspp::threading_single - > - class singleton_holder - { - public: - //the accessor method. - static T& instance(); - static void make_instance(); - - protected: - //protected to be sure that nobody may create one by himself. - singleton_holder(); - - private: - static void destroy_singleton(); - - private: - typedef typename T_threading_model< T * >::volatile_type instance_type; - static instance_type m_instance; - static bool m_destroyed; - }; -} - -#include "singleton_holder.inl" - -#endif diff --git a/utilspp/singleton_holder.inl b/utilspp/singleton_holder.inl deleted file mode 100644 index 0a929411fb478a088ddb3cbf45eb29d3c294fcc7..0000000000000000000000000000000000000000 --- a/utilspp/singleton_holder.inl +++ /dev/null @@ -1,124 +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 SINGLETON_HOLDER_INL -#define SINGLETON_HOLDER_INL - -template -< -class T, -template < class > class T_creation_policy, -template < class > class T_lifetime_policy, -template < class > class T_threading_model -> -T& -utilspp::singleton_holder -< -T, -T_creation_policy, -T_lifetime_policy, -T_threading_model -> -::instance() -{ - if ( m_instance == NULL ) - { - make_instance(); - } - - return ( *m_instance ); -}; - -template -< -class T, -template < class > class T_creation_policy, -template < class > class T_lifetime_policy, -template < class > class T_threading_model -> -void -utilspp::singleton_holder -< -T, -T_creation_policy, -T_lifetime_policy, -T_threading_model ->::make_instance() -{ - typename T_threading_model< T >::lock guard; - (void)guard; - - if ( m_instance == NULL ) - { - if ( m_destroyed ) - { - T_lifetime_policy< T >::on_dead_reference(); - m_destroyed = false; - } - - m_instance = T_creation_policy< T >::create(); - T_lifetime_policy< T >::schedule_destruction( m_instance, &destroy_singleton ); - } -} - -template -< -class T, -template < class > class T_creation_policy, -template < class > class T_lifetime_policy, -template < class > class T_threading_model -> -void -utilspp::singleton_holder -< -T, -T_creation_policy, -T_lifetime_policy, -T_threading_model -> -::destroy_singleton() -{ - assert( !m_destroyed ); - T_creation_policy< T >::destroy( m_instance ); - m_instance = NULL; - m_destroyed = true; -} - -template < class T, -template < class > class C, -template < class > class L, -template < class > class M -> -typename utilspp::singleton_holder< T, C, L, M>::instance_type -utilspp::singleton_holder< T, C, L, M >::m_instance; - -template -< -class T, -template < class > class C, -template < class > class L, -template < class > class M -> -bool utilspp::singleton_holder< T, C, L, M >::m_destroyed; - -#endif diff --git a/utilspp/threading_single.hpp b/utilspp/threading_single.hpp deleted file mode 100644 index 1923bd1b8d54df6e5f40e6b219fe626f665d2d3b..0000000000000000000000000000000000000000 --- a/utilspp/threading_single.hpp +++ /dev/null @@ -1,74 +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 SINGLE_THREADED_HPP -#define SINGLE_THREADED_HPP - -#include "null_type.hpp" - -namespace utilspp -{ - template < typename T = utilspp::null_type > - struct threading_single - { - struct mutex - { - void lock(); - void unlock(); - }; - - struct lock - { - lock(); - lock( mutex &m ); - }; - - typedef T volatile_type; - }; -}; - -template< typename T > -inline -utilspp::threading_single< T >::lock::lock() -{}; - -template< typename T > -inline -utilspp::threading_single< T >::lock::lock( - utilspp::threading_single< T >::mutex & ) -{} - -template< typename T > -inline -void -utilspp::threading_single< T >::mutex::lock() -{}; - -template< typename T > -inline -void -utilspp::threading_single< T >::mutex::unlock() -{}; - -#endif -