![]() |
![]() |
![]() |
![]() |
![]() |
General Concepts
The OM Access Application
An OM Access application is an application that uses the data in an OM Diagram. This OM Diagram is represented in the program by a data structure similar to UML's metamodel.
The first section introduces the basic methods.
Basic Methods
First of all there are some definitions needed; these can be found in the include file omaccess.h:
#include "omaccess.h"This file also includes uml.h and stlmini.h. The file uml.h contains declarations for the UML metamodel, and stlmini.h1 contains a minimal implementation of string and list classes in the standard C++ library used for handling the data.
An instance of the OMModule is needed to hold the information:
OMModule module;To load the contents of a diagram into the module either GetFile or GetBufID can be used:
bool result = GetFile(module, filename);bool result = GetBufID(module, bufid);Returns true on success, false if failed to load the module.
Accessing the Information
The OMModule class keeps the information fetched from the OM Editor in lists. The lists are:
list<Class> classListlist<Generalization> generalizationListlist<AssociationClass> associationlistAggregations and associations are stored into the associationList, to simplify handling. To pick out the associations and aggregations separately, use the functions:
GetAggregations(OMModule&, list<AssociationClass>*)GetAssociations(OMModule&, list<AssociationClass>*)These functions fill the list in the second parameter with the associations and aggregations in the module.
The lists can be traversed using iterators. The following example shows how to print all the names of the classes in a module:
for (list<Class>::iterator ci=omModule.classList.begin();ci != omModule.classList.end();++ci) {const Class &omClass = *ci;cout << omClass.name << endl;}
Relations
The links between associations/aggregations/generalizations and classes are represented as the names of classes, stored as strings.
Generalizations
The Generalization class contains the data members subtype and supertype. The names of the super- and subclass are stored as string.
The data member discriminator contains the discriminator, stored as string.
To list the superclasses and subclasses of a class, the following functions can be used:
GetSuperClassList(OMModule&, string&, list<string>*)GetSubClassList(OMModule&, string&, list<string>*)They put the names of the superclasses or subclasses belonging to the name of the class in string, into the list.
Aggregations/Associations
The AssociationClass class can contain both aggregations and associations as well as associations with association classes connected to them. The boolean member isAggregation can be used to determine if it is an aggregation or association.
To get a list of the names of the classes connected to the association/aggregation, the function
GetEndPoints(AssociationClass&, list<string>*)Example
Here follows a small example that shows how to access the class information. For each class in the diagram it prints the name of the class and the name of its subclasses.
#include <iostream.h>#include "omaccess.h"#include "stlmini.h"int main(int argc, char *argv[]) {if (argc !=2) {cout << "Usage : printclasses <filename>" << endl;return EXIT_FAILURE;}OMModule omModule;// Retrieve the file from the OM Editorif(! GetFile(argv[1], &omModule) )return EXIT_FAILURE;// Iterate over the classesfor (list<Class>::iterator ci=omModule.classList.begin();ci != omModule.classList.end();++ci) {const Class &omClass = *ci;cout << omClass.name << endl;// Extract the subclassesslist<string> classlist;GetSubClassList(omModule,omClass.name,&classlist);// And iterate through themfor (list<string>::iterator ni=classlist.begin();ni != classlist.end();++ni) {const string &name = *ni;cout << " Subclass: " << name << endl;}}return EXIT_SUCCESS;}
1stlmini.h can be replaced by the appropriate standard C++ headers <list.h> and <string.h> if you have access to an implementation of the standard C++ library.
http://www.ibm.com/rational |
![]() |
![]() |
![]() |
![]() |