Updating a Key
You might want to modify the key associated with an object belonging to a set—the flight number in our example. In this case, it is necessary that each set-relation in which the object is involved be kept informed when such a change occurs, in order to preserve their internal coherence. This requires that the flight object “knows” the sets in which it is stored.
To do this, you have to declare in the class Flight—that is, in the target class—a data member of type IlsSetContextList that will handle the list of the sets in which the object—of type Flight—is involved.
class Flight:
public IlsObject
{
public:
Flight(IlsIdentifier identifier):
_identifier(identifier),
_set_context_list(*this)
{}
private:
IlsIdentifier _identifier;
IlsSetContextList<IlsIdentifier> _set_context_list;
};
The data member _set_context_list of type IlsSetContextList is initialized in the constructor of the target class —the class Flight.
You also have to declare two public callback functions, setSetContext and unsetSetContext, that Rogue Wave® Server will automatically invoke each time a flight
is added to a set or removed from a set.
class Flight:
public IlsObject
{
public:
Flight(IlsIdentifier identifier):
_set_context_list(*this)
_identifier(identifier),
{}
void setSetContext(IlsSetContext<IlsIdentifier>& context){
_set_context_list<<&context;
}
void unsetSetContext(IlsSetContext<IlsIdentifer>& context){
_set_context_list>>&context;
}
private:
IlsIdentifier _identifier;
IlsSetContextList<IlsIdentifier> _set_context_list;
};
The first argument passed to these callbacks is an instance of the Rogue Wave Server class template IlsSetContext that takes the key type as its argument—IlsIdentifier in our example.
The last thing to do now is to define the function Flight::rename to modify the name of the key. This function must simply call the function IlsSetContextList::rehash from the Rogue Wave Server library:
void rename(IlsIdentifier id){
IlsIdentifier oldName = _identifier.getValue();
_set_context_list.rehash(oldName, id);
_identifier=id;
}
Version 6.3
Copyright © 2018, Rogue Wave Software, Inc. All Rights Reserved.