Prev | Next | |||
Object Store | Object Views |
Object relations
When it comes to object relations you can use one to one and one to many relations in a straight forward way.
OneToOne relations
In this example we have two object types an address class and a person class.
Each person class should have an address, so we add an oos::object_ptr of type address to the members. That's it. Now we have a one to one relationship beetween two classes.
With this kind of relationship we have a hard linked relationship. Which means if we remove the person from our store the address object is removed as well.
In case we want to keep the address object we can use a oos::object_ref of type adress instead of object_ptr.
With object_ref we have a soft link to the address inside our person class and it won't be removed on a person removal. We must explicitly remove the address.
OneToMany relations
When it comes to one to many releationships it is also quiet easy. OOS comes with three types of container classes which can be used to setup one to many relationships.
Because these classes are designed in the same way as the STL classes we can use them in the same way plus the benefit of the relationship.
Our handy person class needs a list of friends which are also of type person. And because we want this list with soft linked person we use oos::object_ref as the type of the list.
Why declare a list if we don't use it? Next is an example howto to use our persons friend list.
We insert a new person into the object_store. Than we insert and immediatily add some persons as friends to our first person.
Now we can simply iterate over the list like we used to do it with all STL containers. Period.
Prev | Next | |||
Object Store | Object Views |