Overture  Version 25
ReferenceCounting.h
Go to the documentation of this file.
1 #ifndef _ReferenceCounting
2 #define _ReferenceCounting
3 
4 //
5 // Who to blame: Geoff Chesshire
6 //
7 
8 #include "OvertureDefine.h"
9 #ifndef OV_USE_OLD_STL_HEADERS
10 #include <iostream>
11 #else
12 #include <iostream.h>
13 #endif
14 #include "aString.H"
15 #include "OvertureTypes.h"
16 
18  public:
19  inline ReferenceCounting() {
20  className = "ReferenceCounting";
21  globalID = incrementGlobalIDCounter();
22  referenceCount = uncountedReferences = 0;
23  }
24  inline ReferenceCounting
25  (const ReferenceCounting& x, const CopyType ct = DEEP) {
26  className = "ReferenceCounting";
27  globalID = incrementGlobalIDCounter();
28  referenceCount = uncountedReferences = 0;
29  if (&x || &ct);
30  }
31  inline virtual ~ReferenceCounting() {
32  if (referenceCount) {
33  cerr << "ReferenceCounting::~ReferenceCounting(): "
34  << "referenceCount != 0 for globalID = "
35  << getGlobalID() << "." << endl;
36  abort();
37  } // end if
38  }
39  inline virtual ReferenceCounting& operator=(const ReferenceCounting& x)
40  { if (&x); return *this; }
41  inline virtual void reference(const ReferenceCounting& x) { if (&x); }
42  inline virtual void breakReference() { }
44  (const CopyType ct = DEEP) const
45  { return new ReferenceCounting(*this, ct); }
47  { return ++referenceCount + uncountedReferences; }
49  { return --referenceCount + uncountedReferences; }
50  inline Integer getReferenceCount() const
51  { return referenceCount + uncountedReferences; }
53  if (!referenceCount) uncountedReferences = 1;
54  return uncountedReferences;
55  }
56  inline virtual aString getClassName() const { return className; }
57  Integer getGlobalID() const { return globalID; }
58  // change the global ID -- not a wise thing to normally do -- used by plotting routines.
59  void setGlobalID(int id) { globalID=id; }
60  virtual void consistencyCheck() const;
61  private:
62  Integer referenceCount;
63  Integer uncountedReferences;
64  Integer globalID;
65  aString className;
66  static Integer globalIDCounter;
67  static Integer incrementGlobalIDCounter();
68 };
69 ostream& operator<<(ostream& s, const ReferenceCounting& x);
70 
71 #endif // _ReferenceCounting