Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members
TDataPackage Class Reference
A wrapper for data.
More...
#include <datapackage.h>
List of all members.
Public Types |
enum | tType {
BOOL = 0,
DATA_PACKAGE_LIST,
DOUBLE,
ID,
INTEGER_2,
INTEGER_4,
POINT,
STRING
} |
Public Methods |
| TDataPackage () |
| TDataPackage (const string &sIdentifier, const bool *pData) |
| TDataPackage (const string &sIdentifier, const double *pData) |
| TDataPackage (const string &sIdentifier, const int2 *pData) |
| TDataPackage (const string &sIdentifier, const int4 *pData) |
| TDataPackage (const string &sIdentifier, const string *pData) |
| TDataPackage (const string &sIdentifier, const TDataPackageList *pData) |
| TDataPackage (const string &sIdentifier, const TObjectID *pData) |
| TDataPackage (const string &sIdentifier, const TPoint *pData) |
| ~TDataPackage () |
bool | GetAutoDeleteMode () const |
const string & | GetIdentifier () const |
const tType | GetType () const |
| operator bool * () const |
| operator double * () const |
| operator int2 * () const |
| operator int4 * () const |
| operator string * () const |
| operator TDataPackageList * () const |
| operator TObjectID * () const |
| operator TPoint * () const |
void | SetAutoDeleteMode (bool bAutoDelete) |
void | SetData (const string &sIdentifier, const bool *pData) |
void | SetData (const string &sIdentifier, const double *pData) |
void | SetData (const string &sIdentifier, const int2 *pData) |
void | SetData (const string &sIdentifier, const int4 *pData) |
void | SetData (const string &sIdentifier, const TDataPackageList *pData) |
void | SetData (const string &sIdentifier, const TObjectID *pData) |
void | SetData (const string &sIdentifier, const TPoint *pData) |
void | SetData (const string &sIdentifier, const string *pData) |
Private Methods |
void | CheckAutoDelete () |
void | Reset () |
Private Attributes |
bool | bAutoDelete |
void * | pData |
string | sIdentifier |
tType | type |
Detailed Description
A wrapper for data.
-
Author:
-
Marco Krohn <marco.krohn@gmx.de>
-
Version:
-
-
Id:
-
datapackage.h,v 1.19 2002/06/07 00:32:38 mkrohn5 Exp
-
See also:
-
TDataPackageList
(This is the reference for TDataPackage and TDataPackageList)
A data package is a wrapper for all kind of elementary data. The general problem this class and TDataPackageList are going to solve is the transportation problem of data. With the help of TDataPackage and TDataPackageList you can unite very different data like (e.g. bool
, string
and double)
to a package list and send this list to the receiver who has easily access to the stored data.
Note: for convenience there are several methods implemented in TDataPackageList which reduce the need to understand TDataPackage to almost zero.
As mentioned above the data package is only designed for elementary data, more complex data (e.g. TPlanet) is handled as a composite data object consisting of many data packages (see TDataPackageList for details). TDataPackage is quite flexible in its usage: it stores a pointer to the "real data" (often refered as "content") and let the creator of the data package decide whether the content should be automatically deleted or not. Since the data package stores only a pointer you have to ensure that the pointer is still valid, when the data package is used by the receiver. For example
TDataPackageList* foo( TDataPackageList* dpl )
{
string s = "this data will not survive";
dpl->add( "keyword", &s, true );
return dpl;
}
would be fatal since the pointer gets invalid after leaving the method. (Note the "true" in the add function guarantees that a data package name does not occur twice.)
In this case the right thing to do is making a "deep copy" of the object:
TDataPackageList* foo( TDataPackageList* dpl )
{
string s = "this data will not survive";
dpl->add( "keyword", new string(s), true, true );
return dpl;
}
This makes (I have not tested it yet, so please tell me if the code is wrong, FIXME) a deep copy of the object and "sends" the resulting pointer to the data package. Now of course the data package has to take care of deleting the content. This is achieved by adding the last parameter: "true" (means that the autodelete is activated for this package).
If you are looking for more examples of TDataPackageList you should have a look at the load and save methods, as well as the parser. The data package system also plays a central role in the rule atom mechanism.
In case you want to add another data type to TDataPackage, please have a look at the code of CheckAutoDelete
and TDataPackageList::WriteDataPackage
. And check if it is really neccessary to add another data type or if an composite type would do it as well.
Constructor & Destructor Documentation
TDataPackage::TDataPackage |
( |
|
) |
|
|
TDataPackage::TDataPackage |
( |
const string & |
sIdentifier, |
|
|
const bool * |
pData |
|
) |
|
|
TDataPackage::TDataPackage |
( |
const string & |
sIdentifier, |
|
|
const double * |
pData |
|
) |
|
|
TDataPackage::TDataPackage |
( |
const string & |
sIdentifier, |
|
|
const int2 * |
pData |
|
) |
|
|
TDataPackage::TDataPackage |
( |
const string & |
sIdentifier, |
|
|
const int4 * |
pData |
|
) |
|
|
TDataPackage::TDataPackage |
( |
const string & |
sIdentifier, |
|
|
const string * |
pData |
|
) |
|
|
TDataPackage::TDataPackage |
( |
const string & |
sIdentifier, |
|
|
const TDataPackageList * |
pData |
|
) |
|
|
TDataPackage::TDataPackage |
( |
const string & |
sIdentifier, |
|
|
const TObjectID * |
pData |
|
) |
|
|
TDataPackage::TDataPackage |
( |
const string & |
sIdentifier, |
|
|
const TPoint * |
pData |
|
) |
|
|
TDataPackage::~TDataPackage |
( |
|
) |
|
|
Member Function Documentation
void TDataPackage::CheckAutoDelete |
( |
|
) |
[private] |
|
bool TDataPackage::GetAutoDeleteMode |
( |
|
) |
const |
|
const string& TDataPackage::GetIdentifier |
( |
|
) |
const |
|
|
-
Returns:
-
The identifier for this data package.
|
const tType TDataPackage::GetType |
( |
|
) |
const |
|
|
-
Returns:
-
The type for this data package.
|
TDataPackage::operator bool * |
( |
|
) |
const |
|
|
Cast operator to type bool* . |
TDataPackage::operator double * |
( |
|
) |
const |
|
|
Cast operator to type double* . |
TDataPackage::operator int2 * |
( |
|
) |
const |
|
|
Cast operator to type int2* . |
TDataPackage::operator int4 * |
( |
|
) |
const |
|
|
Cast operator to type int4* . |
TDataPackage::operator string * |
( |
|
) |
const |
|
|
Cast operator to type string* . |
TDataPackage::operator TPoint * |
( |
|
) |
const |
|
|
Cast operator to type TPoint* . |
void TDataPackage::Reset |
( |
|
) |
[private] |
|
void TDataPackage::SetAutoDeleteMode |
( |
bool |
bAutoDelete |
) |
|
|
|
Enabling auto-delete (enable is true) will automatically delete the object whenever the pointer variable pData is changed. The default setting is false .
Examples: Setting new data (the old data is than deleted automatically) and calling the destructor. -
Parameters:
-
The |
new value for the auto delete mode. If set to true the objects this object wraps will be deleted. |
|
void TDataPackage::SetData |
( |
const string & |
sIdentifier, |
|
|
const bool * |
pData |
|
) |
|
|
Member Data Documentation
bool TDataPackage::bAutoDelete [private]
|
|
|
Current settings for the auto-delete mode (see SetAutoDeleteMode for more information). |
void* TDataPackage::pData [private]
|
|
|
Pointer to the real data. |
string TDataPackage::sIdentifier [private]
|
|
|
An identifier for the data. |
tType TDataPackage::type [private]
|
|
The documentation for this class was generated from the following file:
Generated on Thu Jun 20 18:13:19 2002 for Stellar Legacy by
1.2.13.1 written by Dimitri van Heesch,
© 1997-2001