Multiple inheritance, subtypes and supertypes

Working with objects of classes that have subtypes and supertypes in C++ may be challenging. In the following we will address these challenges.
When one is using iterators to iterate over aggregates, the first and next methods returns the pointers as they were added to the aggregate. If the object class of the aggregate element has several subtypes, pointers to objects of the specific subtypes are returned. The following example shows such a situation where the program shall handle the different subtypes .

The example below is applicable for the in database memory model.

 

// Create a representation_context and three objects that all are subtypes of
 // representation namely a node, fea_model_3d and explicit_element_representation
 representation_context rep_ctx(m);
 rep_ctx.put_context_identifier("Context1");
 node n(m);
 n.put_name("Node 1");
 n.put_context_of_items(&rep_ctx); 
 fea_model_3d feam(m);
 feam.put_name("Feam 1");
 feam.put_creating_software("Lorentz developed the software");
 feam.put_context_of_items(&rep_ctx); 
 explicit_element_matrix elm(m);
 matrix_property_type mpt;
 mpt.setString("Property type");
 elm.put_property_type(&mpt);
 explicit_element_representation eep(m);
 eep.put_name("explicit_element_representation 1");
 eep.put_matrix(&elm);
 eep.put_context_of_items(&rep_ctx); 
 // Then get the representations attached to the context
 // and handle them separately
 Set<representation*> *reps;
 reps = rep_ctx.get_representations_in_context();
 entityType repType;
 Iterator<representation*, entityType> repIter(reps);
 for (representation* rep = repIter.first(&repType); rep; rep = repIter.next(&repType)) {
 if(repType == et_node) {
 node mynode = (node)rep;
 printf("\nNode : %s",rep->get_name());
 }
 if(repType == et_fea_model_3d) {
 fea_model_3d myfeam = (fea_model_3d)rep;
 printf("\nfea_model_3d : %s",rep->get_name());
 printf("\nfea_model_3d software: %s",myfeam->get_creating_software());
 }
 if (repType == et_explicit_element_representation) {
 explicit_element_representation myeet = (explicit_element_representation)rep;
 printf("\nexplicit_element_representation : %s",rep->get_name());
 explicit_element_matrix *myeem = myeet->get_matrix();
 matrix_property_type *mympt = myeem->get_property_type();
 char *mychar = mympt->getString();
 printf("\nMatrix property type : %s",mychar);
 }
 }