e4_RefCount Methods and Constructors
Author: Jacob Levy

The e4_RefCount Class

The e4_RefCount class is the base class for the e4_Storage, e4_Node, and e4_Vertex classes. It provides reference counting based automated memory management for instances of derived classes, and enables type-safe casting from e4_RefCount to a specific derived type, as well as a method for testing which derived class an instance is actually of.

Here's an example of how to do type-safe casting with the methods provided by the e4_RefCount class:

>     e4_RefCount r = ...;
>     e4_Node n;
>     ...
>     if (r.Kind() == E4_RKNODE) {
>         n = (e4_Node) r;
>     }

If the cast were not type-safe, after the assignment the value of n would be invalidNode.

The e4_RefCount class is not intended to be instantiated directly. Instead, it provides common methods that are of use in derived classes. The following methods and constructors are provided by the e4_RefCount class:

e4_RefCount Methods and Constructors
e4_RefCount() | Default constructor. Returns an invalid instance.
e4_RefCount(const e4_RefCount &ref) | Copying constructor. Returns an instance of e4_RefCount whose state is the same as ref.
~e4_RefCount() | Destructor. Decrements the reference count for the underlying representation and if this is the last reference, its memory is automatically freed.
e4_RefCount & operator=(const e4_RefCount ref) | Assignment operator. Makes the state of this the same as ref and returns this.
bool operator==(const e4_RefCount &comp) const | Returns true if comp and this refer to the same instance or if both are invalid and of the same derived class, false otherwise.
bool operator!=(const e4_RefCount &comp) const | Returns false if comp and this refer to the same instance, false otherwise.
int RefCount() const | Returns the reference count of this instance; this number denotes the number of program variables holding references to this instance. Returns -1 for an invalid instance.
virtual e4_RefKind Kind() const | Returns the e4_RefKind constant denoting the derived type that this instance is actually of. For an illegal instance, returns E4_RKINVALID.
bool IsValid() const | Returns true if this instance is valid; returns false otherwise.
long GetTemporaryUID() | Returns a long value that uniquely identifies this instance as long as it is valid. Returns -1 for all invalid instances.
void SetTransientUserData(void *data) const | Associates a user-specified piece of data with this instance. The association is valid as long as the instance stays valid.
void *GetTransientUserData() const | Retrieves a previously assigned user-specified piece of data associated with this instance. If the instance is invalid, or no data has been previously associated with this instance, returns NULL