Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

TLinkBase Class Reference

An easy way to link objects. More...

#include <link.h>

Inheritance diagram for TLinkBase:

Inheritance graph
[legend]
Collaboration diagram for TLinkBase:

Collaboration graph
[legend]
List of all members.

Public Types

enum  { LINK_BASE = 0, LINK, DOUBLE_LINK }

Public Methods

 TLinkBase ()
 TLinkBase (TLinkable *p)
 TLinkBase (const TObjectID &DestID)
 TLinkBase (const TLinkBase &link)
virtual ~TLinkBase ()
TLinkablegetDest () const
const TObjectIDgetDestID () const
int2 getDestType () const
virtual int2 getType () const
const string & getDestTypeName () const
bool isNull () const
bool isUpdated () const
bool isValid () const
bool load (TDataPackageList *in, const string &sIdentifier, bool bUnique=true)
TLinkBase & operator= (const TLinkBase &src)
bool operator== (const TLinkBase &Two) const
bool save (TDataPackageList *out, const string &sIdentifier, bool bUnique=true) const
virtual void setDest (TLinkable *p)
virtual void setNull ()
void Write (ostream &out) const

Protected Methods

void removeUpdateRequest ()
void requestUpdate ()
void reset ()
void setDest (const TObjectID &DestID)

Protected Attributes

bool bNeedUpdate
TLinkablepDest
TObjectID DestID

Static Protected Attributes

TObjectID NullID

Friends

class TLinkUpdate
class TLinkable

Detailed Description

An easy way to link objects.

Author:
Marco Krohn <marco.krohn@gmx.de>
Version:
Id:
link.h,v 1.38 2002/05/15 08:30:55 ishark Exp
See also:
TLink, TLinkable, TLinkUpdate
This is the base class for linking objects. Setting a link to an object does not only store the pointer to the dest object but also the destination ID. That makes it possible to load and save links which is normaly (using pointers only) almost impossible.

While loading the game the link receives only the dest ID and not the pointer to the object (see setDest(const TObjectID&) ). There is no way around this because the dest object might be loaded after the object which sets the link. The bNeedUpdate flag shows if the link is complete or needs an update. The information if the link needs an update (to become a "real" link) is also stored in the TLinkUpdate class (see TLinkUpdate for details about the update process).

A link is always in one of the three following states:

  1. Null link (comparable with a null pointer)
    That means that the destination pointer (pDest) is 0 as well as the dest ID is 0. The method isNull can be used to find out if the link is a null link or not.
  2. "Real" link (the "normal" state)
    The ID as well as the pointer have values which are different from 0. The link is in any case valid if isValid says so. If the dest object is deleted than the link will automatically (this is a special feature of the TLinkable class) be set to a null link (see above). Use the method isValid to find out if the link is a real one or not.
  3. Link waiting for update
    This state normaly only occurs during the loading process (see TLinkUpdate for more details). The link needs an update (the internal update flag bNeedUpdate is set to true). The dest ID has a value and the pointer is set to 0 so in this case the link is also a null link. The method isUpdated shows if the link is waiting for an update or not.
A special feature of the TLink and TLinkable classes is that links always point to valid objects or are null links. If a dest object is removed the link will automatically be set to null (see TLinkable for more details).


Member Enumeration Documentation

anonymous enum
 

see getType for details.


Constructor & Destructor Documentation

TLinkBase::TLinkBase  
 

Creates an empty link by calling the method reset.

TLinkBase::TLinkBase TLinkable   p
 

Initializes the object with the destination object. The ID of the destination object is copied to this object.

Parameters:
p  The destination object of the link.

TLinkBase::TLinkBase const TObjectID   DestID
 

Initializes the object with the destination ID. The pointer will be updated when the link/object couple is committed.

Parameters:
DestID  The destination ID of the link.

TLinkBase::TLinkBase const TLinkBase &    link
 

Copy constructor.

Parameters:
link  The destination of the link.

virtual TLinkBase::~TLinkBase   [virtual]
 

Removes the link. If the link needs an update it is also removes the update request from TLinkUpdate.


Member Function Documentation

TLinkable* TLinkBase::getDest   const
 

Returns:
The pointer to the dest object or 0 if the dest object does not exist.

const TObjectID& TLinkBase::getDestID   const
 

Returns:
The ID of the dest object.

int2 TLinkBase::getDestType   const
 

Returns:
The type of the dest object.
See also:
TType

const string& TLinkBase::getDestTypeName   const
 

Returns:
The name of the type of the dest object.
See also:
TType

virtual int2 TLinkBase::getType   const [virtual]
 

Note: there are three different link types possible: TLinkBase, TLink and TDoubleLink. In some cases it is useful to know whether the object is a double link or not (this is the main reason for this method). Also note that using RTTI might be unhandy since TLink, TDoubleLink are template classes and therefore decideing if the object is a TDoubleLink object might be difficult.

Returns:
The link type.

Reimplemented in TLink, TDoubleLink, TLink< TArmorType >, TLink< TActionObject >, TLink< TShipDesign >, TLink< TStellarObject >, TLink< TItem >, TLink< TFleet >, TLink< TGalaxy >, TLink< TPlayer >, TLink< TShieldType >, TLink< TSubstanceType >, and TLink< TRace >.

bool TLinkBase::isNull   const
 

Checks if the link is a null object (that means that the destination pointer and the dest ID is 0). Note: a null link never needs an update.

Returns:
true if pDest and DestID is zero, otherwise false.
See also:
IsValid

bool TLinkBase::isUpdated   const
 

Returns:
true if the object does not need an update. If the object is waiting an update the method returns false.

bool TLinkBase::isValid   const
 

Returns:
true if the link points to a real object, otherwise false. Note: you can always(!) trust this information. Links will automatically be set to null if the dest object is deleted (see TLinkable for more information on inverse links). Note also that a link that is waiting for an update is not a valid link. (For more details please see the class description above.)
See also:
IsNull

bool TLinkBase::load TDataPackageList   in,
const string &    sIdentifier,
bool    bUnique = true
 

Loads a TLinkBase object from a list of data packages. Note that a successful load will delete the datapackage from the data package list as well as the datapackage itself.

Parameters:
in  The input stream of data packages.
sIdentifier  The identifier to look for.
bUnique  Loads the data only if the identifier is unique.
Returns:
true means that everything was loaded correctly, otherwise this method will return false.

TLinkBase& TLinkBase::operator= const TLinkBase &    src
 

The standard operator= copies all components. It also takes care that if src needs an update that the copy also gets an update.

Parameters:
src  The link you want to copy.
Returns:
The new link.

bool TLinkBase::operator== const TLinkBase &    Two const
 

Two links are equal if they need no update and if their destination object is the same.

void TLinkBase::removeUpdateRequest   [protected]
 

If bNeedUpdate is set to true this method will remove the update request from TLinkUpdate and reset all values to zero.

See also:
Reset

void TLinkBase::requestUpdate   [protected]
 

Sets bNeedUpdate to true and requests an update from TLinkUpdate. @RemoveUpdateRequest

void TLinkBase::reset   [protected]
 

Resets the link to the default values, that means bNeedUpdate to false, pDest = 0, DestID = 0. Note: This method will _not_ check if the bNeedUpdate flag is true and also will not remove the inverse link to avoid recursion loops.

bool TLinkBase::save TDataPackageList   out,
const string &    sIdentifier,
bool    bUnique = true
const
 

Creates the data package of TLinkBase object and adds it to the data package list.

Parameters:
out  The list of data packages.
sIdentifier  The identifier which is used to store and find the data.
bUnique  If set to true the method will check if the identifier was already used in the data package list.
Returns:
true if everything worked fine, otherwise false (e.g. if the identifier was already used in the data package list).

void TLinkBase::setDest const TObjectID   DestID [protected]
 

Sets an incomplete link, since only the dest ID is known. This will automatically set the bUpdateFlag to true. The dest pointer (pDest) is set to 0 so that isNull will always return true.

virtual void TLinkBase::setDest TLinkable   p [virtual]
 

Sets a link to an object type of TLinkable.

Parameters:
p  pointer to the object which should be linked.

Reimplemented in TLink, TLink< TArmorType >, TLink< TActionObject >, TLink< TShipDesign >, TLink< TStellarObject >, TLink< TItem >, TLink< TFleet >, TLink< TGalaxy >, TLink< TPlayer >, TLink< TShieldType >, TLink< TSubstanceType >, and TLink< TRace >.

virtual void TLinkBase::setNull   [virtual]
 

Changes the link to a null link (that means that the destination pointer and the dest ID is 0). Note: Identical to call setDest(0).

See also:
setDest(TLinkable*)

Reimplemented in TLink, TLink< TArmorType >, TLink< TActionObject >, TLink< TShipDesign >, TLink< TStellarObject >, TLink< TItem >, TLink< TFleet >, TLink< TGalaxy >, TLink< TPlayer >, TLink< TShieldType >, TLink< TSubstanceType >, and TLink< TRace >.

void TLinkBase::Write ostream &    out const
 

Writes the dest ID to a stream.

Parameters:
out  The output stream.


Member Data Documentation

bool TLinkBase::bNeedUpdate [protected]
 

Shows if the link needs an update or not. This flag is only useful while loading the game.

TObjectID TLinkBase::DestID [protected]
 

The ID of the dest object.

TObjectID TLinkBase::NullID [static, protected]
 

ID which is null.

TLinkable* TLinkBase::pDest [protected]
 

The dest object.


The documentation for this class was generated from the following file:
Generated on Thu Jun 20 18:13:27 2002 for Stellar Legacy by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001