To create a header (color_attrib.hxx) file for
ATTRIB_COL:
|
|
|
1.
|
Enter the
#if !defined . . . #endif preprocessor commands to prevent duplicating the declaration.
|
|
|
2.
|
Define the symbol
ATTRIB_COL_CLASS.
|
|
|
3.
|
Include the organization attribute class's header file.
|
|
|
4.
|
Declare the global, dynamically assigned integer identifier for this attribute class.
|
|
|
5.
|
Declare the identification level of this data type to be one level removed from the organization attribute class.
|
|
|
6.
|
Declare that
ATTRIB_COL is derived from
ATTRIB_ABC.
|
|
|
7.
|
Declare an integer that defines the color. (This is the only data for the class.)
|
|
|
8.
|
Enter a constructor to create a color attribute for a given color and attach it to a given entity. A constructor that takes zero arguments must be provided for the save/restore functions. The constructor shown in the following example takes zero arguments because all arguments are defaulted. This is the recommended way of providing both the zero argument and standard constructor, rather than writing multiple constructors.
|
|
|
9.
|
Create the member access (get) and setting (set) functions.
|
|
|
10.
|
Declare the methods for
split_owner and
merge_owner. (Other common methods, such as
trans_owner, are not overloaded in this example.)
|
|
|
11.
|
Call the
ATTRIB_FUNCTIONS macro to declare the functions required to complete the declaration of an attribute. The macro includes declarations for all
ENTITY virtual functions, including
make_copy,
identity,
type_name,
size, and
debug_ent. The macro also includes the declarations for the functions to save, restore, and copy the attribute.
|
|
Example 3-5 shows what what a color attribute file (color_attrib.hxx) could look like.
|
|
C++ Example
|
|
#if !defined(ATTRIB_COL_CLASS)
|
#define ATTRIB_COL_CLASS
|
|
#include "at_abc.hxx"
|
|
extern int ATTRIB_COL_TYPE;
|
#define ATTRIB_COL_LEVEL (ATTRIB_ABC_LEVEL + 1)
|
|
class ATTRIB_COL: public ATTRIB_ABC {
|
|
int color_data;
|
|
public:
|
|
|
ATTRIB_COL(ENTITY* = NULL, int = 0);
|
|
|
int color() const {return color_data;}
|
|
void set_color(int);
|
|
// Functions called to aid attribute migration during modeling
|
// operations.
|
|
|
virtual void split_owner(ENTITY*);
|
|
// The owner of this attribute is about to be split in two - the
|
// argument is the new piece. The owner of this attribute is
|
// about to be merged with the given entity. The logical argument
|
// is TRUE if the owner is to be deleted in the merge.
|
|
|
virtual void merge_owner(
|
|
|
ENTITY*,
|
|
|
|
// "other entity"
|
|
|
logical
|
|
|
|
|
// deleting_owner
|
|
);
|
|
|
ATTRIB_FUNCTIONS(ATTRIB_COL, KERN);
|
};
|
|
#endif
|
|
Example 3-5. color_attrib.hxx Color Attribute Header File
|