libqalculate-ruby 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Makefile +157 -0
- data/Rakefile +7 -0
- data/ext/libqalculate/BuiltinFunctions.h +261 -0
- data/ext/libqalculate/Calculator.h +1037 -0
- data/ext/libqalculate/DataSet.h +304 -0
- data/ext/libqalculate/ExpressionItem.h +289 -0
- data/ext/libqalculate/Function.h +766 -0
- data/ext/libqalculate/MathStructure.h +827 -0
- data/ext/libqalculate/Number.h +387 -0
- data/ext/libqalculate/Prefix.h +219 -0
- data/ext/libqalculate/Unit.h +300 -0
- data/ext/libqalculate/Variable.h +380 -0
- data/ext/libqalculate/includes.h +644 -0
- data/ext/libqalculate/qalculate.h +28 -0
- data/ext/libqalculate/util.h +88 -0
- data/ext/qalc_wrap.cxx +198164 -0
- data/extconf.rb +8 -0
- data/test/test_qalc.rb +40 -0
- metadata +71 -0
@@ -0,0 +1,766 @@
|
|
1
|
+
/*
|
2
|
+
Qalculate
|
3
|
+
|
4
|
+
Copyright (C) 2003-2007 Niklas Knutsson (nq@altern.org)
|
5
|
+
|
6
|
+
This program is free software; you can redistribute it and/or modify
|
7
|
+
it under the terms of the GNU General Public License as published by
|
8
|
+
the Free Software Foundation; either version 2 of the License, or
|
9
|
+
(at your option) any later version.
|
10
|
+
*/
|
11
|
+
|
12
|
+
#ifndef FUNCTION_H
|
13
|
+
#define FUNCTION_H
|
14
|
+
|
15
|
+
#include <libqalculate/ExpressionItem.h>
|
16
|
+
#include <libqalculate/includes.h>
|
17
|
+
|
18
|
+
/** @file */
|
19
|
+
|
20
|
+
///Argument types
|
21
|
+
typedef enum {
|
22
|
+
ARGUMENT_TYPE_FREE,
|
23
|
+
ARGUMENT_TYPE_SYMBOLIC,
|
24
|
+
ARGUMENT_TYPE_TEXT,
|
25
|
+
ARGUMENT_TYPE_DATE,
|
26
|
+
ARGUMENT_TYPE_FILE,
|
27
|
+
ARGUMENT_TYPE_INTEGER,
|
28
|
+
ARGUMENT_TYPE_NUMBER,
|
29
|
+
ARGUMENT_TYPE_VECTOR,
|
30
|
+
ARGUMENT_TYPE_MATRIX,
|
31
|
+
ARGUMENT_TYPE_EXPRESSION_ITEM,
|
32
|
+
ARGUMENT_TYPE_FUNCTION,
|
33
|
+
ARGUMENT_TYPE_UNIT,
|
34
|
+
ARGUMENT_TYPE_BOOLEAN,
|
35
|
+
ARGUMENT_TYPE_VARIABLE,
|
36
|
+
ARGUMENT_TYPE_ANGLE,
|
37
|
+
ARGUMENT_TYPE_SET,
|
38
|
+
ARGUMENT_TYPE_DATA_OBJECT,
|
39
|
+
ARGUMENT_TYPE_DATA_PROPERTY
|
40
|
+
} ArgumentType;
|
41
|
+
|
42
|
+
///Predefined max and min values for number and integer arguments.
|
43
|
+
typedef enum {
|
44
|
+
ARGUMENT_MIN_MAX_NONE,
|
45
|
+
ARGUMENT_MIN_MAX_POSITIVE,
|
46
|
+
ARGUMENT_MIN_MAX_NONZERO,
|
47
|
+
ARGUMENT_MIN_MAX_NONNEGATIVE,
|
48
|
+
ARGUMENT_MIN_MAX_NEGATIVE
|
49
|
+
} ArgumentMinMaxPreDefinition;
|
50
|
+
|
51
|
+
/// Type of mathematical function
|
52
|
+
typedef enum {
|
53
|
+
/// class MathFunction
|
54
|
+
SUBTYPE_FUNCTION,
|
55
|
+
/// class UseFunction
|
56
|
+
SUBTYPE_USER_FUNCTION,
|
57
|
+
/// class DataSet
|
58
|
+
SUBTYPE_DATA_SET
|
59
|
+
} FunctionSubtype;
|
60
|
+
|
61
|
+
/// Abstract base class for mathematical functions.
|
62
|
+
/**
|
63
|
+
* A mathemical function, subclassed from MathFunction, should at least reimplement
|
64
|
+
* calculate(MathStructure&, const MathStructure&, const EvaluationOptions&) and copy(), and preferably also the represents* functions.
|
65
|
+
* Argument definitions should be added in the constructor.
|
66
|
+
*/
|
67
|
+
class MathFunction : public ExpressionItem {
|
68
|
+
|
69
|
+
protected:
|
70
|
+
|
71
|
+
int argc;
|
72
|
+
int max_argc;
|
73
|
+
vector<string> default_values;
|
74
|
+
Sgi::hash_map<size_t, Argument*> argdefs;
|
75
|
+
size_t last_argdef_index;
|
76
|
+
bool testArguments(MathStructure &vargs);
|
77
|
+
virtual MathStructure createFunctionMathStructureFromVArgs(const MathStructure &vargs);
|
78
|
+
virtual MathStructure createFunctionMathStructureFromSVArgs(vector<string> &svargs);
|
79
|
+
string scondition;
|
80
|
+
|
81
|
+
public:
|
82
|
+
|
83
|
+
MathFunction(string name_, int argc_, int max_argc_ = 0, string cat_ = "", string title_ = "", string descr_ = "", bool is_active = true);
|
84
|
+
MathFunction(const MathFunction *function);
|
85
|
+
MathFunction();
|
86
|
+
virtual ~MathFunction();
|
87
|
+
|
88
|
+
virtual ExpressionItem *copy() const = 0;
|
89
|
+
virtual void set(const ExpressionItem *item);
|
90
|
+
virtual int type() const;
|
91
|
+
/** Returns the subtype of the mathematical function, corresponding to which subsubclass the object belongs to.
|
92
|
+
*
|
93
|
+
* @returns ::FunctionSubtype.
|
94
|
+
*/
|
95
|
+
virtual int subtype() const;
|
96
|
+
|
97
|
+
bool testArgumentCount(int itmp);
|
98
|
+
virtual MathStructure calculate(const string &eq, const EvaluationOptions &eo = default_evaluation_options);
|
99
|
+
virtual MathStructure parse(const string &eq, const ParseOptions &po = default_parse_options);
|
100
|
+
virtual int parse(MathStructure &mstruct, const string &eq, const ParseOptions &po = default_parse_options);
|
101
|
+
virtual MathStructure calculate(MathStructure &vargs, const EvaluationOptions &eo = default_evaluation_options);
|
102
|
+
/**
|
103
|
+
* The main function for subclasses to reimplement.
|
104
|
+
* Calculates a value from arguments in vargs and puts it in mstruct.
|
105
|
+
*
|
106
|
+
* This function expects the number of arguments to be equal to the maximum number of arguments, and checked by the argument definitions.
|
107
|
+
*
|
108
|
+
* If the return value is negative, then argument -(return value) has been evaluated in mstruct.
|
109
|
+
* If -(return value) is greater than max arguments, then mstruct is a vector of evaluated argument values.
|
110
|
+
*
|
111
|
+
* @param[out] mstruct Structure that is set with the result of the calculation.
|
112
|
+
* @param vargs Arguments passed to the mathematical function.
|
113
|
+
* @param eo Evaluation options.
|
114
|
+
* @returns 1 if the calculation was successful.
|
115
|
+
*/
|
116
|
+
virtual int calculate(MathStructure &mstruct, const MathStructure &vargs, const EvaluationOptions &eo);
|
117
|
+
/** Returns the functions condition expression.
|
118
|
+
*
|
119
|
+
* @returns The function's condition expression
|
120
|
+
*/
|
121
|
+
string condition() const;
|
122
|
+
/** Print the function's condition expression with argument names.
|
123
|
+
*
|
124
|
+
* @returns The printed condition
|
125
|
+
*/
|
126
|
+
string printCondition();
|
127
|
+
/** Sets the functions condition expression.
|
128
|
+
*
|
129
|
+
* @param expression The function's new condition expression
|
130
|
+
*/
|
131
|
+
void setCondition(string expression);
|
132
|
+
/** Test if arguments fulfil the function's condition expression.
|
133
|
+
*
|
134
|
+
* @param vargs Vector with arguments.
|
135
|
+
* @returns true if the arguments fulfil the function's condition expression
|
136
|
+
*/
|
137
|
+
bool testCondition(const MathStructure &vargs);
|
138
|
+
/** Returns the maximum number of arguments that the function accepts or -1 if the number of arguments is unlimited.
|
139
|
+
*/
|
140
|
+
int args() const;
|
141
|
+
/** Returns the minimum number of arguments for the function.
|
142
|
+
*/
|
143
|
+
int minargs() const;
|
144
|
+
/** Returns the maximum number of arguments that the function accepts or -1 if the number of arguments is unlimited.
|
145
|
+
*/
|
146
|
+
int maxargs() const;
|
147
|
+
/** Parses arguments from a text string and places them in a vector. The text string should be a comma separated list of arguments.
|
148
|
+
*
|
149
|
+
* @param str The argument string to parse.
|
150
|
+
* @param vargs Vector to store parsed arguments in.
|
151
|
+
* @param po Parse options.
|
152
|
+
* @returns The number of parsed arguments.
|
153
|
+
*/
|
154
|
+
int args(const string &str, MathStructure &vargs, const ParseOptions &po = default_parse_options);
|
155
|
+
/** Returns the index of the last argument definition.
|
156
|
+
*
|
157
|
+
* @returns The index of the last argument definition
|
158
|
+
*/
|
159
|
+
size_t lastArgumentDefinitionIndex() const;
|
160
|
+
/** Returns the argument definition for an argument index.
|
161
|
+
*
|
162
|
+
* @param index Argument index.
|
163
|
+
* @returns The argument definition for the index or NULL if no the argument was not defined for the index
|
164
|
+
*/
|
165
|
+
Argument *getArgumentDefinition(size_t index);
|
166
|
+
/** Removes all argument definitions for the function.
|
167
|
+
*/
|
168
|
+
void clearArgumentDefinitions();
|
169
|
+
/** Set the argument definition for an argument index.
|
170
|
+
*
|
171
|
+
* @param index Argument index.
|
172
|
+
* @param argdef A newly allocated argument definition
|
173
|
+
*/
|
174
|
+
void setArgumentDefinition(size_t index, Argument *argdef);
|
175
|
+
int stringArgs(const string &str, vector<string> &svargs);
|
176
|
+
void setDefaultValue(size_t arg_, string value_);
|
177
|
+
const string &getDefaultValue(size_t arg_) const;
|
178
|
+
void appendDefaultValues(MathStructure &vargs);
|
179
|
+
MathStructure produceVector(const MathStructure &vargs, int begin = -1, int end = -1);
|
180
|
+
MathStructure produceArgumentsVector(const MathStructure &vargs, int begin = -1, int end = -1);
|
181
|
+
|
182
|
+
virtual bool representsPositive(const MathStructure&, bool = false) const;
|
183
|
+
virtual bool representsNegative(const MathStructure&, bool = false) const;
|
184
|
+
virtual bool representsNonNegative(const MathStructure&, bool = false) const;
|
185
|
+
virtual bool representsNonPositive(const MathStructure&, bool = false) const;
|
186
|
+
virtual bool representsInteger(const MathStructure&, bool = false) const;
|
187
|
+
virtual bool representsNumber(const MathStructure&, bool = false) const;
|
188
|
+
virtual bool representsRational(const MathStructure&, bool = false) const;
|
189
|
+
virtual bool representsReal(const MathStructure&, bool = false) const;
|
190
|
+
virtual bool representsComplex(const MathStructure&, bool = false) const;
|
191
|
+
virtual bool representsNonZero(const MathStructure&, bool = false) const;
|
192
|
+
virtual bool representsEven(const MathStructure&, bool = false) const;
|
193
|
+
virtual bool representsOdd(const MathStructure&, bool = false) const;
|
194
|
+
virtual bool representsUndefined(const MathStructure&) const;
|
195
|
+
virtual bool representsBoolean(const MathStructure&) const;
|
196
|
+
virtual bool representsNonMatrix(const MathStructure&) const;
|
197
|
+
|
198
|
+
};
|
199
|
+
|
200
|
+
/// A user defined mathematical function.
|
201
|
+
/**
|
202
|
+
* User functions are functions defined using expression strings, representing mathematical formulas.
|
203
|
+
*
|
204
|
+
* The expression/formula of a function is basically a normal expression with placeholders for arguments.
|
205
|
+
* 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.
|
206
|
+
* They are replaced by entered arguments when a function is calculated.
|
207
|
+
* The placeholders naturally also decide the number of arguments that a function requires.
|
208
|
+
* For example the function for triangle area ("base * height / 2") has the name triangle and the formula "(\x*\y)/2",
|
209
|
+
* which gives that "triangle(2, 3)" equals "(2*3) / 2" and returns "3" as result.
|
210
|
+
* An argument can be used more than one time and all arguments must not necessarily be in order in the formula.
|
211
|
+
*
|
212
|
+
* Additionally, optional arguments can be put in the formula with upper-case (X, Y, Z, ...) instead of lower-case letters (x, y, z, ...).
|
213
|
+
* The default value can be put in brackets after the letter (ex. "\X{2}").
|
214
|
+
* The default value may be omitted and is then zero. All additional arguments after an optional argument must also be optional.
|
215
|
+
*
|
216
|
+
* To simplify the formula and make it more efficient, subfunctions can be used.
|
217
|
+
* These works just like the main formula, using the arguments of it.
|
218
|
+
* Subfunctions are referenced in the formula using \index ('\2', '\2', '\3', ...).
|
219
|
+
* 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".
|
220
|
+
* Subfunctions must be added before the main formula is set.
|
221
|
+
*/
|
222
|
+
class UserFunction : public MathFunction {
|
223
|
+
protected:
|
224
|
+
|
225
|
+
string sformula, sformula_calc;
|
226
|
+
vector<string> v_subs;
|
227
|
+
vector<bool> v_precalculate;
|
228
|
+
|
229
|
+
public:
|
230
|
+
|
231
|
+
UserFunction(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);
|
232
|
+
UserFunction(const UserFunction *function);
|
233
|
+
void set(const ExpressionItem *item);
|
234
|
+
ExpressionItem *copy() const;
|
235
|
+
/** Returns the external representation of the formula. */
|
236
|
+
string formula() const;
|
237
|
+
/** Returns the internal representation of the formula. */
|
238
|
+
string internalFormula() const;
|
239
|
+
int calculate(MathStructure &mstruct, const MathStructure &vargs, const EvaluationOptions &eo);
|
240
|
+
/** Sets the formula of the mathematical function.
|
241
|
+
*
|
242
|
+
* @param new_formula Formula/expression.
|
243
|
+
* @param arc_ Minimum number of arguments or -1 to read from formula.
|
244
|
+
* @param max_argc_ Maximum number of arguments (ignored if argc_ < 0)
|
245
|
+
*/
|
246
|
+
void setFormula(string new_formula, int argc_ = -1, int max_argc_ = 0);
|
247
|
+
void addSubfunction(string subfunction, bool precalculate = true);
|
248
|
+
/** Sets the formula for a subfunction.
|
249
|
+
*
|
250
|
+
* @param index Index (starting at 1).
|
251
|
+
* @param subfunction Formula/expression.
|
252
|
+
*/
|
253
|
+
void setSubfunction(size_t index, string subfunction);
|
254
|
+
void delSubfunction(size_t index);
|
255
|
+
void clearSubfunctions();
|
256
|
+
size_t countSubfunctions() const;
|
257
|
+
void setSubfunctionPrecalculated(size_t index, bool precalculate);
|
258
|
+
const string &getSubfunction(size_t index) const;
|
259
|
+
bool subfunctionPrecalculated(size_t index) const;
|
260
|
+
int subtype() const;
|
261
|
+
};
|
262
|
+
|
263
|
+
/// A mathematical function argument definition with free value and base class for all argument definitions.
|
264
|
+
/** Free arguments accepts any value.
|
265
|
+
*/
|
266
|
+
class Argument {
|
267
|
+
|
268
|
+
protected:
|
269
|
+
|
270
|
+
string sname, scondition;
|
271
|
+
bool b_zero, b_test, b_matrix, b_text, b_error, b_rational;
|
272
|
+
/** This function is called from Argument::test() and performs validation specific to the argument definition type.
|
273
|
+
* Should be reimplemented by all subclasses.
|
274
|
+
*
|
275
|
+
* @param value Value to test.
|
276
|
+
* @param eo Evaluation options to use if the value needs to be evaluated.
|
277
|
+
* @returns true if the value is valid for the argument definition.
|
278
|
+
*/
|
279
|
+
virtual bool subtest(MathStructure &value, const EvaluationOptions &eo) const;
|
280
|
+
/** This function is called from Argument::printlong() and returns description specific the argument definition type.
|
281
|
+
* Should be reimplemented by all subclasses. For example IntegerArgument::subprintlong() might return "an integer"
|
282
|
+
* and Argument::printlong() might append " that fulfills the condition: even(\x)".
|
283
|
+
*
|
284
|
+
* @returns Long description.
|
285
|
+
*/
|
286
|
+
virtual string subprintlong() const;
|
287
|
+
|
288
|
+
public:
|
289
|
+
|
290
|
+
/** Creates a new argument definition.
|
291
|
+
*
|
292
|
+
* @param name Name/title of the argument definition.
|
293
|
+
* @param does_test If argument values will be tested.
|
294
|
+
* @param does_error If an error will issued if the value tests false.
|
295
|
+
*/
|
296
|
+
Argument(string name_ = "", bool does_test = true, bool does_error = true);
|
297
|
+
/** Creates a copy of an argument definition.
|
298
|
+
*
|
299
|
+
* @param arg Argument to copy.
|
300
|
+
*/
|
301
|
+
Argument(const Argument *arg);
|
302
|
+
/** Destructor */
|
303
|
+
virtual ~Argument();
|
304
|
+
|
305
|
+
/** Sets the argument to a copy of an argument definition.
|
306
|
+
*
|
307
|
+
* @param arg Argument to copy.
|
308
|
+
*/
|
309
|
+
virtual void set(const Argument *arg);
|
310
|
+
/** Returns a copy of the argument definition.
|
311
|
+
*
|
312
|
+
* @returns A copy.
|
313
|
+
*/
|
314
|
+
virtual Argument *copy() const;
|
315
|
+
|
316
|
+
/** Resturns a short description of the argument definition.
|
317
|
+
* Ex. "number" for NumberArgument.
|
318
|
+
*
|
319
|
+
* @returns Short description.
|
320
|
+
*/
|
321
|
+
virtual string print() const;
|
322
|
+
/** Resturns a long description of the argument definition.
|
323
|
+
* Ex. "A real number > 2".
|
324
|
+
*
|
325
|
+
* @returns Long description.
|
326
|
+
*/
|
327
|
+
string printlong() const;
|
328
|
+
|
329
|
+
/** Tests if a value fulfils the requirements of the argument definition.
|
330
|
+
* The value might change if it has not been fully evaluated.
|
331
|
+
*
|
332
|
+
* @param value Value to test.
|
333
|
+
* @param f Mathematical function that the value is an argument for.
|
334
|
+
* @param eo Evaluation options to use if the value needs to be evaluated.
|
335
|
+
* @returns true if the value is valid for the argument definition.
|
336
|
+
*/
|
337
|
+
bool test(MathStructure &value, int index, MathFunction *f, const EvaluationOptions &eo = default_evaluation_options) const;
|
338
|
+
/** Parses an expression for an argument value.
|
339
|
+
* The default behavior is to use Calculator::parse() directly.
|
340
|
+
*
|
341
|
+
* @param str Expression.
|
342
|
+
* @param po Parse options.
|
343
|
+
* @returns A new mathematical structure with the parsed expression.
|
344
|
+
*/
|
345
|
+
virtual MathStructure parse(const string &str, const ParseOptions &po = default_parse_options) const;
|
346
|
+
/** Parses an expression for an argument value.
|
347
|
+
* The default behavior is to use Calculator::parse() directly.
|
348
|
+
*
|
349
|
+
* @param mstruct Mathematical structure to set with the parsed expression.
|
350
|
+
* @param str Expression.
|
351
|
+
* @param po Parse options.
|
352
|
+
*/
|
353
|
+
virtual void parse(MathStructure *mstruct, const string &str, const ParseOptions &po = default_parse_options) const;
|
354
|
+
|
355
|
+
/** Returns the name/title of the argument definition.
|
356
|
+
*
|
357
|
+
* @returns Name/title.
|
358
|
+
*/
|
359
|
+
string name() const;
|
360
|
+
/** Sets the name/title of the argument definition.
|
361
|
+
*
|
362
|
+
* @param name_ New name/title.
|
363
|
+
*/
|
364
|
+
void setName(string name_);
|
365
|
+
|
366
|
+
/** Sets a custom condition for argument values.
|
367
|
+
* '\x' is replaced by the argument value in the expression.
|
368
|
+
*
|
369
|
+
* @param condition Condition expression.
|
370
|
+
*/
|
371
|
+
void setCustomCondition(string condition);
|
372
|
+
/** Returns the custom condition expression set for argument values.
|
373
|
+
*
|
374
|
+
* @returns Custom condition for argument values.
|
375
|
+
*/
|
376
|
+
string getCustomCondition() const;
|
377
|
+
|
378
|
+
/** If the value for the argument will be tested. If not, the argument only works as an suggestion and any value is allowed.
|
379
|
+
*
|
380
|
+
* @returns true if the argument value will be tested.
|
381
|
+
*/
|
382
|
+
bool tests() const;
|
383
|
+
void setTests(bool does_error);
|
384
|
+
|
385
|
+
/** If an error message will be presented to the user if the value for the argument is not allowed.
|
386
|
+
*
|
387
|
+
* @returns true if error messages will be shown.
|
388
|
+
*/
|
389
|
+
bool alerts() const;
|
390
|
+
void setAlerts(bool does_error);
|
391
|
+
|
392
|
+
/** If an argument value of zero is forbidden.
|
393
|
+
*
|
394
|
+
* @returns true if zero argument value is forbidden.
|
395
|
+
*/
|
396
|
+
bool zeroForbidden() const;
|
397
|
+
/** Sets if a value of zero is forbidden for the argument value.
|
398
|
+
*
|
399
|
+
* @param forbid_zero If zero shall be forbidden.
|
400
|
+
*/
|
401
|
+
void setZeroForbidden(bool forbid_zero);
|
402
|
+
|
403
|
+
bool matrixAllowed() const;
|
404
|
+
void setMatrixAllowed(bool allow_matrix);
|
405
|
+
|
406
|
+
/** If only rational polynomials are allowed as argument value.
|
407
|
+
*
|
408
|
+
* @see MathStructure::isRationalPolynomial()
|
409
|
+
* @returns true if only rational polynomials is allowed.
|
410
|
+
*/
|
411
|
+
bool rationalPolynomial() const;
|
412
|
+
void setRationalPolynomial(bool rational_polynomial);
|
413
|
+
|
414
|
+
virtual bool suggestsQuotes() const;
|
415
|
+
|
416
|
+
/** Returns the type of the argument, corresponding to which subclass the object belongs to.
|
417
|
+
*
|
418
|
+
* @returns ::ArgumentType.
|
419
|
+
*/
|
420
|
+
virtual int type() const;
|
421
|
+
|
422
|
+
};
|
423
|
+
|
424
|
+
/// A definition for numerical arguments.
|
425
|
+
/** These arguments allows numerical values. The value can be restricted to real or rational numbers (defaults to allow all numbers, including complex), and a max and/or min value.
|
426
|
+
*/
|
427
|
+
class NumberArgument : public Argument {
|
428
|
+
|
429
|
+
protected:
|
430
|
+
|
431
|
+
Number *fmin, *fmax;
|
432
|
+
bool b_incl_min, b_incl_max;
|
433
|
+
bool b_complex, b_rational_number;
|
434
|
+
|
435
|
+
protected:
|
436
|
+
|
437
|
+
virtual bool subtest(MathStructure &value, const EvaluationOptions &eo) const;
|
438
|
+
virtual string subprintlong() const;
|
439
|
+
|
440
|
+
public:
|
441
|
+
|
442
|
+
NumberArgument(string name_ = "", ArgumentMinMaxPreDefinition minmax = ARGUMENT_MIN_MAX_NONE, bool does_test = true, bool does_error = true);
|
443
|
+
NumberArgument(const NumberArgument *arg);
|
444
|
+
virtual ~NumberArgument();
|
445
|
+
|
446
|
+
virtual void set(const Argument *arg);
|
447
|
+
virtual Argument *copy() const;
|
448
|
+
|
449
|
+
virtual string print() const;
|
450
|
+
|
451
|
+
void setMin(const Number *nmin);
|
452
|
+
void setIncludeEqualsMin(bool include_equals);
|
453
|
+
bool includeEqualsMin() const;
|
454
|
+
const Number *min() const;
|
455
|
+
void setMax(const Number *nmax);
|
456
|
+
void setIncludeEqualsMax(bool include_equals);
|
457
|
+
bool includeEqualsMax() const;
|
458
|
+
const Number *max() const;
|
459
|
+
|
460
|
+
bool complexAllowed() const;
|
461
|
+
void setComplexAllowed(bool allow_complex);
|
462
|
+
bool rationalNumber() const;
|
463
|
+
void setRationalNumber(bool rational_number);
|
464
|
+
|
465
|
+
virtual int type() const;
|
466
|
+
|
467
|
+
};
|
468
|
+
|
469
|
+
/// A definition for integer arguments.
|
470
|
+
/** These arguments allows numerical integer values. The value can be restricted to a max and/or min value.
|
471
|
+
*/
|
472
|
+
class IntegerArgument : public Argument {
|
473
|
+
|
474
|
+
protected:
|
475
|
+
|
476
|
+
Number *imin, *imax;
|
477
|
+
|
478
|
+
protected:
|
479
|
+
|
480
|
+
virtual bool subtest(MathStructure &value, const EvaluationOptions &eo) const;
|
481
|
+
virtual string subprintlong() const;
|
482
|
+
|
483
|
+
public:
|
484
|
+
|
485
|
+
IntegerArgument(string name_ = "", ArgumentMinMaxPreDefinition minmax = ARGUMENT_MIN_MAX_NONE, bool does_test = true, bool does_error = true);
|
486
|
+
IntegerArgument(const IntegerArgument *arg);
|
487
|
+
virtual ~IntegerArgument();
|
488
|
+
|
489
|
+
virtual void set(const Argument *arg);
|
490
|
+
virtual Argument *copy() const;
|
491
|
+
|
492
|
+
virtual string print() const;
|
493
|
+
|
494
|
+
void setMin(const Number *nmin);
|
495
|
+
const Number *min() const;
|
496
|
+
void setMax(const Number *nmax);
|
497
|
+
const Number *max() const;
|
498
|
+
|
499
|
+
virtual int type() const;
|
500
|
+
|
501
|
+
};
|
502
|
+
|
503
|
+
/// A symbolic argument.
|
504
|
+
/** Accepts variables and symbolic structures.
|
505
|
+
*/
|
506
|
+
class SymbolicArgument : public Argument {
|
507
|
+
|
508
|
+
protected:
|
509
|
+
|
510
|
+
virtual bool subtest(MathStructure &value, const EvaluationOptions &eo) const;
|
511
|
+
virtual string subprintlong() const;
|
512
|
+
|
513
|
+
public:
|
514
|
+
|
515
|
+
SymbolicArgument(string name_ = "", bool does_test = true, bool does_error = true);
|
516
|
+
SymbolicArgument(const SymbolicArgument *arg);
|
517
|
+
virtual ~SymbolicArgument();
|
518
|
+
virtual int type() const;
|
519
|
+
virtual Argument *copy() const;
|
520
|
+
virtual string print() const;
|
521
|
+
};
|
522
|
+
|
523
|
+
/// A text argument.
|
524
|
+
/** Accepts text (symbolic) structures. Argument values are parsed as text, unless surrounded by back slashes (which are then removed). Surrounding Parentheses and first quotation marks are removed.
|
525
|
+
*/
|
526
|
+
class TextArgument : public Argument {
|
527
|
+
|
528
|
+
protected:
|
529
|
+
|
530
|
+
virtual bool subtest(MathStructure &value, const EvaluationOptions &eo) const;
|
531
|
+
virtual string subprintlong() const;
|
532
|
+
|
533
|
+
public:
|
534
|
+
|
535
|
+
TextArgument(string name_ = "", bool does_test = true, bool does_error = true);
|
536
|
+
TextArgument(const TextArgument *arg);
|
537
|
+
virtual ~TextArgument();
|
538
|
+
virtual int type() const;
|
539
|
+
virtual Argument *copy() const;
|
540
|
+
virtual string print() const;
|
541
|
+
virtual bool suggestsQuotes() const;
|
542
|
+
};
|
543
|
+
|
544
|
+
/// A date argument.
|
545
|
+
/** A text argument representing a date.
|
546
|
+
*/
|
547
|
+
class DateArgument : public Argument {
|
548
|
+
|
549
|
+
protected:
|
550
|
+
|
551
|
+
virtual bool subtest(MathStructure &value, const EvaluationOptions &eo) const;
|
552
|
+
virtual string subprintlong() const;
|
553
|
+
|
554
|
+
public:
|
555
|
+
|
556
|
+
DateArgument(string name_ = "", bool does_test = true, bool does_error = true);
|
557
|
+
DateArgument(const DateArgument *arg);
|
558
|
+
virtual ~DateArgument();
|
559
|
+
virtual int type() const;
|
560
|
+
virtual Argument *copy() const;
|
561
|
+
virtual string print() const;
|
562
|
+
};
|
563
|
+
|
564
|
+
/// A vector argument.
|
565
|
+
/**
|
566
|
+
*/
|
567
|
+
class VectorArgument : public Argument {
|
568
|
+
|
569
|
+
protected:
|
570
|
+
|
571
|
+
virtual bool subtest(MathStructure &value, const EvaluationOptions &eo) const;
|
572
|
+
virtual string subprintlong() const;
|
573
|
+
vector<Argument*> subargs;
|
574
|
+
bool b_argloop;
|
575
|
+
|
576
|
+
public:
|
577
|
+
|
578
|
+
VectorArgument(string name_ = "", bool does_test = true, bool allow_matrix = false, bool does_error = true);
|
579
|
+
VectorArgument(const VectorArgument *arg);
|
580
|
+
virtual ~VectorArgument();
|
581
|
+
virtual int type() const;
|
582
|
+
virtual Argument *copy() const;
|
583
|
+
virtual string print() const;
|
584
|
+
bool reoccuringArguments() const;
|
585
|
+
void setReoccuringArguments(bool reocc);
|
586
|
+
void addArgument(Argument *arg);
|
587
|
+
void delArgument(size_t index);
|
588
|
+
size_t countArguments() const;
|
589
|
+
Argument *getArgument(size_t index) const;
|
590
|
+
};
|
591
|
+
|
592
|
+
/// A matrix argument.
|
593
|
+
/**
|
594
|
+
*/
|
595
|
+
class MatrixArgument : public Argument {
|
596
|
+
|
597
|
+
protected:
|
598
|
+
|
599
|
+
virtual bool subtest(MathStructure &value, const EvaluationOptions &eo) const;
|
600
|
+
virtual string subprintlong() const;
|
601
|
+
bool b_square;
|
602
|
+
|
603
|
+
public:
|
604
|
+
|
605
|
+
MatrixArgument(string name_ = "", bool does_test = true, bool does_error = true);
|
606
|
+
MatrixArgument(const MatrixArgument *arg);
|
607
|
+
virtual bool squareDemanded() const;
|
608
|
+
virtual void setSquareDemanded(bool square);
|
609
|
+
virtual ~MatrixArgument();
|
610
|
+
virtual int type() const;
|
611
|
+
virtual Argument *copy() const;
|
612
|
+
virtual string print() const;
|
613
|
+
};
|
614
|
+
|
615
|
+
/// Argument for functions, variables and units.
|
616
|
+
/** Text string representing a function, variable or unit name.
|
617
|
+
*/
|
618
|
+
class ExpressionItemArgument : public Argument {
|
619
|
+
|
620
|
+
protected:
|
621
|
+
|
622
|
+
virtual bool subtest(MathStructure &value, const EvaluationOptions &eo) const;
|
623
|
+
virtual string subprintlong() const;
|
624
|
+
|
625
|
+
public:
|
626
|
+
|
627
|
+
ExpressionItemArgument(string name_ = "", bool does_test = true, bool does_error = true);
|
628
|
+
ExpressionItemArgument(const ExpressionItemArgument *arg);
|
629
|
+
virtual ~ExpressionItemArgument();
|
630
|
+
virtual int type() const;
|
631
|
+
virtual Argument *copy() const;
|
632
|
+
virtual string print() const;
|
633
|
+
};
|
634
|
+
/// A function argument.
|
635
|
+
/**
|
636
|
+
*/
|
637
|
+
class FunctionArgument : public Argument {
|
638
|
+
|
639
|
+
protected:
|
640
|
+
|
641
|
+
virtual bool subtest(MathStructure &value, const EvaluationOptions &eo) const;
|
642
|
+
virtual string subprintlong() const;
|
643
|
+
|
644
|
+
public:
|
645
|
+
|
646
|
+
FunctionArgument(string name_ = "", bool does_test = true, bool does_error = true);
|
647
|
+
FunctionArgument(const FunctionArgument *arg);
|
648
|
+
virtual ~FunctionArgument();
|
649
|
+
virtual int type() const;
|
650
|
+
virtual Argument *copy() const;
|
651
|
+
virtual string print() const;
|
652
|
+
};
|
653
|
+
|
654
|
+
/// A boolean argument.
|
655
|
+
/** Accepts zero or one.
|
656
|
+
*/
|
657
|
+
class BooleanArgument : public Argument {
|
658
|
+
|
659
|
+
protected:
|
660
|
+
|
661
|
+
virtual bool subtest(MathStructure &value, const EvaluationOptions &eo) const;
|
662
|
+
virtual string subprintlong() const;
|
663
|
+
|
664
|
+
public:
|
665
|
+
|
666
|
+
BooleanArgument(string name_ = "", bool does_test = true, bool does_error = true);
|
667
|
+
BooleanArgument(const BooleanArgument *arg);
|
668
|
+
virtual ~BooleanArgument();
|
669
|
+
virtual int type() const;
|
670
|
+
virtual Argument *copy() const;
|
671
|
+
virtual string print() const;
|
672
|
+
};
|
673
|
+
|
674
|
+
class UnitArgument : public Argument {
|
675
|
+
|
676
|
+
protected:
|
677
|
+
|
678
|
+
virtual bool subtest(MathStructure &value, const EvaluationOptions &eo) const;
|
679
|
+
virtual string subprintlong() const;
|
680
|
+
|
681
|
+
public:
|
682
|
+
|
683
|
+
UnitArgument(string name_ = "", bool does_test = true, bool does_error = true);
|
684
|
+
UnitArgument(const UnitArgument *arg);
|
685
|
+
virtual ~UnitArgument();
|
686
|
+
virtual int type() const;
|
687
|
+
virtual Argument *copy() const;
|
688
|
+
virtual string print() const;
|
689
|
+
};
|
690
|
+
class AngleArgument : public Argument {
|
691
|
+
|
692
|
+
protected:
|
693
|
+
|
694
|
+
virtual bool subtest(MathStructure &value, const EvaluationOptions &eo) const;
|
695
|
+
virtual string subprintlong() const;
|
696
|
+
|
697
|
+
public:
|
698
|
+
|
699
|
+
AngleArgument(string name_ = "", bool does_test = true, bool does_error = true);
|
700
|
+
AngleArgument(const AngleArgument *arg);
|
701
|
+
virtual ~AngleArgument();
|
702
|
+
virtual int type() const;
|
703
|
+
virtual Argument *copy() const;
|
704
|
+
virtual string print() const;
|
705
|
+
virtual void parse(MathStructure *mstruct, const string &str, const ParseOptions &po = default_parse_options) const;
|
706
|
+
};
|
707
|
+
class VariableArgument : public Argument {
|
708
|
+
|
709
|
+
protected:
|
710
|
+
|
711
|
+
virtual bool subtest(MathStructure &value, const EvaluationOptions &eo) const;
|
712
|
+
virtual string subprintlong() const;
|
713
|
+
|
714
|
+
public:
|
715
|
+
|
716
|
+
VariableArgument(string name_ = "", bool does_test = true, bool does_error = true);
|
717
|
+
VariableArgument(const VariableArgument *arg);
|
718
|
+
virtual ~VariableArgument();
|
719
|
+
virtual int type() const;
|
720
|
+
virtual Argument *copy() const;
|
721
|
+
virtual string print() const;
|
722
|
+
};
|
723
|
+
class FileArgument : public Argument {
|
724
|
+
|
725
|
+
protected:
|
726
|
+
|
727
|
+
virtual bool subtest(MathStructure &value, const EvaluationOptions &eo) const;
|
728
|
+
virtual string subprintlong() const;
|
729
|
+
|
730
|
+
public:
|
731
|
+
|
732
|
+
FileArgument(string name_ = "", bool does_test = true, bool does_error = true);
|
733
|
+
FileArgument(const FileArgument *arg);
|
734
|
+
virtual ~FileArgument();
|
735
|
+
virtual int type() const;
|
736
|
+
virtual Argument *copy() const;
|
737
|
+
virtual string print() const;
|
738
|
+
};
|
739
|
+
|
740
|
+
/// A set of accepted arguments.
|
741
|
+
/** This is used when several different type of argments shall be accepted by a function.
|
742
|
+
*/
|
743
|
+
class ArgumentSet : public Argument {
|
744
|
+
|
745
|
+
protected:
|
746
|
+
|
747
|
+
virtual bool subtest(MathStructure &value, const EvaluationOptions &eo) const;
|
748
|
+
virtual string subprintlong() const;
|
749
|
+
vector<Argument*> subargs;
|
750
|
+
|
751
|
+
public:
|
752
|
+
|
753
|
+
ArgumentSet(string name_ = "", bool does_test = true, bool does_error = true);
|
754
|
+
ArgumentSet(const ArgumentSet *arg);
|
755
|
+
virtual ~ArgumentSet();
|
756
|
+
virtual int type() const;
|
757
|
+
virtual Argument *copy() const;
|
758
|
+
virtual string print() const;
|
759
|
+
void addArgument(Argument *arg);
|
760
|
+
void delArgument(size_t index);
|
761
|
+
size_t countArguments() const;
|
762
|
+
Argument *getArgument(size_t index) const;
|
763
|
+
|
764
|
+
};
|
765
|
+
|
766
|
+
#endif
|