ebmDevMag.com home
ebm Developer's Magazine
links

developer's mag
main page

article
part 1
part 2
part 3
part 4
part 5
part 6


5 - Gathering Around The Table

The remaining enum table and s_propertyTable[] provide the information to complete the class. s_propertyTable is an array of s_property structures:
struct s_property
{
  int  index;
  char *name;
  e_paramType type;
  long param1, param2; 
};

For the checkbox, this array is defined as follows:
const s_property CObjCheckBox::s_propertyTable[] =
    { { INDEX_CAPTION,"Caption",   TYPE_CHARPTR,    0,   0 },
      { INDEX_CLASS,  "Class Name",TYPE_CHARPTR,    3,   0 },
      { INDEX_HEIGHT, "Height",    TYPE_NUMBER,    13,  13 },
      { INDEX_LEFT,   "Left",      TYPE_NUMBER, -1000,1000 },
      { INDEX_NAME,   "Name",      TYPE_CHARPTR,    3,   0 },
      { INDEX_TOP,    "Top",       TYPE_NUMBER, -1000,1000 },
      { INDEX_WIDTH,  "Width",     TYPE_NUMBER,    15, 300 } };

The order of the enums in the class and their order in this property table is not coincidental - they also double as indexes to an array called m_value[], and care must be taken to make sure they match if you modify the table. The name field contains the text displayed on the editor, on the right hand side grid. Param1 and param2 are used by the item as it sees fit - for example, INDEX_LEFT uses the values for clamping, limiting input from between -1000 and 1000.

The e_paramType value is the key to managing the object's data. The base class has handlers for each of these types, to use in setting and getting values, displaying, and I/O. For instance, TYPE_NUMBER refers to a long, it is written to disk with a size of 4 bytes, and the param1/2 values are used as a validation range (as in the example of INDEX_LEFT).

In contrast, TYPE_CHARPTR refers to a text string. It has a variable length when reading and writing, is displayed differently, and the m_value[] variable referring to it is actually a pointer to a string.

The end result is that the base class manages these details, and each class provides minimal code to do what it needs to be unique. For example, the scroll bar class also redefines the set and get functions to make sure the user cannot change the height on a horizontal scrollbar, or the width of a vertical one. But with most objects, this is not necessary, and so reduces code size.

Further, the s_propertyTable table provides a simple way to expose the properties each object needs to describe itself, making them available to the editor, providing error checking, and allowing simple saving and loading.

Previous Section
Next Section

Copyright © 2001-2006 ebmDevMag.com - Legal Notice