MFC Grid manual

CFieldMap Class Reference

Contains a table of the fields of the class, inheriting from CDataObject. More...

#include <Dapfor/Common/FieldMap.h>

List of all members.


Public Types

typedef std::set< CField * > Fields
 list of the fields, declared in the field map

Public Member Functions

 CFieldMap ()
 constructor
 CFieldMap (CFieldMap *pParentMap)
 Constructor that is applied in the inheritance chain.
virtual ~CFieldMap ()
 Frees all resources. It also destroys all declared fields.
bool AddField (FID fid, CField *pField)
 Declares a new field.
CFieldGetField (FID fid) const
 Gets a declared field by its identifier.
void GetAllFields (Fields &fields) const
 Gets a list of all declared fields.
CFieldMapGetParentMap ()
 Gets a field map of the parent class in the inheritance chain.
const CFieldMapGetParentMap () const
 Gets a field map of the parent class, const version.
void InitHash ()
 Initializes hash.

Detailed Description

Contains a table of the fields of the class, inheriting from CDataObject.

Fields are stored in a table in the form of key-value. An integer identifier is the key and an object of CField is the value. If the number of the fields is more than 50, then it is recommended to initialize a hash in order to accelerate an access to the data of the object. The class, that derives from CDataObject, can have only one table. The key in the table must be unique and it can't be equal to Common::allFields (-1) or Common::fieldNotSpecified (-2). If there is an inheritance chain, identifiers can be the same in different classes, but within one class, they must be unique. For the field identifiers it is recommended to use enumerations. There are some advantages of enumerations:
1. Friendly named identifiers instead of numeric values.
2. Identifiers can be grouped in class, to which they relate
3. These enumerations can be easily used in field declarations.
4. The same enumerations can be used in columns of GUI::CGrid.
5. If enumerations are used, the application does not depend on numeric value changes.

CFiemdMap is responsible for the live time of CField objects that are destroyed in the destructor of CFiemdMap.

Thread safety:
The table that is declared with DF_DECLARE_FIELD_MAP(), DF_BEGIN_FIELD_MAP() etc. is static and it is not changed at runtime. This table is initialized during the application start. CFieldMap is not thread-safe, but if it is declared as a static table, it is possible to read the fields from different threads.

Constructor & Destructor Documentation

CFieldMap ( CFieldMap pParentMap  ) 

Constructor that is applied in the inheritance chain.

Parameters:
[in] pParentMap Field map of the base class in the inheritance chain from CDataObject


Member Function Documentation

bool AddField ( FID  fid,
CField pField 
) [inline]

Declares a new field.

If a field with the similar identifier is already inserted, the function raises a warning in the debug version of the application, that will permit to find the ambiguity.

Parameters:
[in] fid Numeric identifier. The identifier in the table must be unique and it can't be equal to Common::allFields (-1) or Common::fieldNotSpecified (-2);
[in] pField Pointer to a new field.
Returns:
True if the field has been successfully registered. Otherwise false.

CField * GetField ( FID  fid  )  const

Gets a declared field by its identifier.

Parameters:
[in] fid Field identifier
Returns:
Declared field. If the field is not found, the function returns zero.

void GetAllFields ( Fields fields  )  const

Gets a list of all declared fields.

Parameters:
[in,out] fields List of declared fields.
Note:
The programmer must not delete the fields, received in the container. CFieldMap in its destructor will destroy them itself.

CFieldMap * GetParentMap (  ) 

Gets a field map of the parent class in the inheritance chain.

Returns:
Field map of the base class in the inheritance chain from CDataObject.

const CFieldMap * GetParentMap (  )  const

Gets a field map of the parent class, const version.

Returns:
Field map of the base class in the inheritance chain from CDataObject.

void InitHash (  ) 

Initializes hash.

Note:
If a hash is already initialized, it is not recommended to add value in the table of functions.