MFC Grid manual

CDynamicObject Class Reference

CDynamicObject has nether Set- nor Get- functions. The values are accessible by the field identifiers. More...

#include <Dapfor/Common/DynamicObject.h>

Inheritance diagram for CDynamicObject:

CDataObject

List of all members.


Public Member Functions

 CDynamicObject (bool canNotify)
virtual ~CDynamicObject ()
virtual const Field GetField (FID fid) const
 Gets a data object field.
virtual void GetAllFields (Fields &fields) const
 The function copies all declared fields.
virtual void GetAllFids (Fids &fids) const
 Gets all the integer identifiers supported by the object.
virtual const CFieldMapGetFieldMap () const
 Gets data object fields.
virtual bool DeclareField (CField *field)
 Declares a new field.
Set methods
virtual bool SetMfcString (FID fid, const CString &val)
 Sets a MFC string value in the field specified by the identifier.
virtual bool SetStlString (FID fid, const TString &val)
 Sets a STL string value in the field specified by the identifier.
virtual bool SetChar (FID fid, char val)
 Sets char value in the field specified by the identifier.
virtual bool SetUChar (FID fid, unsigned char val)
 Sets unsigned char value in the field specified by the identifier.
virtual bool SetShort (FID fid, short val)
 Sets short value in the field specified by the identifier.
virtual bool SetUShort (FID fid, unsigned short val)
 Sets unsigned short value in the field specified by the identifier.
virtual bool SetLong (FID fid, long val)
 Sets long value in the field specified by the identifier.
virtual bool SetULong (FID fid, unsigned long val)
 Sets unsigned long value in the field specified by the identifier.
virtual bool SetInt64 (FID fid, int64 val)
 Sets __int64 value in the field specified by the identifier.
virtual bool SetBool (FID fid, bool val)
 Sets bool value in the field specified by the identifier.
virtual bool SetFloat (FID fid, float val)
 Sets float value in the field specified by the identifier.
virtual bool SetDouble (FID fid, double val)
 Sets double value in the field specified by the identifier.
virtual bool SetObjectPtr (FID fid, CDataObject *val)
 Sets a pointer to CDataObject in the field specified by the identifier.
virtual bool SetValue (FID fid, const CValue &val)
 Sets CValue in the field specified by the identifier.
Get methods
virtual CString GetMfcString (FID fid) const
 Gets MFC string value from the field specified by the identifier.
virtual TString GetStlString (FID fid) const
 Gets STL string value from the field specified by the identifier.
virtual char GetChar (FID fid) const
 Gets char value from the field specified by the identifier.
virtual unsigned char GetUChar (FID fid) const
 Gets unsigned char value from the field specified by the identifier.
virtual short GetShort (FID fid) const
 Gets short value from the field specified by the identifier.
virtual unsigned short GetUShort (FID fid) const
 Gets unsigned short value from the field specified by the identifier.
virtual long GetLong (FID fid) const
 Gets long value from the field specified by the identifier.
virtual unsigned long GetULong (FID fid) const
 Gets unsigned long value from the field specified by the identifier.
virtual int64 GetInt64 (FID fid) const
 Gets __int64 value from the field specified by the identifier.
virtual bool GetBool (FID fid) const
 Gets bool value from the field specified by the identifier.
virtual float GetFloat (FID fid) const
 Gets float value from the field specified by the identifier.
virtual double GetDouble (FID fid) const
 Gets double value from the field specified by the identifier.
virtual CDataObjectGetObjectPtr (FID fid) const
 Gets a pointer to CDataObject from the field specified by the identifier.
virtual CValue GetValue (FID fid) const
Formatted strings
virtual CString GetFormattedMfcString (FID fid, const CFormat *defaultFormat) const
 Gets a formatted MFC string.
virtual bool SetFormattedMfcString (FID fid, const CString &val, const CFormat *defaultFormat)
 Sets a formatted MFC string.
virtual TString GetFormattedStlString (FID fid, const CFormat *defaultFormat) const
 Gets a formatted STL string.
virtual bool SetFormattedStlString (FID fid, const TString &val, const CFormat *defaultFormat)
 Sets a formatted STL string.
Field accessors
virtual bool HasGetMethod (FID fid) const
 Indicates whether the object has Get- method.
virtual bool HasSetMethod (FID fid) const
 Indicates whether the object has Set- method.
virtual EnType GetFieldType (FID fid) const
 Gets a field type.
virtual TString GetFieldName (FID fid) const
 Gets the field name, set during CField registration.
virtual const CFormatGetFormat (FID fid) const
 Gets the format to convert non-formatted value to the string and back.

Detailed Description

CDynamicObject has nether Set- nor Get- functions. The values are accessible by the field identifiers.

CDynamicObject provides access to values stored in the table. This table can be changed at run time in contrast to the static tables organized with DF_DECLARE_FIELD_MAP(), DF_BEGIN_FIELD_MAP(), DF_BEGIN_FIELD_MAP_EX(), DF_END_FIELD_MAP() macros. In this case memory consumption for dynamic data objects increases greatly. CDynamicObject is usually used if data object type is unknown beforehand. (For example, if data is imported from another application using drag&drop or copy/paste). If the object type is known, it is recommended to use static declaration. CDynamicObject doesn't contain Get- and Set- methods To simulate standard behavior of the data object, all the functions working with unformatted and formatted data were redefined. Every CDynamicObject contains two tables.
1. CFieldMap table to store information about formats for transformation of data into a string and back.
2. Container that stores unformatted data which are accessible by its identifier.

During the first call of any Set- method, CDynamicObject adds a new value corresponding to the identifier to the table of unformatted values. To transform the value into the string with custom format, this format can be registered in CFieldMap with DeclareField() function. CDynamicObject in its destructor destroys all registered fields. In multi-threaded applications essential mechanisms were implemented in order to enable simultaneous access from different threads.

Version:
2.0.0 Initial version

Constructor & Destructor Documentation

CDynamicObject ( bool  canNotify  ) 

Constructor

Parameters:
[in] canNotify Indicates whether a dynamic object will send notifications to the subscribers via CDataObject::ISink interface if Set- method is called.

~CDynamicObject (  )  [virtual]

Destructor


Member Function Documentation

const CFieldMap * GetFieldMap (  )  const [virtual]

Gets data object fields.

Retrieves the field map. Const version.

Returns:
CFieldMap type object.

Implements CDataObject.

bool DeclareField ( CField field  )  [virtual]

Declares a new field.

Declares a new field for the dynamic object. The field mustn't have Set- or Get- methods that can be called, because they are an attribute of class and not object. So they should be set to zero. The field identifier can't be equal to Common::allFields(-1) or Common::fieldNotSpecified(-2).

Parameters:
[in] field A new field
Returns:
If the field with the same identifier has been declared before, the function returns false. If the field has been successfully added, true is returned.

bool SetMfcString ( FID  fid,
const CString &  val 
) [virtual]

Sets a MFC string value in the field specified by the identifier.

Parameters:
[in] fid Field identifier
[in] val New MFC string value
Returns:
true if success. Otherwise false.

Reimplemented from CDataObject.

bool SetStlString ( FID  fid,
const TString &  val 
) [virtual]

Sets a STL string value in the field specified by the identifier.

Parameters:
[in] fid Field identifier
[in] val New STL string value
Returns:
true if success. Otherwise false.

Reimplemented from CDataObject.

bool SetChar ( FID  fid,
char  val 
) [virtual]

Sets char value in the field specified by the identifier.

Parameters:
[in] fid Field identifier
[in] val New char value
Returns:
true if success. Otherwise false.

Reimplemented from CDataObject.

bool SetUChar ( FID  fid,
unsigned char  val 
) [virtual]

Sets unsigned char value in the field specified by the identifier.

Parameters:
[in] fid Field identifier
[in] val New unsigned char value
Returns:
true if success. Otherwise false.

Reimplemented from CDataObject.

bool SetShort ( FID  fid,
short  val 
) [virtual]

Sets short value in the field specified by the identifier.

Parameters:
[in] fid Field identifier
[in] val New short value
Returns:
true if success. Otherwise false.

Reimplemented from CDataObject.

bool SetUShort ( FID  fid,
unsigned short  val 
) [virtual]

Sets unsigned short value in the field specified by the identifier.

Parameters:
[in] fid Field identifier
[in] val New unsigned short value
Returns:
true if success. Otherwise false.

Reimplemented from CDataObject.

bool SetLong ( FID  fid,
long  val 
) [virtual]

Sets long value in the field specified by the identifier.

Parameters:
[in] fid Field identifier
[in] val New long value
Returns:
true if success. Otherwise false.

Reimplemented from CDataObject.

bool SetULong ( FID  fid,
unsigned long  val 
) [virtual]

Sets unsigned long value in the field specified by the identifier.

Parameters:
[in] fid Field identifier
[in] val New unsigned long value
Returns:
true if success. Otherwise false.

Reimplemented from CDataObject.

bool SetInt64 ( FID  fid,
int64  val 
) [virtual]

Sets __int64 value in the field specified by the identifier.

Parameters:
[in] fid Field identifier
[in] val New __int64 value
Returns:
true if success. Otherwise false.

Reimplemented from CDataObject.

bool SetBool ( FID  fid,
bool  val 
) [virtual]

Sets bool value in the field specified by the identifier.

Parameters:
[in] fid Field identifier
[in] val New boolean value
Returns:
true if success. Otherwise false.

Reimplemented from CDataObject.

bool SetFloat ( FID  fid,
float  val 
) [virtual]

Sets float value in the field specified by the identifier.

Parameters:
[in] fid Field identifier
[in] val New float value
Returns:
true if success. Otherwise false.

Reimplemented from CDataObject.

bool SetDouble ( FID  fid,
double  val 
) [virtual]

Sets double value in the field specified by the identifier.

Parameters:
[in] fid Field identifier
[in] val New double value
Returns:
true if success. Otherwise false.

Reimplemented from CDataObject.

bool SetObjectPtr ( FID  fid,
CDataObject val 
) [virtual]

Sets a pointer to CDataObject in the field specified by the identifier.

Parameters:
[in] fid Field identifier
[in] val New pointer to CDataObject
Returns:
true if success. Otherwise false.

Reimplemented from CDataObject.

bool SetValue ( FID  fid,
const CValue val 
) [virtual]

Sets CValue in the field specified by the identifier.

Parameters:
[in] fid Field identifier
[in] val New CValue object
Returns:
true if success. Otherwise false.

Reimplemented from CDataObject.

CString GetMfcString ( FID  fid  )  const [virtual]

Gets MFC string value from the field specified by the identifier.

Parameters:
[in] fid Field identifier
Returns:
MFC string value if found. Otherwise an empty string is returned.

Reimplemented from CDataObject.

TString GetStlString ( FID  fid  )  const [virtual]

Gets STL string value from the field specified by the identifier.

Parameters:
[in] fid Field identifier
Returns:
STL string value if found. Otherwise an empty string is returned.

Reimplemented from CDataObject.

char GetChar ( FID  fid  )  const [virtual]

Gets char value from the field specified by the identifier.

Parameters:
[in] fid Field identifier
Returns:
char value if found. Otherwise 0 is returned.

Reimplemented from CDataObject.

unsigned char GetUChar ( FID  fid  )  const [virtual]

Gets unsigned char value from the field specified by the identifier.

Parameters:
[in] fid Field identifier
Returns:
unsigned char value if found. Otherwise 0 is returned.

Reimplemented from CDataObject.

short GetShort ( FID  fid  )  const [virtual]

Gets short value from the field specified by the identifier.

Parameters:
[in] fid Field identifier
Returns:
short value if found. Otherwise 0 is returned.

Reimplemented from CDataObject.

unsigned short GetUShort ( FID  fid  )  const [virtual]

Gets unsigned short value from the field specified by the identifier.

Parameters:
[in] fid Field identifier
Returns:
unsigned short value if found. Otherwise 0 is returned.

Reimplemented from CDataObject.

long GetLong ( FID  fid  )  const [virtual]

Gets long value from the field specified by the identifier.

Parameters:
[in] fid Field identifier
Returns:
long value if found. Otherwise 0 is returned.

Reimplemented from CDataObject.

unsigned long GetULong ( FID  fid  )  const [virtual]

Gets unsigned long value from the field specified by the identifier.

Parameters:
[in] fid Field identifier
Returns:
unsigned long value if found. Otherwise 0 is returned.

Reimplemented from CDataObject.

int64 GetInt64 ( FID  fid  )  const [virtual]

Gets __int64 value from the field specified by the identifier.

Parameters:
[in] fid Field identifier
Returns:
__int64 value if found. Otherwise 0 is returned.

Reimplemented from CDataObject.

bool GetBool ( FID  fid  )  const [virtual]

Gets bool value from the field specified by the identifier.

Parameters:
[in] fid Field identifier
Returns:
boolean value if found. Otherwise false is returned.

Reimplemented from CDataObject.

float GetFloat ( FID  fid  )  const [virtual]

Gets float value from the field specified by the identifier.

Parameters:
[in] fid Field identifier
Returns:
float value if found. Otherwise 0.0f is returned.

