| 1 |
<html> |
| 2 |
<head> |
| 3 |
<style type="text/css"> |
| 4 |
p.example { background-color: #fcc; |
| 5 |
font-family: monospace; |
| 6 |
white-space: pre;; } |
| 7 |
p.result { background-color: #ccc; } |
| 8 |
</style> |
| 9 |
</head> |
| 10 |
<body> |
| 11 |
|
| 12 |
<h1>Calling subcomponents</h1> |
| 13 |
|
| 14 |
<p> |
| 15 |
<b>Ecpp</b>-pages can embed other pages. These embedded pages are called |
| 16 |
subcomponents. They come in 2 variants: local and external. Local |
| 17 |
subcomponents are defined inside another component with |
| 18 |
<b><%def <i>componentname</i>></b> and closed with |
| 19 |
<b></def></b>. External subcomponents are normal components. |
| 20 |
</p> |
| 21 |
|
| 22 |
<p> |
| 23 |
A subcomponentcall starts with <b><&</b> and ends with |
| 24 |
<b>&></b>. Insert the componentname between these tags. If you omit the |
| 25 |
library-part of the component, the current library is used. If the |
| 26 |
componentname is a single word, ecpp looks for a local component, which is |
| 27 |
called if found. Otherwise it is a external componentcall. |
| 28 |
</p> |
| 29 |
|
| 30 |
<p> |
| 31 |
You can dynamically build componentnames, by putting a c++-expression inside |
| 32 |
brackets. This expression is evaluated on runtime and the resulting component |
| 33 |
is called. The expression can be of type (or convertable to) |
| 34 |
<b>std::string</b>, <b>tnt::Compident</b> or <b>tnt::Subcompident</b>. |
| 35 |
</p> |
| 36 |
|
| 37 |
<p> |
| 38 |
After the componentname you can add named parameters. Put a name followed by |
| 39 |
'=' and a value. The value is either a constant string or a expression. A |
| 40 |
expression must be bracketed. If you want to pass just the same parameters |
| 41 |
your current component received, put the single word <b>qparam</b> into the |
| 42 |
list (actually you can pass any <b>cxxtools::query_params</b>-variable). |
| 43 |
</p> |
| 44 |
|
| 45 |
<p> |
| 46 |
A special case are local components, which have c++-parameters. You can put a |
| 47 |
normal parameterlist just like in c++-functions after the defition |
| 48 |
(<b><%def></b>-block) after the componentname. The can only be called locally. |
| 49 |
</p> |
| 50 |
|
| 51 |
<h2>Just a local componentcall</h2> |
| 52 |
|
| 53 |
<p class="example"> |
| 54 |
<& localcomp param1="value1" &> |
| 55 |
</p> |
| 56 |
|
| 57 |
<p class="result"> |
| 58 |
<& localcomp param1="value1" &> |
| 59 |
</p> |
| 60 |
|
| 61 |
|
| 62 |
<h2> Another local componentcall. We pass a c++-parameter. </h2> |
| 63 |
<p class="example"> |
| 64 |
<& localcomp_p(5) &> |
| 65 |
</p> |
| 66 |
<p class="result"> |
| 67 |
<& localcomp_p(5) > |
| 68 |
</p> |
| 69 |
|
| 70 |
|
| 71 |
<h2>A external componentcall (localcomp "extcomp" does not exist)</h2> |
| 72 |
|
| 73 |
<p class="example"> |
| 74 |
<& subcomp param1="value1" &> |
| 75 |
</p> |
| 76 |
<p class="result"> |
| 77 |
<& subcomp param1="value1" &> |
| 78 |
</p> |
| 79 |
|
| 80 |
<h2> a external componentcall </h2> |
| 81 |
|
| 82 |
<p class="example"> |
| 83 |
<& extcomp@extlib param1="value1" &> |
| 84 |
</p> |
| 85 |
<p class="result"> |
| 86 |
<& extcomp@extlib param1="value1" &> |
| 87 |
</p> |
| 88 |
|
| 89 |
<h2> a external subcomponentcall </h2> |
| 90 |
|
| 91 |
<p class="example"> |
| 92 |
<& extcomp.subcomp@extlib param1="value1" &> |
| 93 |
</p> |
| 94 |
<p class="result"> |
| 95 |
<& extcomp.subcomp@extlib param1="value1" &> |
| 96 |
</p> |
| 97 |
|
| 98 |
<h2> compose componentname by expression </h2> |
| 99 |
<{ |
| 100 |
// define some variables here |
| 101 |
std::string compname = "extcomp"; |
| 102 |
std::string libname = "extlib"; |
| 103 |
}> |
| 104 |
<p class="example"> |
| 105 |
<& (compname + '@' + libname) param1="value1" &> |
| 106 |
</p> |
| 107 |
<p class="result"> |
| 108 |
<& (compname + '@' + libname) param1="value1" &> |
| 109 |
</p> |
| 110 |
|
| 111 |
<h2> call component by componentidentifier </h2> |
| 112 |
<p class="example"> |
| 113 |
<& (tnt::Compident(compname, libname)) param1="value1" &> |
| 114 |
</p> |
| 115 |
<p class="result"> |
| 116 |
<& (tnt::Compident(libname, compname)) param1="value1" &> |
| 117 |
</p> |
| 118 |
|
| 119 |
<h2> pass a expression as parameter </h2> |
| 120 |
<p class="example"> |
| 121 |
<& localcomp param1=(1+5) qparam param2="uhu"&> |
| 122 |
</p> |
| 123 |
<p class="result"> |
| 124 |
<& localcomp param1=(1+5) qparam param2="uhu"&> |
| 125 |
</p> |
| 126 |
|
| 127 |
<h2> pass multiple values with the same name as parameter </h2> |
| 128 |
<p class="example"> |
| 129 |
<& localcomp param3="value1" param3="value2" |
| 130 |
param4="17" param4=(28) &> |
| 131 |
</p> |
| 132 |
<& localcomp param3="value1" param3="value2" |
| 133 |
param4="17" param4=(28) &> |
| 134 |
|
| 135 |
<%doc> |
| 136 |
<h2> call subcomponents in c++-blocks </h2> |
| 137 |
<p class="example"> |
| 138 |
callComp("extcomp@extlib", request, reply, qparam); |
| 139 |
</p> |
| 140 |
<p class="result"> |
| 141 |
<{ |
| 142 |
callComp("extcomp@extlib", request, reply, qparam); |
| 143 |
}> |
| 144 |
</p> |
| 145 |
|
| 146 |
</body> |
| 147 |
</html> |
| 148 |
|
| 149 |
<%def localcomp> |
| 150 |
<%args> |
| 151 |
param1; |
| 152 |
param2; |
| 153 |
param3[]; |
| 154 |
int param4[]; |
| 155 |
</%args> |
| 156 |
This is a local subcomponent. |
| 157 |
We got a parameter <i>param1</i> with the value <b><$param1$></b>. |
| 158 |
% if (!param2.empty()) { |
| 159 |
We got <i>param2</i> also. Its value is <b><$param2$></b>. |
| 160 |
% } |
| 161 |
We got <$ param3.size() $> times "param3" and <$ param4.size() $> times |
| 162 |
"param4". |
| 163 |
The values of param3 are: |
| 164 |
<{ std::copy(param3.begin(), param3.end(), |
| 165 |
std::ostream_iterator<param3_type::value_type>(reply.out(), ", ")); }>. |
| 166 |
The values of param4 are: |
| 167 |
<{ std::copy(param4.begin(), param4.end(), |
| 168 |
std::ostream_iterator<param4_type::value_type>(reply.out(), ", ")); }>. |
| 169 |
</%def> |
| 170 |
</%doc> |
| 171 |
|
| 172 |
<%def localcomp_p(int i)> |
| 173 |
This is a local subcomponent with parameter. |
| 174 |
We got a c++-integer-parameter with the value <b><$i$></b>. |
| 175 |
This component can only be called locally because of c++-parameters. |
| 176 |
</%def> |