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