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
Toshihiro Shimizu 890ddd
namespace TSyntax
Toshihiro Shimizu 890ddd
{
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
Toshihiro Shimizu 890ddd
  \li a \e CalcNode that is a basic element of the expression that must be evaluated;
Toshihiro Shimizu 890ddd
  \li a \e Grammar that is a sequence of string patterns that define operations on nodes;
Toshihiro Shimizu 890ddd
  \li a \e Builder that is a sequence or a tree of calcnodes and operations on that;
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
class DVAPI TExpression
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	class Imp;
Shinya Kitaoka 262a92
	std::unique_ptr<imp> m_imp;</imp>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	TExpression();
Toshihiro Shimizu 890ddd
	~TExpression();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TExpression(const TExpression &);
Toshihiro Shimizu 890ddd
	TExpression &operator=(TExpression);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//! Sets the expression's grammar - does \b not acquire ownership.
Toshihiro Shimizu 890ddd
	void setGrammar(const TSyntax::Grammar *grammar);
Toshihiro Shimizu 890ddd
	const TSyntax::Grammar *getGrammar() const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*!
Toshihiro Shimizu 890ddd
    Sets the expression's text - a mix of mathematical expressions
Toshihiro Shimizu 890ddd
    and grammar-recognized patterns that is able to calculate the
Toshihiro Shimizu 890ddd
    expression's value at a given frame.
Toshihiro Shimizu 890ddd
  */
Shinya Kitaoka 3bfa54
	void setText(std::string text);
Toshihiro Shimizu 890ddd
	std::string getText() const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TSyntax::Calculator *getCalculator();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*!
Toshihiro Shimizu 890ddd
		Returns whether the expression is valid according to actual
Toshihiro Shimizu 890ddd
      grammar syntax (i.e. it has at least one calculator node).
Toshihiro Shimizu 890ddd
	*/
Toshihiro Shimizu 890ddd
	bool isValid();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	std::string getError() const;
Toshihiro Shimizu 890ddd
	std::pair<int, int=""> getErrorPos() const;</int,>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void accept(TSyntax::CalculatorNodeVisitor &visitor);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setOwnerParameter(TDoubleParam *param);
Toshihiro Shimizu 890ddd
	TDoubleParam *getOwnerParameter() const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool isCycling() const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Toshihiro Shimizu 890ddd
	// The expression is parsed lazily - ie when a getters attempts to
Toshihiro Shimizu 890ddd
	// evaluate the expression and it was not yet parsed
Toshihiro Shimizu 890ddd
	void parse();
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif