ReferenceAble.h
1 //-*-C++-*-
2 /***************************************************************************
3  *
4  * Copyright (C) 2004 by Willem van Straten
5  * Licensed under the Academic Free License version 2.1
6  *
7  ***************************************************************************/
8 
9 // psrchive/Util/units/ReferenceAble.h
10 
11 #ifndef __ReferenceAble_h
12 #define __ReferenceAble_h
13 
14 #include <vector>
15 #include <string>
16 
17 #include "HeapTracked.h"
18 
19 namespace Reference {
20 
22  extern bool verbose;
23 
25 
35  class Able : public HeapTracked {
36 
37  template<class Type, bool active> friend class To;
38 
39  public:
40 
42  Able ();
43 
45  Able (const Able&);
46 
48  Able& operator = (const Able&);
49 
51  virtual ~Able();
52 
54  unsigned get_reference_count() const { return __reference_count; }
55 
57  static size_t get_instance_count ();
58 
59  protected:
60 
62  class Handle;
63 
65  Handle* __reference (bool active) const;
66 
68  void __dereference (bool auto_delete = true) const;
69 
70  private:
71 
73  mutable Handle* __reference_handle;
74 
76  mutable unsigned __reference_count;
77 
78  };
79 
81  class Able::Handle {
82 
83  private:
85  Handle (const Handle&);
86 
88  Handle& operator = (const Handle&);
89 
90  public:
91 
93  Handle ();
94 
96  ~Handle();
97 
99  Able* pointer;
100 
102  unsigned handle_count;
103 
105  void decrement (bool active, bool auto_delete);
106 
108  static void copy (Handle* &to, Handle* const &from, bool active);
109 
110  };
111 
112 }
113 
114 #endif // #ifndef __ReferenceAble_h
115 
116 
117 
virtual ~Able()
Destructor.
Definition: ReferenceAble.C:181
Able * pointer
Pointer to Able instance.
Definition: ReferenceAble.h:104
Able()
Default constructor.
Definition: ReferenceAble.C:80
~Handle()
Destructor.
Definition: ReferenceAble.C:333
Contains two basic classes that simplify dynamic memory management.
Definition: HeapTracked.h:17
unsigned handle_count
Count of all references to this handle.
Definition: ReferenceAble.h:107
Handle()
Default constructor.
Definition: ReferenceAble.C:312
static void copy(Handle *&to, Handle *const &from, bool active)
Thread-safe copy and increment.
Definition: ReferenceAble.C:283
Able & operator=(const Able &)
Assignment operator.
Definition: ReferenceAble.C:102
static size_t get_instance_count()
Returns the current number instances in existence.
Definition: ReferenceAble.C:73
Manages Reference::To references to the instance.
Definition: ReferenceAble.h:40
Definition: ReferenceAble.h:86
void decrement(bool active, bool auto_delete)
Thread-safe decrement and delete.
Definition: ReferenceAble.C:229
bool verbose
Verbosity flag.
Definition: ReferenceAble.h:27
unsigned get_reference_count() const
Returns the number of references there are to this.
Definition: ReferenceAble.h:59
Handle * __reference(bool active) const
Add the address of a reference to this object.
Definition: ReferenceAble.C:112
void __dereference(bool auto_delete=true) const
Remove the address of a reference to this object.
Definition: ReferenceAble.C:201

Generated using doxygen 1.8.17