Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * Copyright (c) 2002 Michael Niedermayer <michaelni@gmx.at>
  3.  *
  4.  * This file is part of FFmpeg.
  5.  *
  6.  * FFmpeg is free software; you can redistribute it and/or
  7.  * modify it under the terms of the GNU Lesser General Public
  8.  * License as published by the Free Software Foundation; either
  9.  * version 2.1 of the License, or (at your option) any later version.
  10.  *
  11.  * FFmpeg is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.  * Lesser General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU Lesser General Public
  17.  * License along with FFmpeg; if not, write to the Free Software
  18.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19.  */
  20.  
  21. /**
  22.  * @file
  23.  * simple arithmetic expression evaluator
  24.  */
  25.  
  26. #ifndef AVUTIL_EVAL_H
  27. #define AVUTIL_EVAL_H
  28.  
  29. #include "avutil.h"
  30.  
  31. typedef struct AVExpr AVExpr;
  32.  
  33. /**
  34.  * Parse and evaluate an expression.
  35.  * Note, this is significantly slower than av_expr_eval().
  36.  *
  37.  * @param res a pointer to a double where is put the result value of
  38.  * the expression, or NAN in case of error
  39.  * @param s expression as a zero terminated string, for example "1+2^3+5*5+sin(2/3)"
  40.  * @param const_names NULL terminated array of zero terminated strings of constant identifiers, for example {"PI", "E", 0}
  41.  * @param const_values a zero terminated array of values for the identifiers from const_names
  42.  * @param func1_names NULL terminated array of zero terminated strings of funcs1 identifiers
  43.  * @param funcs1 NULL terminated array of function pointers for functions which take 1 argument
  44.  * @param func2_names NULL terminated array of zero terminated strings of funcs2 identifiers
  45.  * @param funcs2 NULL terminated array of function pointers for functions which take 2 arguments
  46.  * @param opaque a pointer which will be passed to all functions from funcs1 and funcs2
  47.  * @param log_ctx parent logging context
  48.  * @return >= 0 in case of success, a negative value corresponding to an
  49.  * AVERROR code otherwise
  50.  */
  51. int av_expr_parse_and_eval(double *res, const char *s,
  52.                            const char * const *const_names, const double *const_values,
  53.                            const char * const *func1_names, double (* const *funcs1)(void *, double),
  54.                            const char * const *func2_names, double (* const *funcs2)(void *, double, double),
  55.                            void *opaque, int log_offset, void *log_ctx);
  56.  
  57. /**
  58.  * Parse an expression.
  59.  *
  60.  * @param expr a pointer where is put an AVExpr containing the parsed
  61.  * value in case of successful parsing, or NULL otherwise.
  62.  * The pointed to AVExpr must be freed with av_expr_free() by the user
  63.  * when it is not needed anymore.
  64.  * @param s expression as a zero terminated string, for example "1+2^3+5*5+sin(2/3)"
  65.  * @param const_names NULL terminated array of zero terminated strings of constant identifiers, for example {"PI", "E", 0}
  66.  * @param func1_names NULL terminated array of zero terminated strings of funcs1 identifiers
  67.  * @param funcs1 NULL terminated array of function pointers for functions which take 1 argument
  68.  * @param func2_names NULL terminated array of zero terminated strings of funcs2 identifiers
  69.  * @param funcs2 NULL terminated array of function pointers for functions which take 2 arguments
  70.  * @param log_ctx parent logging context
  71.  * @return >= 0 in case of success, a negative value corresponding to an
  72.  * AVERROR code otherwise
  73.  */
  74. int av_expr_parse(AVExpr **expr, const char *s,
  75.                   const char * const *const_names,
  76.                   const char * const *func1_names, double (* const *funcs1)(void *, double),
  77.                   const char * const *func2_names, double (* const *funcs2)(void *, double, double),
  78.                   int log_offset, void *log_ctx);
  79.  
  80. /**
  81.  * Evaluate a previously parsed expression.
  82.  *
  83.  * @param const_values a zero terminated array of values for the identifiers from av_expr_parse() const_names
  84.  * @param opaque a pointer which will be passed to all functions from funcs1 and funcs2
  85.  * @return the value of the expression
  86.  */
  87. double av_expr_eval(AVExpr *e, const double *const_values, void *opaque);
  88.  
  89. /**
  90.  * Free a parsed expression previously created with av_expr_parse().
  91.  */
  92. void av_expr_free(AVExpr *e);
  93.  
  94. /**
  95.  * Parse the string in numstr and return its value as a double. If
  96.  * the string is empty, contains only whitespaces, or does not contain
  97.  * an initial substring that has the expected syntax for a
  98.  * floating-point number, no conversion is performed. In this case,
  99.  * returns a value of zero and the value returned in tail is the value
  100.  * of numstr.
  101.  *
  102.  * @param numstr a string representing a number, may contain one of
  103.  * the International System number postfixes, for example 'K', 'M',
  104.  * 'G'. If 'i' is appended after the postfix, powers of 2 are used
  105.  * instead of powers of 10. The 'B' postfix multiplies the value for
  106.  * 8, and can be appended after another postfix or used alone. This
  107.  * allows using for example 'KB', 'MiB', 'G' and 'B' as postfix.
  108.  * @param tail if non-NULL puts here the pointer to the char next
  109.  * after the last parsed character
  110.  */
  111. double av_strtod(const char *numstr, char **tail);
  112.  
  113. #endif /* AVUTIL_EVAL_H */
  114.