2
* Copyright (c) <2002-2004> <Jean-Philippe Barrette-LaPierre>
4
* Permission is hereby granted, free of charge, to any person obtaining
5
* a copy of this software and associated documentation files
6
* (cURLpp), to deal in the Software without restriction,
7
* including without limitation the rights to use, copy, modify, merge,
8
* publish, distribute, sublicense, and/or sell copies of the Software,
9
* and to permit persons to whom the Software is furnished to do so,
10
* subject to the following conditions:
12
* The above copyright notice and this permission notice shall be included
13
* in all copies or substantial portions of the Software.
15
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
#ifndef LIFETIME_LIBRARY_HPP
25
#define LIFETIME_LIBRARY_HPP
29
#include "PrivateMembers.hpp"
30
#include "CreationUsingNew.hpp"
35
template< typename T >
36
unsigned int getLongevity( T *p );
39
* Assigns an object a longevity. Ensures ordered destructions of objects
40
* registered thusly during the exit sequence of the application.
42
template< typename T, typename TDestroyer >
43
void setLibraryLongevity(
45
unsigned int longevity,
46
TDestroyer d = utilspp::PrivateMembers::Deleter< T >::deleteObject
50
* This class is a lifetime policy for the singleton. This
51
* class allow you to terminate the singleton explicitly.
52
* You can terminate by calling:
54
* LifetimeLibrarySingleton::instance().terminate()
56
* This singleton use the utilspp::LifetimeWithLongevity policy.
58
template< typename T >
59
struct LifetimeLibrary
61
static void scheduleDestruction( T *obj, void (*func)() );
62
static void onDeadReference();
65
class LifetimeLibraryImpl
68
LifetimeLibraryImpl();
69
~LifetimeLibraryImpl();
71
void add( utilspp::PrivateMembers::LifetimeTracker *tracker );
75
utilspp::PrivateMembers::TrackerArray mTrackerArray;
79
unsigned int getLongevity( utilspp::LifetimeLibraryImpl *p );
81
typedef utilspp::SingletonHolder<
82
utilspp::LifetimeLibraryImpl,
83
utilspp::CreationUsingNew,
84
utilspp::LifetimeWithLongevity
85
> LifetimeLibrarySingleton;
88
* This class will ensure that
90
* LifetimeLibraryImpl::terminate()
94
template< typename T = utilspp::LifetimeLibrarySingleton >
95
class LifetimeLibraryGuard
98
~LifetimeLibraryGuard();
102
#include "LifetimeLibrary.inl"