Story of my life…
People who fly often, like I do, know that there is always a big risk that something is happening. Either on your airport, or on the airport where your plane came from or the airport where your plane is heading to. Also the plane is a mechanical and electronic device with software in it. I repeat…. with software in it.
There is a lot that can go wrong there and, experience shows, that will go wrong. A lot is mostly safety stuff, flying would be possible but safety precautions prevent that. And that is a good thing. Flying is safe because we care a lot about safety.
That all is apart from other annoyances. Expensive mediocre food, people who think they are alone in the airplane and many more. But in spite of all that…I still love flying.
This BLOG is about Rhapsody isn’t it?
Yes, yes, it is. I mix stories about my life that mostly consists of traveling the world to spread the word about Rhapsody and some technical stories about Rhapsody itself.
Today we had a discussion with my colleagues from development about Container Classes is Rhapsody. Container classes are Classes that have a 1:* relationship with another class. (See picture) So Class ProductDatabase has a 1:* relation with the Class Product. What does that mean? And especially for the Code Generation in Rhapsody. That depends on the language you are using in Rhapsody.
OK. in ‘C’ first.
In ‘C’ the 1:1 association or aggregation between A and B mean that you have a pointer to B in your A class (struct) A composition will have a complete struct B inside A. The “*” relation will generate a RiCCollection B. What is a RiCCollection? This is basically an Array where items of “B” can be stored. You don’t know where the items are stored so when you are searching through your collection you will have to look in every item in the collections and compare to see if you found the right one. (On average you have to search half of the array) When that is no problem you can use this. There is a property you can set “Ordered” that will create a linked list instead of jus an array (a RiCList). That means you still have to search through half the list (on average) to find a specific item but you can order the items to find them quicker. Here is the code belonging to the 3 relations in C and in C++:
The “qualify” field will allow you to select one of “B”‘s attributes as a key. (It creates a RiCMap). The items are stored in a balanced binary tree, storing takes a while since the tree might have to be re-balanced again, but searching is way faster, on average 2log(n) (For searching 1024 items you need to compare a maximum of 10 times)
You can also just use multiplicity to do this, just create a 1:10 relation and you will have a static array of 10 “B”‘s that you can use in the same way.These constructs doe not only are generated inside the structure that represents your class, there are also functions generated (Yes also in case of the static array!) to add items, to delete items, to delete the complete structure and depending on the kind of container some search functions.
What about ‘C++’?
C++ does not know Container Classes by itself but the Standard Template Library does. Since not all compilers support the STL, tree are also non-STL container classes.
can be set to:
- OMContainers, OMContainer, OMList and OMMap
- STLContainers, vector, list and map
- OMUContainers, OMUContainer, OMUList and OMUMap
As you can see there are even Templateless versions for the poor amongst us that use a compiler that does not support templates. The STL versions use list, vector and map from the STL. The same functions are available, in ‘C++’ they are all inherited from the container type. Something to keep in mind is that searching the structure will have a different way if using iterators.
Now where’s the drawback?
There is no real drawback here, the only thing is that this will use memory. But there are enough properties to limit that to just the amount you need. The routines are consuming some of your ROM as well of course. But they make your life easier. A lot easier. But check your map file to see what is used there. TODO- pictures from the advanced trainings, list of the functions in C and the different iterators in C++.
The model I used to make the pictures is here: ContainerClasses
OK, that’s it for today!
Happy Holidays! And have fun modeling with Rhapsody!
Walter van der Heiden (firstname.lastname@example.org)