IlsInvertedRelationList
Category
Modeling class template
Inheritance Path
IlsViewedRel➥ IlsInvertedRelationList Related Pattern
Bridge
Description
Rogue Wave® Server lets you invert several relations by maintaining a list of back pointers to the origins of a set of relations. This list of pointers is declared as an instance of the class template
IlsInvertedRelationList and maintained by means of the functions
setContext and
unsetContext. Modifying an inverted relation may trigger the recomputation of derived data members that depend on that relation.
TargetType and
OriginType must derive directly or transitively from
IlsObject or
IlsEntity. Derivation must be public.
The
IlsInvertedRelationList template makes a forward declaration of the function
IlsViewed* Ils2Viewed(OriginType*) and uses it in its implementation. This is to prevent the compiler from requiring 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 IlsInvertedRelationList
{
public:
(TargetType& target,
IlsActivity activity=IlsModel::GetDefaultActivity(),
IlsCardinality mincard=0,
IlsCardinality maxcard=ILS_UNLIMITED_MAXCARD,
Initial& origins=NewInitial()
IlsBoolean check_card=IlsTrue);
IlsBoolean
isIn(OriginType* e);
Myself&
cons(OriginType* newe);
Myself&
remove(OriginType* olde);
Operators
};
Constructor
IlsInvertedRelationList
(TargetType& target,
IlsActivity activity=IlsModel::GetDefaultActivity(),
IlsCardinality mincard=0,
IlsCardinality maxcard=ILS_UNLIMITED_MAXCARD,
Initial& origins=NewInitial(),
IlsBoolean check_card=IlsTrue);
This constructor takes the following arguments:
A reference to the target object (that is, to the object in which the relation is declared).
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.
The minimal cardinality of the list: This argument is optional and defaults to zero.
The maximal cardinality of the list. The maximal cardinality can be an unsigned integer, or can be indetermined. This argument is optional and defaults to
ILS_UNLIMITED_MAXCARD.
The argument
origins is a list of objects. Its default value,
NewInitial, creates an empty list.
If the length of
origins is less than the value assigned to
mincard, the exception
IlsMinCardViolated is thrown.
The argument
check_card specifies whether cardinalities should be checked at object construction.
Member Functions
[static] Initial& NewInitial();
This static member function builds an empty list which is used by the constructor as the default value of the argument origins.
Accessors
TargetType& getTarget();
This member function returns the target of the relation.
IlsCardinality getMinCard() const;
This member function indicates the minimal cardinality of the list.
IlsCardinality getMaxCard() const;
This member function indicates the maximal cardinality of the list.
unsigned int getLength() const;
This member function returns the number of objects in the list.
OriginType* getFirst();
This member function returns the first item of the list. If the list is empty, the exception
IlsForbiddenOnEmptyList is thrown.
OriginType* getLast();
This member function returns the last item of the list. If the list is empty, the exception
IlsForbiddenOnEmptyList is thrown.
IlsBoolean isIn(OriginType* e);
This member function returns IlsTrue if the specified item belongs to the list.
Adding/Removing Objects
Myself& cons(OriginType* newe);
This member function adds the specified object to the list. If this function is called when the maximum cardinality has been reached, then the exception IlsMaxCardViolated is thrown.
Myself& remove(OriginType* olde);
This member function removes the specified object from the list. If this function is called when the minimal cardinality has been reached, then the exception
IlsMinCardViolated is thrown. Removing an object that does not belong to the list causes the exception
IlsNotFound to be thrown.
Myself& clear();
This member function empties the list. If the minimal cardinality is different from zero, the exception
IlsMinCardViolated is thrown, and the number of items remaining in the list will be equal to the minimal cardinality specified.
Notification
OriginType** getAdded(int&);
During a notification phase, this member function returns an array of pointers to the objects that have been added to the list since the last notification phase. It returns an empty array if no object has been added to the list.
OriginType** getRemoved(int&);
During a notification phase, this member function returns an array of pointers to the objects that have been removed from the list since the last notification phase. It returns an empty array if no object has been removed from the list.
IlsBoolean isLengthModified();
During a notification phase, this member function returns IlsTrue if the number of objects in the list has been modified since the last notification phase.
IlsBoolean isModified();
During a notification phase, this member function returns IlsTrue if the list relation has been modified since the last notification phase, that is, if one or more items have been added to, or removed from, the list.
Operators
Myself& operator<<(OriginType* newe);
This insertion operator adds an object to the list. This operator throws the same exceptions as the cons function documented earlier.
Myself& operator>>(OriginType* olde);
This extraction operator removes an object from the list. This operator throws the same exception as the remove function documented earlier.
OriginType* operator[](unsigned int i);
This operator returns the i-th list element.
See Also
Exceptions,
IlsDerived,
IlsEntity,
IlsInvertedRelationList::Initial,
IlsInvertedRelationList::ConstIterator,
IlsInvertedRelationList::Iterator,
IlsInvertedRelationList::Position,
IlsObject,
IlsOwnsList,
IlsUsesList,
setContext,
unsetContext
Version 5.8
Copyright © 2014, Rogue Wave Software, Inc. All Rights Reserved.