1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>libqalculate-0.9.7: UserFunction Class Reference</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.5 -->
<div class="navigation" id="top">
<div class="tabs">
<ul>
<li><a href="index.html"><span>Main Page</span></a></li>
<li class="current"><a href="classes.html"><span>Classes</span></a></li>
<li><a href="files.html"><span>Files</span></a></li>
</ul>
</div>
<div class="tabs">
<ul>
<li><a href="classes.html"><span>Alphabetical List</span></a></li>
<li><a href="annotated.html"><span>Class List</span></a></li>
<li><a href="hierarchy.html"><span>Class Hierarchy</span></a></li>
<li><a href="functions.html"><span>Class Members</span></a></li>
</ul>
</div>
</div>
<div class="contents">
<h1>UserFunction Class Reference</h1><!-- doxytag: class="UserFunction" --><!-- doxytag: inherits="MathFunction" -->A user defined mathematical function.
<a href="#_details">More...</a>
<p>
<code>#include <Function.h></code>
<p>
<div class="dynheader">
Inheritance diagram for UserFunction:</div>
<div class="dynsection">
<p><center><img src="classUserFunction.png" usemap="#UserFunction_map" border="0" alt=""></center>
<map name="UserFunction_map">
<area href="classMathFunction.html" alt="MathFunction" shape="rect" coords="0,56,96,80">
<area href="classExpressionItem.html" alt="ExpressionItem" shape="rect" coords="0,0,96,24">
</map>
</div>
<p>
<a href="classUserFunction-members.html">List of all members.</a><table border="0" cellpadding="0" cellspacing="0">
<tr><td></td></tr>
<tr><td colspan="2"><br><h2>Public Member Functions</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="e5efd39607a7e8e63a6d5bb9c80284fd"></a><!-- doxytag: member="UserFunction::UserFunction" ref="e5efd39607a7e8e63a6d5bb9c80284fd" args="(string cat_, string name_, string formula_, bool is_local=true, int argc_=-1, string title_="", string descr_="", int max_argc_=0, bool is_active=true)" -->
</td><td class="memItemRight" valign="bottom"><b>UserFunction</b> (string cat_, string name_, string formula_, bool is_local=true, int argc_=-1, string title_="", string descr_="", int max_argc_=0, bool is_active=true)</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="51200fd29d8a87270e05fa2804290592"></a><!-- doxytag: member="UserFunction::UserFunction" ref="51200fd29d8a87270e05fa2804290592" args="(const UserFunction *function)" -->
</td><td class="memItemRight" valign="bottom"><b>UserFunction</b> (const <a class="el" href="classUserFunction.html">UserFunction</a> *function)</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="859fbcd5dd3334225236533a707da315"></a><!-- doxytag: member="UserFunction::set" ref="859fbcd5dd3334225236533a707da315" args="(const ExpressionItem *item)" -->
void </td><td class="memItemRight" valign="bottom"><b>set</b> (const <a class="el" href="classExpressionItem.html">ExpressionItem</a> *item)</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="977bcae2b31f4f7b434146de024af973"></a><!-- doxytag: member="UserFunction::copy" ref="977bcae2b31f4f7b434146de024af973" args="() const " -->
<a class="el" href="classExpressionItem.html">ExpressionItem</a> * </td><td class="memItemRight" valign="bottom"><b>copy</b> () const </td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">string </td><td class="memItemRight" valign="bottom"><a class="el" href="classUserFunction.html#ebc08bff43873105e5a303f37c5a3934">formula</a> () const </td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">string </td><td class="memItemRight" valign="bottom"><a class="el" href="classUserFunction.html#937b1ebf753bad0e97ab4edb62d9fe9d">internalFormula</a> () const </td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="classUserFunction.html#eb9215783f3ea3c0dd339a07903bddb3">calculate</a> (<a class="el" href="classMathStructure.html">MathStructure</a> &mstruct, const <a class="el" href="classMathStructure.html">MathStructure</a> &vargs, const <a class="el" href="structEvaluationOptions.html">EvaluationOptions</a> &eo)</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="classUserFunction.html#c55dd008a692088cab7028c1ff0275db">setFormula</a> (string new_formula, int argc_=-1, int max_argc_=0)</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="95e09e51fe699744ab4fe77e9dd71461"></a><!-- doxytag: member="UserFunction::addSubfunction" ref="95e09e51fe699744ab4fe77e9dd71461" args="(string subfunction, bool precalculate=true)" -->
void </td><td class="memItemRight" valign="bottom"><b>addSubfunction</b> (string subfunction, bool precalculate=true)</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="classUserFunction.html#d9478f600ee1601f5e1a3351722cd23e">setSubfunction</a> (size_t index, string subfunction)</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="0a6f7dfa338bda7b6fbd42621da68043"></a><!-- doxytag: member="UserFunction::delSubfunction" ref="0a6f7dfa338bda7b6fbd42621da68043" args="(size_t index)" -->
void </td><td class="memItemRight" valign="bottom"><b>delSubfunction</b> (size_t index)</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="b12a1cfe02f125279ff6697b61ab4d14"></a><!-- doxytag: member="UserFunction::clearSubfunctions" ref="b12a1cfe02f125279ff6697b61ab4d14" args="()" -->
void </td><td class="memItemRight" valign="bottom"><b>clearSubfunctions</b> ()</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="d078ab882857e2ab8cc54e7cec666fff"></a><!-- doxytag: member="UserFunction::countSubfunctions" ref="d078ab882857e2ab8cc54e7cec666fff" args="() const " -->
size_t </td><td class="memItemRight" valign="bottom"><b>countSubfunctions</b> () const </td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="66558b8f41b9faa99a9ac63d36f14c6a"></a><!-- doxytag: member="UserFunction::setSubfunctionPrecalculated" ref="66558b8f41b9faa99a9ac63d36f14c6a" args="(size_t index, bool precalculate)" -->
void </td><td class="memItemRight" valign="bottom"><b>setSubfunctionPrecalculated</b> (size_t index, bool precalculate)</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="69112d81ea725411baebb18da8db54d8"></a><!-- doxytag: member="UserFunction::getSubfunction" ref="69112d81ea725411baebb18da8db54d8" args="(size_t index) const " -->
const string & </td><td class="memItemRight" valign="bottom"><b>getSubfunction</b> (size_t index) const </td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="d8c632b7787780563c9e0a4b8411ec50"></a><!-- doxytag: member="UserFunction::subfunctionPrecalculated" ref="d8c632b7787780563c9e0a4b8411ec50" args="(size_t index) const " -->
bool </td><td class="memItemRight" valign="bottom"><b>subfunctionPrecalculated</b> (size_t index) const </td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="classUserFunction.html#bc53125233703260602bfcb4c3ffb7a5">subtype</a> () const </td></tr>
<tr><td colspan="2"><br><h2>Protected Attributes</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="def2aa020e61548eba99668304638e0c"></a><!-- doxytag: member="UserFunction::sformula" ref="def2aa020e61548eba99668304638e0c" args="" -->
string </td><td class="memItemRight" valign="bottom"><b>sformula</b></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="5199b7c0a47ef76bc0baeb5f274619f9"></a><!-- doxytag: member="UserFunction::sformula_calc" ref="5199b7c0a47ef76bc0baeb5f274619f9" args="" -->
string </td><td class="memItemRight" valign="bottom"><b>sformula_calc</b></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="1fc5ea2b2f486e4b24998a9fa27ea3f0"></a><!-- doxytag: member="UserFunction::v_subs" ref="1fc5ea2b2f486e4b24998a9fa27ea3f0" args="" -->
vector< string > </td><td class="memItemRight" valign="bottom"><b>v_subs</b></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="568d49d6d854e54ff4142d677771ce11"></a><!-- doxytag: member="UserFunction::v_precalculate" ref="568d49d6d854e54ff4142d677771ce11" args="" -->
vector< bool > </td><td class="memItemRight" valign="bottom"><b>v_precalculate</b></td></tr>
</table>
<hr><a name="_details"></a><h2>Detailed Description</h2>
A user defined mathematical function.
<p>
User functions are functions defined using expression strings, representing mathematical formulas.<p>
The expression/formula of a function is basically a normal expression with placeholders for arguments. These placeholders consists of a backslash and a letter — x, y, z for the 1st, 2nd and 3rd arguments and a to u for argument 4 to 24. They are replaced by entered arguments when a function is calculated. The placeholders naturally also decide the number of arguments that a function requires. For example the function for triangle area ("base * height / 2") has the name triangle and the formula "(\x*\y)/2", which gives that "triangle(2, 3)" equals "(2*3) / 2" and returns "3" as result. An argument can be used more than one time and all arguments must not necessarily be in order in the formula.<p>
Additionally, optional arguments can be put in the formula with upper-case (X, Y, Z, ...) instead of lower-case letters (x, y, z, ...). The default value can be put in brackets after the letter (ex. "\X{2}"). The default value may be omitted and is then zero. All additional arguments after an optional argument must also be optional.<p>
To simplify the formula and make it more efficient, subfunctions can be used. These works just like the main formula, using the arguments of it. Subfunctions are referenced in the formula using ('', '', '', ...). Even though it would be quite meaningless, the formula for triangle function could for example have a subfunction "\x*\y" and the formula "\1/2". Subfunctions must be added before the main formula is set. <hr><h2>Member Function Documentation</h2>
<a class="anchor" name="ebc08bff43873105e5a303f37c5a3934"></a><!-- doxytag: member="UserFunction::formula" ref="ebc08bff43873105e5a303f37c5a3934" args="() const " -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">string UserFunction::formula </td>
<td>(</td>
<td class="paramname"> </td>
<td> ) </td>
<td width="100%"> const</td>
</tr>
</table>
</div>
<div class="memdoc">
<p>
Returns the external representation of the formula.
</div>
</div><p>
<a class="anchor" name="937b1ebf753bad0e97ab4edb62d9fe9d"></a><!-- doxytag: member="UserFunction::internalFormula" ref="937b1ebf753bad0e97ab4edb62d9fe9d" args="() const " -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">string UserFunction::internalFormula </td>
<td>(</td>
<td class="paramname"> </td>
<td> ) </td>
<td width="100%"> const</td>
</tr>
</table>
</div>
<div class="memdoc">
<p>
Returns the internal representation of the formula.
</div>
</div><p>
<a class="anchor" name="eb9215783f3ea3c0dd339a07903bddb3"></a><!-- doxytag: member="UserFunction::calculate" ref="eb9215783f3ea3c0dd339a07903bddb3" args="(MathStructure &mstruct, const MathStructure &vargs, const EvaluationOptions &eo)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">int UserFunction::calculate </td>
<td>(</td>
<td class="paramtype"><a class="el" href="classMathStructure.html">MathStructure</a> & </td>
<td class="paramname"> <em>mstruct</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">const <a class="el" href="classMathStructure.html">MathStructure</a> & </td>
<td class="paramname"> <em>vargs</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">const <a class="el" href="structEvaluationOptions.html">EvaluationOptions</a> & </td>
<td class="paramname"> <em>eo</em></td><td> </td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td><td width="100%"><code> [virtual]</code></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>
The main function for subclasses to reimplement. Calculates a value from arguments in vargs and puts it in mstruct.<p>
This function expects the number of arguments to be equal to the maximum number of arguments, and checked by the argument definitions.<p>
If the return value is negative, then argument -(return value) has been evaluated in mstruct. If -(return value) is greater than max arguments, then mstruct is a vector of evaluated argument values.<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
<table border="0" cellspacing="2" cellpadding="0">
<tr><td valign="top"><tt>[out]</tt> </td><td valign="top"><em>mstruct</em> </td><td>Structure that is set with the result of the calculation. </td></tr>
<tr><td valign="top"></td><td valign="top"><em>vargs</em> </td><td>Arguments passed to the mathematical function. </td></tr>
<tr><td valign="top"></td><td valign="top"><em>eo</em> </td><td>Evaluation options. </td></tr>
</table>
</dl>
<dl class="return" compact><dt><b>Returns:</b></dt><dd>1 if the calculation was successful. </dd></dl>
<p>Reimplemented from <a class="el" href="classMathFunction.html#5ce71d94adcafa5a2d355c9c56cb0632">MathFunction</a>.</p>
</div>
</div><p>
<a class="anchor" name="c55dd008a692088cab7028c1ff0275db"></a><!-- doxytag: member="UserFunction::setFormula" ref="c55dd008a692088cab7028c1ff0275db" args="(string new_formula, int argc_=-1, int max_argc_=0)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void UserFunction::setFormula </td>
<td>(</td>
<td class="paramtype">string </td>
<td class="paramname"> <em>new_formula</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">int </td>
<td class="paramname"> <em>argc_</em> = <code>-1</code>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">int </td>
<td class="paramname"> <em>max_argc_</em> = <code>0</code></td><td> </td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td><td width="100%"></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>
Sets the formula of the mathematical function.<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
<table border="0" cellspacing="2" cellpadding="0">
<tr><td valign="top"></td><td valign="top"><em>new_formula</em> </td><td>Formula/expression. </td></tr>
<tr><td valign="top"></td><td valign="top"><em>arc_</em> </td><td>Minimum number of arguments or -1 to read from formula. </td></tr>
<tr><td valign="top"></td><td valign="top"><em>max_argc_</em> </td><td>Maximum number of arguments (ignored if argc_ < 0) </td></tr>
</table>
</dl>
</div>
</div><p>
<a class="anchor" name="d9478f600ee1601f5e1a3351722cd23e"></a><!-- doxytag: member="UserFunction::setSubfunction" ref="d9478f600ee1601f5e1a3351722cd23e" args="(size_t index, string subfunction)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void UserFunction::setSubfunction </td>
<td>(</td>
<td class="paramtype">size_t </td>
<td class="paramname"> <em>index</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">string </td>
<td class="paramname"> <em>subfunction</em></td><td> </td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td><td width="100%"></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>
Sets the formula for a subfunction.<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
<table border="0" cellspacing="2" cellpadding="0">
<tr><td valign="top"></td><td valign="top"><em>index</em> </td><td>Index (starting at 1). </td></tr>
<tr><td valign="top"></td><td valign="top"><em>subfunction</em> </td><td>Formula/expression. </td></tr>
</table>
</dl>
</div>
</div><p>
<a class="anchor" name="bc53125233703260602bfcb4c3ffb7a5"></a><!-- doxytag: member="UserFunction::subtype" ref="bc53125233703260602bfcb4c3ffb7a5" args="() const " -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">int UserFunction::subtype </td>
<td>(</td>
<td class="paramname"> </td>
<td> ) </td>
<td width="100%"> const<code> [virtual]</code></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>
Returns the subtype of the mathematical function, corresponding to which subsubclass the object belongs to.<p>
<dl class="return" compact><dt><b>Returns:</b></dt><dd><a class="el" href="Function_8h.html#fec0f104510357adbe8df8a9f3a7ce9a" title="Type of mathematical function.">FunctionSubtype</a>. </dd></dl>
<p>Reimplemented from <a class="el" href="classMathFunction.html#1173ab198af529b3a13e7c8ef01d6d1f">MathFunction</a>.</p>
</div>
</div><p>
<hr>The documentation for this class was generated from the following file:<ul>
<li>libqalculate/<a class="el" href="Function_8h.html">Function.h</a></ul>
</div>
<hr size="1"><address style="text-align: right;"><small>Generated on Tue Jan 5 08:26:29 2010 for libqalculate-0.9.7 by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.5 </small></address>
</body>
</html>
|