This example, uses two propagation patterns, both of which specify simple traversal directives, however these do have return values. For brevity and clarity, we will use the same cd.cd and demeter-input as in the previous examples.
The first propagation pattern will count the number of Officers:
*operation* int num_officers()
*init* (@ 0 @)
*traverse*
*from* C *to* Officer
*wrapper* Officer
*suffix* (@ return_val += 1; @)
The second propagation pattern computes the Salary for all Officers:
*operation* double officer_salary()
*init* (@ 0.0 @)
*traverse*
*from* C *via* Officer *to* Salary
*wrapper* Salary
*suffix* (@ return_val += this -> get_s() -> get_val(); @)
Then, since main.tcl is almost all automatically generated, and will look exactlly like the one created in the class dictionary example, the only section which is included here is the part which may be modified by the user:
#------------------------------------ #Your code follows after this #------------------------------------ # Here is the call to the first propagation pattern # Number of officers puts "Number of Officers Propagation Pattern Output" set numO [$nC num_officers:] puts "Number of Officers =" puts $numO # Here is the call to the second propagation pattern # Officer Salary puts "Officers Salary Propagation Pattern Output" set oSal [$nC officer_salary:] puts "Total Officer Salary = " puts $oSal #------------------------------------
Before viewing the output, the user should have a good idea of what she expects to receive as return values. Looking at the demeter input file she can see that there are five officers. Therefore the first propagation pattern should return 5. Likewise, she can add their salaries relatively quickly:
225.00 + 229.12 + 122.10 + 214.84 + 257.32 = 1098.38
This is the output which is produced by typing run, edited, so that the only output given below is the output which is actually generated by the call to the propagation pattern:
Number of Officers Propagation Pattern Output
>> void C::num_officers_(int& return_val), "1-DEM.C", line 17
>> void A::num_officers_(int& return_val), "1-DEM.C", line 39
>> void MemberList::num_officers_(int& return_val), "1-DEM.C", line 65
>> void Member::num_officers_(int& return_val), "1-DEM.C", line 93
>> at Regular , *** PREMATURELY TERMINATED *** , "1-DEM.C", line 95
<< at Regular , *** PREMATURELY TERMINATED *** , "1-DEM.C", line 95
<< void Member::num_officers_(int& return_val), "1-DEM.C", line 93
>> void Officer::num_officers_(int& return_val), "1-DEM.C", line 104
<< void Officer::num_officers_(int& return_val), "1-DEM.C", line 104
>> void Officer::num_officers_(int& return_val), "1-DEM.C", line 104
<< void Officer::num_officers_(int& return_val), "1-DEM.C", line 104
<< void MemberList::num_officers_(int& return_val), "1-DEM.C", line 65
>> void SubAList::num_officers_(int& return_val), "1-DEM.C", line 124
>> void Whole::num_officers_(int& return_val), "1-DEM.C", line 163
>> void A::num_officers_(int& return_val), "1-DEM.C", line 39
>> void MemberList::num_officers_(int& return_val), "1-DEM.C", line 65
>> void Member::num_officers_(int& return_val), "1-DEM.C", line 93
>> at Regular , *** PREMATURELY TERMINATED *** , "1-DEM.C", line 95
<< at Regular , *** PREMATURELY TERMINATED *** , "1-DEM.C", line 95
<< void Member::num_officers_(int& return_val), "1-DEM.C", line 93
>> void Officer::num_officers_(int& return_val), "1-DEM.C", line 104
<< void Officer::num_officers_(int& return_val), "1-DEM.C", line 104
<< void MemberList::num_officers_(int& return_val), "1-DEM.C", line 65
<< void A::num_officers_(int& return_val), "1-DEM.C", line 39
<< void Whole::num_officers_(int& return_val), "1-DEM.C", line 163
>> void Partial::num_officers_(int& return_val), "1-DEM.C", line 188
>> void A::num_officers_(int& return_val), "1-DEM.C", line 39
>> void MemberList::num_officers_(int& return_val), "1-DEM.C", line 65
>> void Member::num_officers_(int& return_val), "1-DEM.C", line 93
>> at Regular , *** PREMATURELY TERMINATED *** , "1-DEM.C", line 95
<< at Regular , *** PREMATURELY TERMINATED *** , "1-DEM.C", line 95
<< void Member::num_officers_(int& return_val), "1-DEM.C", line 93
>> void Officer::num_officers_(int& return_val), "1-DEM.C", line 104
<< void Officer::num_officers_(int& return_val), "1-DEM.C", line 104
>> void Officer::num_officers_(int& return_val), "1-DEM.C", line 104
<< void Officer::num_officers_(int& return_val), "1-DEM.C", line 104
<< void MemberList::num_officers_(int& return_val), "1-DEM.C", line 65
<< void A::num_officers_(int& return_val), "1-DEM.C", line 39
<< void Partial::num_officers_(int& return_val), "1-DEM.C", line 188
<< void SubAList::num_officers_(int& return_val), "1-DEM.C", line 124
<< void A::num_officers_(int& return_val), "1-DEM.C", line 39
<< void C::num_officers_(int& return_val), "1-DEM.C", line 17
<< int C::num_officers(), "1-DEM.C", line 7
Number of Officers =
5
Officers Salary Propagation Pattern Output
>> double C::officer_salary(), "2-DEM.C", line 7
>> void C::officer_salary_(double& return_val), "2-DEM.C", line 17
>> void A::officer_salary_(double& return_val), "2-DEM.C", line 39
>> void MemberList::officer_salary_(double& return_val), "2-DEM.C", line 65
>> void Member::officer_salary_(double& return_val), "2-DEM.C", line 93
>> at Regular , *** PREMATURELY TERMINATED *** , "2-DEM.C", line 95
<< at Regular , *** PREMATURELY TERMINATED *** , "2-DEM.C", line 95
<< void Member::officer_salary_(double& return_val), "2-DEM.C", line 93
>> void Officer::officer_salary_(double& return_val), "2-DEM.C", line 104
>> void Salary::officer_salary_(double& return_val), "2-DEM.C", line 129
<< void Salary::officer_salary_(double& return_val), "2-DEM.C", line 129
<< void Officer::officer_salary_(double& return_val), "2-DEM.C", line 104
>> void Officer::officer_salary_(double& return_val), "2-DEM.C", line 104
>> void Salary::officer_salary_(double& return_val), "2-DEM.C", line 129
<< void Salary::officer_salary_(double& return_val), "2-DEM.C", line 129
<< void Officer::officer_salary_(double& return_val), "2-DEM.C", line 104
<< void MemberList::officer_salary_(double& return_val), "2-DEM.C", line 65
>> void SubAList::officer_salary_(double& return_val), "2-DEM.C", line 147
>> void Whole::officer_salary_(double& return_val), "2-DEM.C", line 186
>> void A::officer_salary_(double& return_val), "2-DEM.C", line 39
>> void MemberList::officer_salary_(double& return_val), "2-DEM.C", line 65
>> void Member::officer_salary_(double& return_val), "2-DEM.C", line 93
>> at Regular , *** PREMATURELY TERMINATED *** , "2-DEM.C", line 95
<< at Regular , *** PREMATURELY TERMINATED *** , "2-DEM.C", line 95
<< void Member::officer_salary_(double& return_val), "2-DEM.C", line 93
>> void Officer::officer_salary_(double& return_val), "2-DEM.C", line 104
>> void Salary::officer_salary_(double& return_val), "2-DEM.C", line 129
<< void Salary::officer_salary_(double& return_val), "2-DEM.C", line 129
<< void Officer::officer_salary_(double& return_val), "2-DEM.C", line 104
<< void MemberList::officer_salary_(double& return_val), "2-DEM.C", line 65
<< void A::officer_salary_(double& return_val), "2-DEM.C", line 39
<< void Whole::officer_salary_(double& return_val), "2-DEM.C", line 186
>> void Partial::officer_salary_(double& return_val), "2-DEM.C", line 211
>> void A::officer_salary_(double& return_val), "2-DEM.C", line 39
>> void MemberList::officer_salary_(double& return_val), "2-DEM.C", line 65
>> void Member::officer_salary_(double& return_val), "2-DEM.C", line 93
>> at Regular , *** PREMATURELY TERMINATED *** , "2-DEM.C", line 95
<< at Regular , *** PREMATURELY TERMINATED *** , "2-DEM.C", line 95
<< void Member::officer_salary_(double& return_val), "2-DEM.C", line 93
>> void Officer::officer_salary_(double& return_val), "2-DEM.C", line 104
>> void Salary::officer_salary_(double& return_val), "2-DEM.C", line 129
<< void Salary::officer_salary_(double& return_val), "2-DEM.C", line 129
<< void Officer::officer_salary_(double& return_val), "2-DEM.C", line 104
>> void Officer::officer_salary_(double& return_val), "2-DEM.C", line 104
>> void Salary::officer_salary_(double& return_val), "2-DEM.C", line 129
<< void Salary::officer_salary_(double& return_val), "2-DEM.C", line 129
<< void Officer::officer_salary_(double& return_val), "2-DEM.C", line 104
<< void MemberList::officer_salary_(double& return_val), "2-DEM.C", line 65
<< void A::officer_salary_(double& return_val), "2-DEM.C", line 39
<< void Partial::officer_salary_(double& return_val), "2-DEM.C", line 211
<< void SubAList::officer_salary_(double& return_val), "2-DEM.C", line 147
<< void A::officer_salary_(double& return_val), "2-DEM.C", line 39
<< void C::officer_salary_(double& return_val), "2-DEM.C", line 17
<< double C::officer_salary(), "2-DEM.C", line 7
Total Officer Salary =
1098.380005