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

TObjectID Class Reference

A class for storing an object ID. More...

#include <link.h>

List of all members.

Public Methods

 TObjectID ()
 TObjectID (const TObjectID &Object)
 TObjectID (const byte *ByteArray, bool bTemp=false)
 TObjectID (const int *IntArray, bool bTemp=false)
bool isNull () const
bool isTemp () const
bool load (TDataPackageList *in, const string &sIdentifier, bool bUnique=true)
TObjectID & operator= (const TObjectID &Object)
TObjectID operator++ ()
TObjectID operator++ (int)
bool operator== (const TObjectID &Object) const
bool operator!= (const TObjectID &Object) const
bool operator< (const TObjectID &Object) const
bool save (TDataPackageList *out, const string &sIdentifier, bool bUnique=true, bool bAutoDelete=false) const
void setID (const byte *ByteArray, bool bTemp=false)
void setID (const int *IntArray, bool bTemp=false)
void setNull ()
void setTemp (bool bTemp)
void write (ostream &out) const

Static Public Methods

int getIDSize ()

Static Public Attributes

const int ID_SIZE = 6

Private Attributes

byte ObjectID [ID_SIZE]
bool bTemp

Friends

class TLinkUpdate


Detailed Description

A class for storing an object ID.

Author:
Marco Krohn <marco.krohn@gmx.de>
Version:
Id:
link.h,v 1.38 2002/05/15 08:30:55 ishark Exp
See also:
TLinkable
This class is just a wrapper class for a byte array. The array size is determined by the constant ID_LENGTH. This gives (at the moment 6 bytes) about 2.8 * 10^14 different object ID's which should be enough for all purposes. Standard methods like equal operator, comparison operators etc. are implemented.

In addition to the 6 byte array TObjectID stores a flag which shows if the ID is a real one or just temp. (temp in the sense that this ID is at once transformed to a real ID on the server side. Therefore temp IDs exist on the client-side only) This is useful on the client side, since the objects generated there (e.g. split fleet) need new ID numbers which are not unique. Note: temp IDs do only exist on the client side, never on the server side. The necessary transformation of the IDs is part of TLinkUpdate.

TObjectID is mainly used in TLinkable to give all linkable objects their own and unique ID.


Constructor & Destructor Documentation

TObjectID::TObjectID  
 

The constructor sets bTemp = false and calls setNull to initialize the array with 0.

TObjectID::TObjectID const TObjectID &    Object
 

Copy constructor to allow calls like: TObjectID One = Two;

Parameters:
Object  The new ID for this object.

TObjectID::TObjectID const byte *    ByteArray,
bool    bTemp = false
 

Initialization of the object ID with a byte array. bTemp is set to false.

Parameters:
ByteArray  An array of bytes. The array should have at least the same size as the TObjectID, that means TObjectID::GetSize() elements.
bTemp  The value for the temp flag (default false).
See also:
SetID, GetSize

TObjectID::TObjectID const int *    IntArray,
bool    bTemp = false
 

Constructor for initializing the object with an integer array. It is assumed that the integers are between 0 and 255 otherwise the method sends a warning message to the log file.

Parameters:
IntArray  An array of integers. The array should have at least the same size as the TObjectID, that means TObjectID::GetSize() elements.
bTemp  The value for the temp flag (default false).
See also:
SetID, GetSize


Member Function Documentation

int TObjectID::getIDSize   [static]
 

Returns:
The number of bytes used for storing the ID. (Note: the result is not equal to sizeof(TObjectID).)

bool TObjectID::isNull   const
 

Returns:
true if the ID is null, otherwise false. (Note: the result does not depend on the setting of the variable bTemp.)

bool TObjectID::isTemp   const
 

Returns:
true if the ID is temp, otherwise false.

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

Loads a TObjectID 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.

bool TObjectID::operator!= const TObjectID &    Object const
 

Compares two IDs to find out if they are different.

Parameters:
Object  The ID to compare with.
Returns:
true if the two IDs are the different.
See also:
operator==

TObjectID TObjectID::operator++ int   
 

The (postfix) incrementation operator increases the ID by 1.

Parameters:
Is  not used but is necessary to differ between the postfix and the prefix version (the prefix version has no int parameter).
Returns:
The old ID.

TObjectID TObjectID::operator++  
 

The (prefix) incrementation operator increases the ID by 1.

Returns:
The new ID.

bool TObjectID::operator< const TObjectID &    Object const
 

Compares two IDs to find out which of them is smaller. Note: a temp ID is always smaller than a real ID.

Parameters:
Object  The ID to compare with.
Returns:
true if the ID of Object is greater then the other ID, otherwise the method returns false.

TObjectID& TObjectID::operator= const TObjectID &    Object
 

The standard equal operator simply copies the byte array and the bTemp flag.

Parameters:
object  The source object.
Returns:
A reference to the dest object.

bool TObjectID::operator== const TObjectID &    Object const
 

Compares two IDs to find out if they are equal. Note that two IDs are never identical if their temp flag differs.

Parameters:
Object  The ID to compare with.
Returns:
true if the two IDs are the same (including the temp flag).
See also:
operator!=

bool TObjectID::save TDataPackageList   out,
const string &    sIdentifier,
bool    bUnique = true,
bool    bAutoDelete = false
const
 

Creates the data package for a TObjectID object and adds it to the data package list. Note: Do not modify the auto delete setting of the data package!

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.
bAutoDelete  Setting this flag to true means that _this_ object will automatically be deleted by the TDataPackageList. Use with care!
Returns:
true if everything worked fine, otherwise false (e.g. if the identifier was already used in the data package list).

void TObjectID::setID const int *    IntArray,
bool    bTemp = false
 

Reads an array of integers to initalize the object. Since integers have a different range, values >255 are treated as 255, values <0 are treated as 0.

Parameters:
ByteArray  An array of integers which should have a size (number of entries) equal or greater than getIDSize.
bTemp  The value for the temp flag.

void TObjectID::setID const byte *    ByteArray,
bool    bTemp = false
 

Reads an array of bytes to initalize the object.

Parameters:
ByteArray  An array of bytes which should have a size equal or greater than getIDSize.
bTemp  The value for the temp flag.

void TObjectID::setNull  
 

Sets the ID to { 0, 0, ..., 0 }. The temp flag bTemp is not changed.

See also:
setTemp

void TObjectID::setTemp bool    bTemp
 

Sets the bTemp flag. Note: the ID is not changed.

Parameters:
bTemp  The new value for the temp flag.
See also:
setNull

void TObjectID::write ostream &    out const
 

Writes the ID to a stream. The result looks like: "[0f,00,00,00,00,00]" or if it is a temp object "temp[01,04,00,00,00,00]".

Parameters:
out  The output stream.


Member Data Documentation

bool TObjectID::bTemp [private]
 

Describes if the ID is a temp or a real one

const int TObjectID::ID_SIZE = 6 [static]
 

The number of bytes used for one ID

byte TObjectID::ObjectID[ID_SIZE] [private]
 

The ID is an array of a fixed number of bytes


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