Example 4-5. C++ Code Fragments: Instantiating the V1 Features
// segment of code that instantiates the features
// no error checking provided--for illustration
// purposes only
// each feature object needs to know the model number
// and feature ID it corresponds to in order to retrieve
// information when requested. Note how this information
// is passed into each object's constructor
// open model
modelNum= V1OpenModel( modelName);
nElements= V1GetNumberofElements(modelNum);
Feature *features[MAXFEATURES];
// do for each feature in the model
for (i= 0; i < nElements; i++) {
// determine feature present and create
// appropriate feature object
switch( V1GetType( modelNum, i)) {
case SLOT:
features[i]=
new V1Slot( modelNum,
V1GetID( modelNum, i));
break;
case HOLE:
features[i]=
new V1Hole( modelNum,
V1GetID( modelNum, i));
break;
...
}
}
Example 4-6. C++ Code Fragments: Implementation of V1 Methods
// modelNum and myID are private members containing
// information about the model and feature (in V1) this
// feature corresponds to
double V1Slot::getX () {
// call appropriate method for V1 to get needed
// information. Note: this method may actually
// call several methods in V1
// to get the information.
return V1GetXforSlot( modelNum, myID);
}
double V1Hole::getX () {
// call appropriate method for V1 to get needed
// information. Note: this method may actually
// call several methods in V1
// to get the information.
return V1GetXforHole( modelNum, myID);
}
Example 4-7. C++ Code Fragments: Instantiating the V2 Features
// segment of code that instantiates the features
// no error checking provided--for illustration
// purposes only
// each feature object needs to know the feature in the
// V2 system it corresponds to in order to retrieve
// information when requested. Note how this information
// is passed into each object's constructor
// open model
myModel= V2OpenModel( modelName);
nElements= myModel->getNumElements();
Feature *features[MAXFEATURES];
OOGFeature *oogF;
// do for each feature in the model
for (i= 0; i < nElements; i++) {
// determine feature present and create
// appropriate feature object
oogF= myModel->getElement(i);
switch( oogF->myType()) {
case SLOT:
features[i]= new V2Slot( oogF);
break;
case HOLE:
features[i]= new V2Hole( oogF);
break;
...
}
}
}
Example 4-8. C++ Code Fragments: Implementation of V2 Methods
// oogF is a reference to the feature object in V2 that
// the object containing it corresponds to
double V2Slot::getX () {
// call appropriate method on oogF to get needed
// information.
return oogF->getX();
}
double V2Hole::getX () {
// call appropriate method on oogF to get needed
// information.
return oogF->getX();
}