Dynamic View Services > Defining Runtime Access to the Server Model > Declaring Runtime Attributes > Extended Macros
 
Extended Macros
You can use this kind of macro when:
*you need to declare a runtime attribute that is not directly associated with a C++ data member;
*you want to control the access to and/or the editing of an attribute.
These two cases are illustrated by the identifier runtime attribute of the class Project (see For Classes with Identifiers.)
The following declaration:
ILS_RW_ATTRIBUTE_STRING(Project,
ident,
getIdentifier,
setIdentifier,
isIdentifierModified)
declares the runtime attribute ident, which is neither a data member of the class Project nor a data member of the parent class IlsEntity.
This runtime attribute is fully defined by its accessor getIdentifier, its modifier setIdentifier and its modification test isIdentifierModified.
In this case, only setIdentifier is an application-specific function. The two other arguments are implemented by the class IlsEntity.
Let us assume that before modifying the project identifier, you want to check whether there is any other project with the same identifier in the project dictionary. The setIdentifier function could be written as follows:
IlsBoolean Project::setIdentifier(IlsString id)
{
Project* p=_dictionary.get(id);
if (p && p!=this){
IlsString msg;
msg << "Project " << id
<< " already exists. Cannot rename project "
<< getIdentifier()
IlsMvServer::ReplyMessage(IlsMvMessage::AppliError(msg));
return IlsFalse;
}
else{
rename(id);
return IlsTrue;
}
}
If the project name already exists, a reply message is returned to the component. Moreover, if the function returns IlsFalse, the transaction that triggered this modification is rolled back on both the server side and the component side (see Interaction Cycles).
Other macros are supplied to let you declare an entry with a user-defined modifier or define a read-only attribute. See the macros ILS_W_ENTRY_XXX and ILS_R_ATTRIBUTE_XXX, described in the Rogue Wave® Server Reference Manual, for details.
*The macros ILS_R_ATTRIBUTE_XXX and ILS_RW_ATTRIBUTE_XXX require a modification test function. For runtime attributes related to entry or derived data members, the modification test usually returns only the result of the function IlsEntry::isModified or IlsDerived::isModified.
*The macro ILS_R_ATTRIBUTE_XXX also requires a subscription function. This function is used by Rogue Wave Server to indicate that a view is, or is no longer, interested in a given attribute.
*When this attribute is related to a derived data member, the subscription function should call the member function IlsDerived::incrEagerness or IlsDerived::decrEagerness, depending on the status passed to the subscription function.
*When the attribute is related to an entry data member, the subscription function usually has an empty body.

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