Dynamic View Services > Specifying Dynamic View Types > Expression of Representation Attributes > Complex Expressions
 
Complex Expressions
On the other hand, the code extract below defines a new type of dynamic view, named DepartmentTable, on the properties of the employees in a department.
Example
view DepartmentTable:
subscribe origin Department:
represent TableR table:
string title=this.getFullName(company.identifier,name);
string column[1]="Employee name";
string column[2]="Month cost";
propagate employees;
subscribe Employee:
represent RowR row:
Ref<TableR> owner=department->table;
string column[1]=name;
string column[2]=monthCost;
string bgColor=(department.manager==this)?"green":"white";
string fgColor=(status in ("level_1", "level_2"))?"gray":"black";
This code sample contains two examples of a complex expression: one for the title attribute of the table representation, and two for the foreground and background color attributes (fgColor ant bgColor) of the row representations. These representation attributes are not editable because their value is not directly mapped to a server runtime attribute or relation.
Expressions with References to Functions
The expression for the title attribute is a call to a runtime function named getFullName. This function is declared as a runtime member function of Department as follows:
ILS_OBJECT_BEGIN(Departement)
...
ILS_MEMBER_FUNCTION2(IlsString,Department,getFullName,\
IlsString,IlsString)
...
ILS_OBJECT_END(Departement)
In the above example, the function applies to the relation this, which is implicitly declared on each server runtime type. Its target is the owner object. Thus, the expression:
string title=this.getFullName(company.identifier,department.name);
is semantically equivalent to:
string title=getFullName(company.identifier,department.name);
An implementation of this function could be:
IlsString Department::getFullName(IlsString companyNm,IlsString departmentNm)
{
IlsString res;
return res << departmentNm << " of " << companyNm;
}
Notice that the company identifier and department name are passed as arguments to the function getFullName —although these data members could have been directly accessed within the member function. This is to force the view interpreter to reevaluate the expression and to update the title representation attribute each time one of these attributes is updated.
Expression Determined by a Conditional Expression
In the second complex expression, the background color of a row representation is determined by a conditional expression:
string bgColor=(department.manager==this)?"green":"white";
This color is set to green if the employee is the department manager, and to white if it is not.
Note that the sub-expression department->manager returns an instance of IlsMvValue of type IlsMvDataType::MV_ANY, which contains a null address if the relation department is null —that is, if it has no target— or if the relation manager of the target is null. Otherwise, the value contains the address of the target object department.manager. Thus, the sub-expression department.manager==this compares this address with the address of the employee that is notified.
Expression Determined by an Enumeration Expression
An enumeration operator has been introduced in the syntax so as to test whether the result of the evaluation of an expression is equal to one of the value in the enumeration.
In the third complex expression, the background color of a row expression is determined by an enumeration expression:
string fgColor=(status in ("level_1", "level_2"))?"gray":"black";
This color is set to gray if the employee has a status equal to level_1 or level_2, or to black if his status is different. Note that in the enumeration the accepted valuse are constant values (literals).

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