Modeling Services > Relations > One-to-one Relations > Updating Ownership Relations
 
Updating Ownership Relations
As illustrated in the following code, a relation data member behaves like a pointer when it is accessed, and, as such, it can be dereferenced. In addition, a relation can be modified by the assignment of a pointer or a smart pointer.
// ...
typedef IlsSmartPointer<Car> CarP;
// ...
class Person:
public IlsObject
{
  public:
    IlsOwns<Person,Car> car;
    Person();
};
 
CarP AssignNewCarAndRepaint(Person& p, CarP newCar){
    p.car=newCar; // assignment of a new car
    p.car->rePaint(); // apply rePaint function to the car
    return p.car; // the relation can convert to a smart pointer
}
Two main rules govern the updating of an ownership relation:
*By default, when an ownership relation is broken, if the target of this relation is also the target of a use relation, then the use relations are also severed.
Updating an Ownership Relation
We will see in Context-Sensitive Features that this behavior can be fine-tuned.
*If the relation is assigned a new target which is already the target of another ownership relation, the exception IlsAlreadyInserted is thrown.

Version 6.3
Copyright © 2018, Rogue Wave Software, Inc. All Rights Reserved.