Skip to content
Snippets Groups Projects
Commit 28d8251c authored by jpbl's avatar jpbl
Browse files

added missing files

parent dd5cc2be
No related branches found
No related tags found
No related merge requests found
#include "singleton_holder.hpp"
#include "lifetime_library.hpp"
/*
* 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 "lifetime_with_longevity.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
/*
* 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
/*
* 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment