Select

It is not possible to map select types directly to C+. In the C+ EXPRESS API selects are treated in two different ways:

  • If all the alternatives in the select type are entities (object classes), the select is treated as an entity.
  • If the select have at least one alternative different from entity, the select will be declared as a class cppSelect, which is the same way as selects are treated in SDAI.

All select alternatives are entities

The select is mapped to the supertype of all entities namely dbInstance. This will create efficient code, but has the drawback that every object is applicable where such selects are specified. When such selects return values in, for example, get-functions, the generated C++ type of the return value is void *. The void * must then be casted to the correct C++ object pointer. Example:
TYPE characterized_definition = SELECT (
characterized_object,
characterized_product_definition,
shape_definition);
END_TYPE;
The generator will generate the following for characterized_definition:
typedef dbInstance characterized_definition;
The entity property_definition has an attribute of type characterized_definition with name definition. All the alternatives of characterized_definition are entities.
As an example, we create a property and connect it to the product_definition defined above. In this case we know that a product_definition is attached to the property, but in the general case we do not know this, and, therefore, we exemplify how all possible entity types in the graph of the select type characterized_definition are handled.
// Create a property
property_definition *prop_def_1= newObject(property_definition);
prop_def_1->put_name("Prop1");
// set the definition attribute beeing the product definition from above
prop_def_1->put_definition(pd);
// Retrieve the proprty definition and exemplify how is processed
// based on the retrieved type.
entityType objectType;
void* obj = prop_def_1->get_definition(&objectType);
if(objectType == et_product_definition){
product_definition mypd = (product_definition)obj;
product *myp = mypd->get_formation()->get_of_product();
printf("\nProperty 1 is connected to product: %s",myp->get_id());
} else if(objectType == et_characterized_object){
// handle characterized_object
} else if(objectType == et_product_definition_shape){
// handle product_definition_shape
} else if(objectType == et_shape_aspect){
// handle shape_aspect
} else if(objectType == et_shape_aspect_relationship){
// handle shape_aspect_relationship
} else if(objectType == et_product_definition_relationship){
// handle product_definition_relationship
} else {
throw new CedmError(sdaiETYPEUNDEF);
}
// Create another property and attach it to a characterized_object
property_definition *prop_def_2= newObject(property_definition);
prop_def_2->put_name("Prop2");
characterized_object *co = newObject(characterized_object);
co->put_name("co1");
prop_def_2->put_definition(co);
// Retrieve the proprty definition and exemplify how is processed
// based on the retrieved type.
obj = prop_def_2->get_definition(&objectType);
if(objectType == et_product_definition){
// handle product_definition
} else if(objectType == et_characterized_object){
characterized_object myco = (characterized_object)obj;
printf("\nProperty 2 is connected to characterized_object: %s",myco->get_name());
} else if(objectType == et_product_definition_shape){
// handle product_definition_shape
} else if(objectType == et_shape_aspect){
// handle shape_aspect
} else if(objectType == et_shape_aspect_relationship){
// handle shape_aspect_relationship
} else if(objectType == et_product_definition_relationship){
// handle product_definition_relationship
}else {
throw new CedmError(sdaiETYPEUNDEF);
}

Select where at least one of the alternatives is not an entity

See the EXPRESS example below. That is a select where the alternatives are either a string or an enumeration.
TYPE application_defined_degree_of_freedom = STRING;
END_TYPE;
TYPE enumerated_curve_element_freedom = ENUMERATION OF (
x_translation, y_translation, _translation,
x_rotation, y_rotation, z_rotation,
warp,
none );
END_TYPE;
TYPE curve_element_freedom = SELECT (
enumerated_curve_element_freedom,
application_defined_degree_of_freedom);
END_TYPE;

The C++ generator generates the following class declaration for the select type curve_element_freedom:
class curve_element_freedom : public cppSelect {
public:
curve_element_freedom() { }
curve_element_freedom(enumerated_curve_element_freedom v, Model *m) ;
curve_element_freedom(application_defined_degree_of_freedom v) ;
};

// The code below shows how to create curve_element_freedom selects
// and put it into the attribute release_freedom of //_curve_element_end_release_packet objects
// By new(m), the selects are created in memory controlled Models
// The m after enumerated_curve_element_freedom_X_ROTATION is necessary
// because enumerated_curve_element_freedom_X_ROTATION must be translated
// to the corresponding instance identifier in the underlying database.
curve_element_freedom *cef1;
cef1 = new(m)curve_element_freedom(enumerated_curve_element_freedom_X_ROTATION, m);
curve_element_freedom *cef2;
cef2 = new(m)curve_element_freedom("application defined degree of fredom",m);
curve_element_end_release_packet * ceerp1;
ceerp1 = newObject(curve_element_end_release_packet);
ceerp1->put_release_freedom(cef1);
curve_element_end_release_packet * ceerp2;
ceerp2 = newObject(curve_element_end_release_packet);
ceerp2->put_release_freedom(cef2);