tahoma2d/toonz/sources/include/texpression.h

99 lines
2.3 KiB
C
Raw Normal View History

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