TParamFile

List of ancestors:
TObj
Files:
params.h, params.cpp

Desc. & Idea Warnings Methods Attributes Operators Specials

 

Abstract  Abstract

Virtual  Virtual Overridden  Overridden
Key, Important  Key, Important Constructor  Constructor Destructor  Destructor
Methods beginning with Get or Set (get/set) are usually intended to access Attributes of same name (exceptions will be marked).

 

Description

This class is intended to simply access and use a bunch of parametric files as shown in the params.h.

Title

 

Warnings

Avoid to open a file with flSet ("save after work") flag more then ones. This is because during the save the file is overwritten not changed.
Inserted parameters are really inserted not copied.
Don't create any parts of TParamFile on stack(TGroup, TAParam, TPFileID) as they are destroyed with the parent TParamFile.

Title

 

Methods

Public:

void AddDirective(char *aFilename,char *aDirective)
void AddFileID(TPFileID *Who)
void AddRemark(char *aFilename,char *aRemark)
Key, Important TAParam *AddParam(TAParam *NewParam,char* Groupname,char* Filename)
BOOL ChangeFilename(char *From, char *To)
void Clear()
void Close(char *aFilename)
VirtualKey, Important BOOL Exist(char *)
TParamFile *Extract(char * aFilename)
TStrList *GetDirectives(char *aFilename)
VirtualKey, Important TPFileID* GetFileID(char *FileName)
VirtualKey, Important TGroup * GetGroup(char *Called)
TPFileID *GetNo1FileID()
Key, Important TAParam *GetParam(char *Called)
TStrList *GetRemarks(char *aFilename)
OverriddenKey, Important uint GetSerSize(BOOL subclass=FALSE)
void Load(char *aFilename,TFlag OpenType=flNotSet,BOOL Control=TRUE)
void Merge(TParamFile &With, BOOL Control=TRUE)
Key, Important BOOL ReadBool(char *Called,BOOL DefVal)
Key, Important char ReadChar(char *Called,char DefVal)
Key, Important float ReadFloat(char *Called,float DefVal)
Key, Important int ReadInt(char *Called,int DefVal)
Key, Important char *ReadString(char *Called,char *DefVal)
Key, Important TFit ReadTFit(char *Called,TFit DefVal)
Key, Important TProb ReadTProb(char *Called,TProb DefVal)
void Save(char *aFilename)
void SaveAll()
void SaveInto(char *aFilename)
OverriddenKey, Important uint Serialize(BYTE **rawbytes,BOOL subclass=FALSE)
ConstructorKey, Important TParamFile(BYTE** raw,uint length,BOOL subclass)
ConstructorKey, Important TParamFile(char *aFilename=NULL, TFlag OpenType=flNotSet)
Destructor ~TParamFile(void)


Protected:

void Compact()
TPFileID *EjectFileID(char *aName)
TGroup *GetFirstGrp()
TAParam *GetFirstParam()
TGroup *InsertGroup(TGroup *Who,BOOL Control=TRUE)
TAParam *InsertParam(TAParam *Who,char *GroupName,BOOL Control=TRUE)
BOOL IsSingle()
void NeedCompactUp()
void PutAtBeginning (TAParam *Who)
void PutFileID(TPFileID *thing,FILE *into,BOOL trimed=FALSE)
void PutGroup(TGroup *thing,FILE *into)
void PutParam(TAParam *thing,FILE *into)
void SaveAsociated(TPFileID *asoc,FILE *into)
void SetFirstGrp(TGroup *val)
void SetFirstParam(TAParam* Who)
void WorkUpDirectives(TStrList &Directives, TFlag InheritedState)


Private:


Title


void AddDirective(char *aFilename,char *aDirective)

Adds a directive line into the TPFileID specified by a Filename.
The line is copied.

Arguments:

aFilename...specifies the TPFileID which the directive insert to

aDirecive...the directive line

See also ParamFiles directives

Section Title


void AddFileID(TPFileID *Who)

Inserts the specified TPFileID into the hierarchy

Arguments:

Who...specifies the TPFileID which should be inserted

Section Title


void AddRemark(char *aFilename,char *aRemark)

Adds a remark line into the TPFileID specified by a Filename.
The line is copied.

Arguments:

aFilename...specifies the TPFileID which the remark insert to

aRemark...the remark line

Section Title


TAParam *AddParam(TAParam *NewParam,char* Groupname,char* Filename)

Inserts the specified TAParam into the structure. If the group or TPFileID of the specified names doesn't exist, they are created. The parameter is bounded in not copied.

Arguments:

NewParam... ..the parameter to be inserted
Groupname....the name of the group which the parameter should be inserted to
Filename....the name of the file the parameter belongs to

Returns:

Returns the pointer to the inserted parameter.

Section Title


BOOL ChangeFilename(char *From, char *To)

Changes a TPFileID.Filename specified by the string From to the value To. But this happens only if TPFileID.Filename of value does not exist already.

Arguments:

From... ..old filename; specifies the TPFileID to be affected
To....new filename

Returns:

Returns TRUE if the operation was successful. If the  TPFileID.Filename was not changed FALSE is returned

Section Title


void Clear()

Deletes all parameters, groups and FileIDs. The structure remains empty like after a call of the constructor without parameters.
See also TParamFile(char *, TFlag)

Section Title


void Close(char *aFilename)

Removes the FileID specified by aFilename and saves it if it is said by TPFileID.Saveable. All params pointing to this FileID are also deleted.

Arguments

aFilename...name of the parametric file to be closed

See alsoTPFileID.Saveable, TAParam.SourceFile

Section Title


BOOL Exist(char *aPar)

Answers the question of the existence of a parameter in the structure. If the parameter is found, it is placed on the beginning of the list so later access is faster.

Arguments

aPar...name of the parameter, that should be looked for.

Returns

TRUE if a parameter of the specified name exists, otherwise FALSE.

Section Title


TParamFile *Extract(char * aFilename)

Creates a new TParamFile structure filled with FileID of the specified aFilename and all belonging parameters with their groups. If there is no FileID with the aFilename no new structure is created

Arguments

aFilename...name of the file which parameters should be extracted

Returns

Pointer to the new structure. If a FileID is not found NULL is returned.

See also Merge, operator <<, operator >>

Section Title


TStrList *GetDirectives(char *aFilename)

Get the directives obtained from a specified file.

Arguments

aFilename....the file the directives was taken from

Returns

The TStrList with the directives.

Section Title


TPFileID* GetFileID(char *FileName)

Finds the FileID with the specified Filename in the structure.

Arguments

Filename....the name of the file which the FileID is associated with.

Returns

The TPFileID with the specified Filename or NULL if no such exists.

Section Title


TGroup * GetGroup(char *Called)

Finds the Group with the specified name in the structure.

Arguments

Called....the name of the group to be found

Returns

The appropriate TGroup or NULL if no group of the Called name exists.

See alsoTGroup[], TAParam.GetGrp

Section Title


TPFileID *GetNo1FileID()

Returns

Return the first FileID in the list.

See alsoTPFileID.GetNext

Section Title


TAParam *GetParam(char *Called)

Searches for a parameter with the specified name. If the parameter is found it is placed at the beginning of the list for later faster access.

Arguments

Called...the name of the parameter

Returns

the parameter with the specified name or if no such exists the NotExists is returned

See alsoTParamFile[], TParamFile.Exist, NotExists, TAParam.Name

Section Title


TStrList *GetRemarks(char *aFilename)

Get the remarks obtained from a specified file.

Arguments

aFilename....the file the remarks was taken from

Returns

The TStrList with the remarks.

Section Title


void Load(char *aFilename,TFlag OpenType=flNotSet,BOOL Control=TRUE)

Loads the parameters (builds the structure) from a specified file. The existing structure is destroyed. All directives are handled also.

Arguments

aFilename....the source file
OpenType...the type the file will be handled (changes will be written back or not)
Control....control the duplicity of parameter names

See alsoSave, SaveAll, SaveInto, Close

Section Title


void Merge(TParamFile &With, BOOL Control=TRUE)

The structure specified by the With parameter is build into the local structure.

Arguments:

With.....the TParamFile structure, that should be merged into the local structure.
Control.... to control or not the duplicity of parameter names. The same named parameter stays int the old striker.

See alsooperator<<, operator>>

Section Title


type Readtype(char *Called, type DefVal)

These functions (ReadBool, ReadChar, ReadFloat, ReadInt, ReadString, ReadTFit, ReadTProb) can be used to obtain values from the structure.

Arguments

Called....name of the parameter
DefVal....default value, that should be returned, if no parameter with the specified name exists

Returns

value of the parameter as a type you required, or a DefVal if no parameter is found

See alsoTAParam.Astype

Section Title


void Save(char *aFilename)

Save the specified file with all parameters, groups, remarks and directives belonging into it. Ignores the Saveable TFlag in TPFileID.

Arguments

aFilename...name of the file to be saved

Section Title


void SaveAll()

Save all file in the structure (all TPFileID). All items are added to their parent files. TFlag is ignored.

Section Title


void SaveInto(char *aFilename)

The complete structure is saved into one file. File directives are omitted. The structure is not affected.

Arguments

aFilename...the target filename

Section Title


TParamFile(BYTE** raw,uint length,BOOL subclass)

Deserialization constructor. Rebuilds the structure from the rawbytes serialized before.

See alsoTObj.TObj, TObj.Serialize

Section Title


TParamFile(char *aFilename=NULL, TFlag OpenType=flNotSet)

Constructor. Creates a new empty structure. If aFilename is specified the file is loaded.

Arguments

aFilename....name of the file to be loaded, if NULL the structure remains empty
OpenType...how to handle the file

See alsoLoad

Section Title


~TParamFile(void)

Destructor.The structure is closed and all items are destroyed.

See also Close


Section Title


TGroup *InsertGroup(TGroup *Who,BOOL Control=TRUE)

Inserts the specified TGroup into the hierarchy. This function is for internal use only. Instead use the function AddParam.

Arguments:

Who...specifies the TGroup which should be inserted.

Control...If this flag is set to true, the structure is controlled for existence of a group of the same name If such a group exists items are rather inserted into it, not the new group just simply inserted.

Returns:

Returns the pointer to the target group. The inserted one or , if controlled and exists, the group of the same name that is used for inserted subitems.

Section Title


TAParam *InsertParam(TAParam *Who,char *GroupName,BOOL Control=TRUE)

Inserts the specified TAParam into the hierarchy. This function is for internal use only. Instead use the function AddParam.

Arguments:

Who...specifies the TAParam which should be inserted

GroupName...target group.

Control...control or not the existence of a parameter of the same name.

Returns:

Returns the pointer to the final TAParam.

Section Title


Attributes

Public:

Protected:

TGroup * FirstGrp
TAParam * FirstParam
Key, Important TAParam * NotExist
TPFileID * No1FileID

Private:

BOOL NeedCompact

Title


TGroup *FirtsGrp

Pointer to the first item of the groups list.

Section Title


TAParam *FirstParam

Pointer to the fist item of the params list.

Section Title


TAParam *NotExist

Pointer to the TAParam  that is returned, when a parameter of the specified name doesn't exist. It contains the default values: 0, FALSE, "", #0, 0% etc. The values are read only. The SetValue procedure has no effect.

Section Title


TPFileID *No1FileID

Pointer to the fist item of the TPFileIDs list.

Section Title


BOOL NeedCompact

Flag to specify if the control for empty groups and file IDs is required before a save.

Section Title


Operators

Public:

Key, Important TAParam& operator [] (char* Called)
TParamFile& operator << (TParamFile &With)
TParamFile& operator >> (TParamFile &With)

Protected:
Private:

Title


TAParam& operator [](char *Called)

Returns the TAParam of the specified name. Unlike the function GetParam it return a reference to this object, so a pointed notation can be used. So as the GetParam, if the TAParam doesn't exist, the NotExist param is returned.

Arguments:

Called....the name of the parameter wanted.

Returns:

reference to the requested parameter

Section Title


TParamFile & operator <<(TParamFile& With)

Merges the With parameter into the local structure. See method Merge.

Arguments:

With.....the TParamFile structure, that should be merged into the local structure.

Returns:

reference to the reorganised local structure

Section Title


TParamFile& operator >>(TParamFile& With)

Merges the local striker into the With parameter. See method Merge.

Arguments:

With.....the target TParamFile structure

Returns:

reference to the reorganised With structure

Section Title


Specials

For the syntax of a parametric file see params.h

Title