Next: Unknown Node Types Up: Creating a New Previous: The Creation Function

Declaration Object

This section is hard to understand and takes you into an obscure corner of the C++ world; do not worry if you do not understand it at first. The take-home message is that if you mimic the example in declaring an object of type F_classDeclare in the .h file you are creating to describe your new node type, then anyone who compiles an application using your .h file will be able to successfully read objects of your new node type from disk.

Any node type which is to be read from disk must be declared to FARFALLA; specifically, at run time FARFALLA must be informed of the four character F_NodeType and the name of the function that creates a new node. Rather than requiring the application programmers to remember to declare your node to FARFALLA before they use it, we require you, the node developer, to cause this declaration to happen automatically for any user who includes your node class definition file (the .h file). To accomplish this, we use a C++ gimmick.

You have learned that every C++ class can define a constructor which will be executed when objects of the class are created. If an object is defined globally, the constructor will be executed before the main part of the program begins.

We have defined a class called F_classDeclare whose constructor declares a class to FARFALLA. At the bottom of your class definition file you should declare an object of this class. Then any application program in which the user includes your file will cause your class to be declared to FARFALLA. The two arguments to the constructor are the F_NodeType you have defined for your class and the name of the function that returns a pointer to a new instance of your class. In erpNode.h the F_classDeclare declaration looks like this:


static F_classDeclare declareErp(erpType,newErpNode);

Do not worry if you do not understand this gimmick; this is the trickiest thing in FARFALLA, and until you understand it you can make it work simply by closely mimicking the example here.



Next: Unknown Node Types Up: Creating a New Previous: The Creation Function


walter@
Wed Aug 10 11:53:26 PDT 1994