Shinya Kitaoka 810553
#pragma once
Shinya Kitaoka 810553
Toshihiro Shimizu 890ddd
#ifndef TEXPRESSION_INCLUDED
Toshihiro Shimizu 890ddd
#define TEXPRESSION_INCLUDED
Toshihiro Shimizu 890ddd
Shinya Kitaoka 262a92
#include <memory></memory>
Shinya Kitaoka 262a92
Toshihiro Shimizu 890ddd
// TnzCore includes
Toshihiro Shimizu 890ddd
#include "tcommon.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#undef DVAPI
Toshihiro Shimizu 890ddd
#undef DVVAR
Toshihiro Shimizu 890ddd
#ifdef TNZBASE_EXPORTS
Toshihiro Shimizu 890ddd
#define DVAPI DV_EXPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_EXPORT_VAR
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#define DVAPI DV_IMPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_IMPORT_VAR
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//========================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//    Forward declaration
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class TUnit;
Toshihiro Shimizu 890ddd
class TDoubleParam;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace TSyntax {
Toshihiro Shimizu 890ddd
class Grammar;
Toshihiro Shimizu 890ddd
class CalculatorNodeVisitor;
Toshihiro Shimizu 890ddd
class Calculator;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//========================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//************************************************************************************
Toshihiro Shimizu 890ddd
//    TExpression  declaration
Toshihiro Shimizu 890ddd
//************************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//! This class manages a generic expression.
Toshihiro Shimizu 890ddd
/*!
Toshihiro Shimizu 890ddd
  An expression is a sequence of characthers and contains:
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  \li a \e CalcNode that is a basic element of the expression that must be
Shinya Kitaoka 120a6e
  evaluated;
Shinya Kitaoka 120a6e
  \li a \e Grammar that is a sequence of string patterns that define operations
Shinya Kitaoka 120a6e
  on nodes;
Shinya Kitaoka 120a6e
  \li a \e Builder that is a sequence or a tree of calcnodes and operations on
Shinya Kitaoka 120a6e
  that;
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
class DVAPI TExpression {
Shinya Kitaoka 120a6e
  class Imp;
Shinya Kitaoka 120a6e
  std::unique_ptr<imp> m_imp;</imp>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TExpression();
Shinya Kitaoka 120a6e
  ~TExpression();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TExpression(const TExpression &);
Shinya Kitaoka 120a6e
  TExpression &operator=(TExpression);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  //! Sets the expression's grammar - does \b not acquire ownership.
Shinya Kitaoka 120a6e
  void setGrammar(const TSyntax::Grammar *grammar);
Shinya Kitaoka 120a6e
  const TSyntax::Grammar *getGrammar() const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  /*!
Shinya Kitaoka 120a6e
Sets the expression's text - a mix of mathematical expressions
Shinya Kitaoka 120a6e
and grammar-recognized patterns that is able to calculate the
Shinya Kitaoka 120a6e
expression's value at a given frame.
Shinya Kitaoka 120a6e
*/
Shinya Kitaoka 120a6e
  void setText(std::string text);
Shinya Kitaoka 120a6e
  std::string getText() const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TSyntax::Calculator *getCalculator();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  /*!
Shinya Kitaoka 120a6e
          Returns whether the expression is valid according to actual
Shinya Kitaoka 120a6e
grammar syntax (i.e. it has at least one calculator node).
Shinya Kitaoka 120a6e
  */
Shinya Kitaoka 120a6e
  bool isValid();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  std::string getError() const;
Shinya Kitaoka 120a6e
  std::pair<int, int=""> getErrorPos() const;</int,>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void accept(TSyntax::CalculatorNodeVisitor &visitor);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void setOwnerParameter(TDoubleParam *param);
Shinya Kitaoka 120a6e
  TDoubleParam *getOwnerParameter() const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool isCycling() const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  // The expression is parsed lazily - ie when a getters attempts to
Shinya Kitaoka 120a6e
  // evaluate the expression and it was not yet parsed
Shinya Kitaoka 120a6e
  void parse();
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif