~ubuntu-branches/ubuntu/raring/sflphone/raring

« back to all changes in this revision

Viewing changes to sflphone-common/libs/utilspp/singleton/LifetimeLibrary.hpp

  • Committer: Package Import Robot
  • Author(s): Francois Marier
  • Date: 2011-11-25 13:24:12 UTC
  • mfrom: (4.1.10 sid)
  • Revision ID: package-import@ubuntu.com-20111125132412-dc4qvhyosk74cd42
Tags: 1.0.1-4
Don't assume that arch:all packages will get built (closes: #649726)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *    Copyright (c) <2002-2004> <Jean-Philippe Barrette-LaPierre>
3
 
 *    
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:
11
 
 *    
12
 
 *    The above copyright notice and this permission notice shall be included
13
 
 *    in all copies or substantial portions of the Software.
14
 
 *    
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.
22
 
 */
23
 
 
24
 
#ifndef LIFETIME_LIBRARY_HPP
25
 
#define LIFETIME_LIBRARY_HPP
26
 
 
27
 
#include <cassert>
28
 
#include <algorithm> 
29
 
#include "PrivateMembers.hpp"
30
 
#include "CreationUsingNew.hpp"
31
 
 
32
 
namespace utilspp
33
 
{
34
 
   
35
 
   template< typename T >
36
 
   unsigned int getLongevity( T *p );
37
 
 
38
 
   /**
39
 
    * Assigns an object a longevity. Ensures ordered destructions of objects
40
 
    * registered thusly during the exit sequence of the application.
41
 
    */
42
 
   template< typename T, typename TDestroyer >
43
 
      void setLibraryLongevity( 
44
 
            T *obj, 
45
 
            unsigned int longevity, 
46
 
            TDestroyer d = utilspp::PrivateMembers::Deleter< T >::deleteObject
47
 
            );
48
 
 
49
 
  /**
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:
53
 
   *
54
 
   * LifetimeLibrarySingleton::instance().terminate()
55
 
   *
56
 
   * This singleton use the utilspp::LifetimeWithLongevity policy.
57
 
   */
58
 
  template< typename T >
59
 
  struct LifetimeLibrary
60
 
  {
61
 
    static void scheduleDestruction( T *obj, void (*func)() );
62
 
    static void onDeadReference();
63
 
  };
64
 
  
65
 
  class LifetimeLibraryImpl
66
 
  {
67
 
  public:
68
 
    LifetimeLibraryImpl();
69
 
    ~LifetimeLibraryImpl();
70
 
    
71
 
    void add( utilspp::PrivateMembers::LifetimeTracker *tracker );
72
 
    void terminate();
73
 
    
74
 
  private:
75
 
    utilspp::PrivateMembers::TrackerArray mTrackerArray;
76
 
    int mNbElements;
77
 
  };
78
 
  
79
 
  unsigned int getLongevity( utilspp::LifetimeLibraryImpl *p );
80
 
 
81
 
  typedef utilspp::SingletonHolder< 
82
 
    utilspp::LifetimeLibraryImpl,
83
 
    utilspp::CreationUsingNew,  
84
 
    utilspp::LifetimeWithLongevity
85
 
    > LifetimeLibrarySingleton;
86
 
 
87
 
  /**
88
 
   * This class will ensure that 
89
 
   *
90
 
   * LifetimeLibraryImpl::terminate() 
91
 
   *
92
 
   * is called.
93
 
   */
94
 
  template< typename T = utilspp::LifetimeLibrarySingleton >
95
 
  class LifetimeLibraryGuard
96
 
  {
97
 
  public:
98
 
    ~LifetimeLibraryGuard();
99
 
  };
100
 
};
101
 
 
102
 
#include "LifetimeLibrary.inl"
103
 
 
104
 
#endif