Reimplemented from CDataObject.

double GetDouble ( FID  fid  )  const [virtual]

Gets double value from the field specified by the identifier.

Parameters:
[in] fid Field identifier
Returns:
double value if found. Otherwise 0.0 is returned.

Reimplemented from CDataObject.

CDataObject * GetObjectPtr ( FID  fid  )  const [virtual]

Gets a pointer to CDataObject from the field specified by the identifier.

Parameters:
[in] fid Field identifier
Returns:
pointer to CDataObject if found. Otherwise 0 is returned.

Reimplemented from CDataObject.

CValue GetValue ( FID  fid  )  const [virtual]

Parameters:
[in] fid Field identifier
Returns:
CValue object if found. Otherwise CValue object with Common::Undefined type is returned.

Reimplemented from CDataObject.

CString GetFormattedMfcString ( FID  fid,
const CFormat defaultFormat 
) const [virtual]

Gets a formatted MFC string.

Parameters:
[in] fid Field identifier
[in] defaultFormat Format, which is applied to convert value to a MFC string. If the format is not specified, the function looks for the format, declared with DeclareField() function. If it also is not found, the format returned by CFormat::GetDefaultFormat() is applied.
Returns:
Formatted string if value exists. Otherwise an empty MFC string.

Reimplemented from CDataObject.

bool SetFormattedMfcString ( FID  fid,
const CString &  str,
const CFormat defaultFormat 
) [virtual]

Sets a formatted MFC string.

Parameters:
[in] fid Field identifier
[in] str Formatted string
[in] defaultFormat Format, which is applied to convert the formatted MFC string to the value. If the format is not specified, the function looks for the format, declared with DeclareField() function. If it also is not found, the output value is considered as MfcString type.
Returns:
True, if success. Otherwise false.

Reimplemented from CDataObject.

TString GetFormattedStlString ( FID  fid,
const CFormat defaultFormat 
) const [virtual]

Gets a formatted STL string.

Parameters:
[in] fid Field identifier
[in] defaultFormat Format, which is applied to convert value to a STL string. If the format is not specified, the function looks for the format, declared with DeclareField() function. If it also is not found, the format returned by CFormat::GetDefaultFormat() is applied.
Returns:
Formatted string if value exists. Otherwise an empty STL string.

Reimplemented from CDataObject.

bool SetFormattedStlString ( FID  fid,
const TString &  str,
const CFormat defaultFormat 
) [virtual]

Sets a formatted STL string.

Parameters:
[in] fid Field identifier
[in] str Formatted string
[in] defaultFormat Format, which is applied to convert the formatted string to the value. If the format is not specified, the function looks for the format, declared with DeclareField() function. If it also is not found, the output value is considered as StlString type.
Returns:
True, if success. Otherwise false.

Reimplemented from CDataObject.

bool HasGetMethod ( FID  fid  )  const [virtual]

Indicates whether the object has Get- method.

Parameters:
[in] fid Field identifier
Returns:
true if Get-method was declared by DeclareField() function in the object. Otherwise - false.
Thread safety:
The function is thread safe.

Reimplemented from CDataObject.

bool HasSetMethod ( FID  fid  )  const [virtual]

Indicates whether the object has Set- method.

Parameters:
[in] fid Field identifier
Returns:
true if Set-method was declared by DeclareField() function in the object. Otherwise - false.
Thread safety:
The function is thread safe.

Reimplemented from CDataObject.

EnType GetFieldType ( FID  fid  )  const [virtual]

Gets a field type.

An field type is determined by non-formatted value, which is returned by the field with the specified identifier.

Parameters:
[in] fid Field identifier
Returns:
One of Common::EnType types if value is found. Otherwise Common::Undefined
Thread safety:
The function is thread safe.

Reimplemented from CDataObject.

TString GetFieldName ( FID  fid  )  const [virtual]

Gets the field name, set during CField registration.

Parameters:
[in] fid Field identifier
Returns:
Field name if it was declared by DeclareField() function. Otherwise the returned string is empty.
Thread safety:
The function is thread safe.

Reimplemented from CDataObject.

const CFormat * GetFormat ( FID  fid  )  const [virtual]

Gets the format to convert non-formatted value to the string and back.

Parameters:
[in] fid Field identifier
Returns:
Field format if it was declared by DeclareField() function. Otherwise null.
Thread safety:
The function is thread safe.

Reimplemented from CDataObject.