Krita Source Code Documentation
Loading...
Searching...
No Matches
FormulaToken Class Reference

#include <EnhancedPathFormula.h>

Public Types

enum  Operator {
  OperatorInvalid , OperatorAdd , OperatorSub , OperatorMul ,
  OperatorDiv , OperatorLeftPar , OperatorRightPar , OperatorComma
}
 operator types More...
 
enum  Type {
  TypeUnknown = 0 , TypeNumber , TypeOperator , TypeReference ,
  TypeFunction
}
 token types More...
 

Public Member Functions

qreal asNumber () const
 Returns the token converted to qreal.
 
Operator asOperator () const
 Returns the token as operator.
 
 FormulaToken (const FormulaToken &token)
 copy constructor
 
 FormulaToken (Type type=TypeUnknown, const QString &text=QString(), int position=-1)
 Constructs token with given type, text and position.
 
bool isFunction () const
 Returns if token is a function.
 
bool isNumber () const
 Returns if the token is a number.
 
bool isOperator () const
 Returns if the token is a operator, OperatorInvalid if token is no operator.
 
bool isReference () const
 Returns if token is a reference.
 
FormulaTokenoperator= (const FormulaToken &token)
 assignment operator
 
int position () const
 Returns the position of the token.
 
QString text () const
 Returns the text representation of the token.
 
Type type () const
 Returns the type of the token.
 

Private Attributes

int m_position {-1}
 the tokens position
 
QString m_text
 the token text representation
 
Type m_type {TypeUnknown}
 the token type
 

Detailed Description

Definition at line 15 of file EnhancedPathFormula.h.

Member Enumeration Documentation

◆ Operator

operator types

Enumerator
OperatorInvalid 

invalid operator

OperatorAdd 
  • addition
OperatorSub 
  • subtraction
OperatorMul 
  • multiplication
OperatorDiv 

/ division

OperatorLeftPar 

(left parentheses

OperatorRightPar 

) right parentheses

OperatorComma 

, comma

Definition at line 28 of file EnhancedPathFormula.h.

◆ Type

token types

Enumerator
TypeUnknown 

unknown type

TypeNumber 

14, 3, 1977, 3.141592, 1e10, 5.9e-7

TypeOperator 

+, *, /, -

TypeReference 

function reference, modifier reference or named variable

TypeFunction 

function name

Definition at line 19 of file EnhancedPathFormula.h.

19 {
20 TypeUnknown = 0,
25 };
@ TypeReference
function reference, modifier reference or named variable
@ TypeOperator
+, *, /, -
@ TypeNumber
14, 3, 1977, 3.141592, 1e10, 5.9e-7
@ TypeUnknown
unknown type
@ TypeFunction
function name

Constructor & Destructor Documentation

◆ FormulaToken() [1/2]

FormulaToken::FormulaToken ( Type type = TypeUnknown,
const QString & text = QString(),
int position = -1 )
explicit

Constructs token with given type, text and position.

Definition at line 654 of file EnhancedPathFormula.cpp.

656{
657}
Type type() const
Returns the type of the token.
QString text() const
Returns the text representation of the token.
QString m_text
the token text representation
Type m_type
the token type
int position() const
Returns the position of the token.
int m_position
the tokens position

◆ FormulaToken() [2/2]

FormulaToken::FormulaToken ( const FormulaToken & token)

copy constructor

Definition at line 659 of file EnhancedPathFormula.cpp.

660{
661 if (this != &token) {
662 *this = token;
663 }
664}

Member Function Documentation

◆ asNumber()

qreal FormulaToken::asNumber ( ) const

Returns the token converted to qreal.

Definition at line 679 of file EnhancedPathFormula.cpp.

680{
681 if (isNumber()) {
682 return m_text.toDouble();
683 } else {
684 return 0.0;
685 }
686}
bool isNumber() const
Returns if the token is a number.

References isNumber(), and m_text.

◆ asOperator()

FormulaToken::Operator FormulaToken::asOperator ( ) const

Returns the token as operator.

Definition at line 688 of file EnhancedPathFormula.cpp.

689{
690 if (isOperator()) {
691 return matchOperator(m_text);
692 } else {
693 return OperatorInvalid;
694 }
695}
FormulaToken::Operator matchOperator(const QString &text)
bool isOperator() const
Returns if the token is a operator, OperatorInvalid if token is no operator.

References isOperator(), m_text, matchOperator(), and OperatorInvalid.

◆ isFunction()

bool FormulaToken::isFunction ( ) const
inline

Returns if token is a function.

Definition at line 75 of file EnhancedPathFormula.h.

76 {
77 return m_type == TypeFunction;
78 }

References m_type, and TypeFunction.

◆ isNumber()

bool FormulaToken::isNumber ( ) const
inline

Returns if the token is a number.

Definition at line 65 of file EnhancedPathFormula.h.

66 {
67 return m_type == TypeNumber;
68 }

References m_type, and TypeNumber.

◆ isOperator()

bool FormulaToken::isOperator ( ) const
inline

Returns if the token is a operator, OperatorInvalid if token is no operator.

Definition at line 70 of file EnhancedPathFormula.h.

71 {
72 return m_type == TypeOperator;
73 }

References m_type, and TypeOperator.

◆ isReference()

bool FormulaToken::isReference ( ) const
inline

Returns if token is a reference.

Definition at line 80 of file EnhancedPathFormula.h.

81 {
82 return m_type == TypeReference;
83 }

References m_type, and TypeReference.

◆ operator=()

FormulaToken & FormulaToken::operator= ( const FormulaToken & token)

assignment operator

Definition at line 666 of file EnhancedPathFormula.cpp.

667{
668 if (this == &rhs) {
669 return *this;
670 }
671
672 m_type = rhs.m_type;
673 m_text = rhs.m_text;
674 m_position = rhs.m_position;
675
676 return *this;
677}

References m_position, m_text, and m_type.

◆ position()

int FormulaToken::position ( ) const
inline

Returns the position of the token.

Definition at line 59 of file EnhancedPathFormula.h.

60 {
61 return m_position;
62 }

References m_position.

◆ text()

QString FormulaToken::text ( ) const
inline

Returns the text representation of the token.

Definition at line 54 of file EnhancedPathFormula.h.

55 {
56 return m_text;
57 }

References m_text.

◆ type()

Type FormulaToken::type ( ) const
inline

Returns the type of the token.

Definition at line 49 of file EnhancedPathFormula.h.

50 {
51 return m_type;
52 }

References m_type.

Member Data Documentation

◆ m_position

int FormulaToken::m_position {-1}
private

the tokens position

Definition at line 92 of file EnhancedPathFormula.h.

92{-1};

◆ m_text

QString FormulaToken::m_text
private

the token text representation

Definition at line 91 of file EnhancedPathFormula.h.

◆ m_type

Type FormulaToken::m_type {TypeUnknown}
private

the token type

Definition at line 90 of file EnhancedPathFormula.h.


The documentation for this class was generated from the following files: