Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Sep 11, 2010, 12:34:00 AM (15 years ago)
Author:
landauf
Message:

merged doc branch back to trunk

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/util/ExprParser.h

    r6417 r7401  
    2828
    2929/**
    30   @file
    31   @brief Declaration of FloatParser
     30@file
     31@ingroup Util
     32@brief Declaration of FloatParser
    3233*/
    3334
     
    4243namespace orxonox
    4344{
     45    /** Parser for expressions like \c "3 * cos(5 + 4) / a" where \a a is a predeclared
     46        variable.
     47    @par Usage
     48        Using it is rather simple:
     49        @code
     50        std::string str("3 + 4");
     51        ExprParser expr;
     52        expr.parse(str);
     53        if (expr.getSuccess())
     54        {
     55            if (!expr.getRemains().empty())
     56            {
     57                COUT(2) << "Warning: Expression could not be parsed to the end! Remains: '" << expr.getRemains() << '\'' << std::endl;
     58            }
     59            double result = expr.getResult();
     60        }
     61        else
     62            COUT(1) << "Error: Cannot calculate expression: Parse error." << std::endl;
     63        @endcode
     64        getRemains() returns the expression after what could be parsed. For instance
     65        \c "2*3 text" will return \c "text" as remains.
     66    @details
     67        The implementation of this class is really old and sort of a trial for
     68        a first C++ class by Reto. That explains why it looks more like C than
     69        C++... Also some of the variable names are in German. <br>
     70        Explaining how it works exactly is probably not possible anymore, but it
     71        is based on recursively parsing the expression character by character.
     72        That much I can remember.
     73    @par Functions, operators and variables supported
     74        - Variables:
     75            - e
     76            - pi
     77        - Functions:
     78            - sin, asin, sinh, asinh
     79            - cos, acos, cosh, acosh
     80            - tan, atan, tanh, atanh
     81            - int, floor, ceil, abs, sign
     82            - pow, sqrt, exp, ln, log
     83            - mod, div
     84            - min, max
     85            - radians, degrees
     86        - Operators:
     87            - +, -, ! (unary)
     88            - +, -, *, /, %, ^, |, &, !, <, >, !=, <=, >=, =
     89    @note
     90        Operators may not be very consistent with C++ rules, but using the class
     91        for plus and minus should be perfectly ok.
     92    */
    4493    class _UtilExport ExprParser
    4594    {
Note: See TracChangeset for help on using the changeset viewer.