IlsInvertedRelation
Category
Modeling class template
Inheritance Path
IlsInvertedRelation
Related Pattern
Bridge
Description
Rogue Wave® Server lets you invert a relation by maintaining a back pointer to the origin of that relation. This pointer is declared as an instance of the class template
IlsInvertedRelation and maintained by means of the functions
setContext and
unsetContext. A relation of type
IlsInvertedRelation contains an entry. Modifying it may therefore trigger the recomputation of derived members or notification.
TargetType and
OriginType must directly or transitively derive from
IlsEntity or
IlsObject.
The
IlsInvertedRelation template makes a forward declaration of the function
IlsViewed* Ils2Viewed(OriginType*) and uses it in its implementation. This to avoid the compiler to require visibility on the class
OriginType when instantiating the inverted relation template. The implementation of the
Ils2Viewed function is expanded by the macro
ILS_OBJECT_DECL or its derivatives. If you do not want to use that macro because the type
OriginType is not notified by views, you can define your own function in a source of your application that has visibility on the class
OriginType, as follows:
Ils2Viewed* Ils2Viewed(TargetType* obj){return obj;}
Library
Synopsis
template <class TargetType, class OriginType>
class IlsInvertedRelation
{
public:
(TargetType&,
IlsActivity activity=IlsModel::getDefaultActivity());
Myself&
set(OriginType* rhs);
Operators
(IlsInvertedRelation<TargetType,OriginType>& rhs);
};
Constructor
IlsInvertedRelation
(TargetType&,
IlsActivity activity=IlsModel::GetDefaultActivity());
As its first argument, this constructor takes a reference to the type in which the relation is declared. It initializes the back pointer to zero. The argument
activity specifies whether the relation is active or not. A relation is active if its modification sets off the recomputation of derived data members. The default value is the one returned by the static member function
IlsModel::GetDefaultActivity, which is
ILS_INACTIVE by default.
Member Functions
Accessors
TargetType& getTarget();
This member function returns the target of the relation.
OriginType* getValue();
This member function returns a pointer to the origin of the relation. It is useful especially when the conversion operator cannot be used or when the compiler is likely to encounter multiple user-defined conversions.
Modifiers
Myself& set(OriginType* rhs);
This member function assigns a new origin to the inverted relation.
Myself& clear();
This member function sets the relation to zero.
Notification
IlsBoolean isModified();
During a notification phase, this member function returns IlsTrue only if the relation has been modified since the last notification phase.
OriginType* getOldvalue();
During a notification phase, this member function returns a smart pointer to the object that was the target of the relation before the notification phase.
Operators
These operators let you use inverted relations as if they were pointers.
operator OriginType*();
This operator converts the relation to a pointer to an object of the OriginType.
It is equivalent to the member function getValue (see above).
OriginTypeP operator->();
This dereference operator returns the origin of the relation.
OriginType& operator*();
This indirection operator returns a reference to the origin of the relation.
IlsBoolean operator!();
This operator returns IlsTrue if the inverted relation is set to 0.
IlsBoolean operator==(OriginType* rhs);
This operator checks whether the origin-type is equal to another origin-type.
IlsBoolean operator!=(OriginType* rhs);
This operator checks whether the origin-type is not equal to another origin-type.
IlsBoolean operator==(Myself& rhs);
This operator checks whether the inverted relation is equal to another inverted relation.
IlsBoolean operator!=(Myself& rhs);
This operator checks whether the inverted relation is not equal to another inverted relation.
Myself& operator=(OriginType* rhs);
This operator assign a new origin to the inverted relation.
Myself& operator=(IlsInvertedRelation<TargetType,OriginType>& rhs);
This operator assigns an inverted relation to the inverted relation.
See Also
Version 5.8
Copyright © 2014, Rogue Wave Software, Inc. All Rights Reserved.