All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines
Public Member Functions | Static Public Attributes | Protected Member Functions
QGpCoreTools::ExpressionOperator Class Reference

#include <ExpressionAction.h>

Inheritance diagram for QGpCoreTools::ExpressionOperator:
QGpCoreTools::ExpressionAction QGpCoreTools::XMLClass

List of all members.

Public Member Functions

virtual bool addArgument (ExpressionAction *a)
 ExpressionOperator (Type type)
virtual int priority () const
virtual void replaceArgument (ExpressionAction *oldA, ExpressionAction *newA)
virtual QVariant value () const
virtual const QString & xml_tagName () const
virtual ~ExpressionOperator ()

Static Public Attributes

static const QString xmlExpressionOperatorTag = "ExpressionOperator"

Protected Member Functions

virtual void xml_writeChildren (XML_WRITECHILDREN_ARGS) const
virtual void xml_writeProperties (XML_WRITEPROPERTIES_ARGS) const

Constructor & Destructor Documentation

{_type=type;_operand1=0;_operand2=0;}
{delete _operand1; delete _operand2;}

Member Function Documentation

If all arguments are already set, the new argument is set as the second and the old second one is set as the argument of the new argument. This mechanism is designed for cases where an operator with a higher priority is encountered during parse.

Implements QGpCoreTools::ExpressionAction.

References QGpCoreTools::ExpressionAction::addArgument(), QGpCoreTools::ExpressionAction::parent(), QGpCoreTools::ExpressionAction::priority(), priority(), QGpCoreTools::ExpressionAction::replaceArgument(), QGpCoreTools::ExpressionAction::setParent(), and TRACE.

{
  TRACE;
  if(!_operand1) {
    a->setParent(this);
    _operand1=a;
  } else if(!_operand2) {
    a->setParent(this);
    _operand2=a;
  } else {
    if(a->priority()<_operand2->priority()) {
      if(a->priority()==priority()) {
        parent()->replaceArgument(this, a);
        if(!a->addArgument(this)) return false;
      } else {
        if(a->addArgument(_operand2)) {
          a->setParent(this);
          _operand2=a;
        } else return false;
      }
    } else return false;
  }
  return true;
}
virtual int QGpCoreTools::ExpressionOperator::priority ( ) const [inline, virtual]

Reimplemented from QGpCoreTools::ExpressionAction.

Referenced by addArgument().

                               {
    switch (_type) {
    case Mult:
    case FloatDiv:
    case IntMod:
    case IntDiv:
      return 3;
    case Sum:
    case Subtract:
      return 2;
    default:
      return 1;
    }
  }

Implements QGpCoreTools::ExpressionAction.

References QGpCoreTools::ExpressionAction::setParent(), and TRACE.

{
  TRACE;
  newA->setParent(this);
  if(oldA==_operand1) {
    _operand1=newA;
  } else if(oldA==_operand2) {
    _operand2=newA;
  } else {
    ASSERT(_operand1==oldA || _operand2==oldA);
  }
}
QVariant QGpCoreTools::ExpressionOperator::value ( ) const [virtual]

Implements QGpCoreTools::ExpressionAction.

References QGpCoreTools::ExpressionAction::Assign, QGpCoreTools::ExpressionAction::compare(), QGpCoreTools::ExpressionAction::Equal, QGpCoreTools::ExpressionAction::FloatDiv, QGpCoreTools::ExpressionAction::floatDiv(), QGpCoreTools::ExpressionAction::FloatDivAssign, QGpCoreTools::ExpressionAction::GreaterOrEqual, QGpCoreTools::ExpressionAction::GreaterThan, QGpCoreTools::ExpressionAction::IntDiv, QGpCoreTools::ExpressionAction::IntMod, QGpCoreTools::ExpressionAction::isReadOnly(), QGpCoreTools::ExpressionAction::LessOrEqual, QGpCoreTools::ExpressionAction::LessThan, QGpCoreTools::ExpressionAction::Mult, QGpCoreTools::ExpressionAction::mult(), QGpCoreTools::ExpressionAction::MultAssign, QGpCoreTools::ExpressionAction::NotEqual, QGpCoreTools::ExpressionAction::setValue(), QGpCoreTools::ExpressionAction::Subtract, QGpCoreTools::ExpressionAction::subtract(), QGpCoreTools::ExpressionAction::SubtractAssign, QGpCoreTools::ExpressionAction::Sum, QGpCoreTools::ExpressionAction::sum(), QGpCoreTools::ExpressionAction::SumAssign, TRACE, and QGpCoreTools::ExpressionAction::value().

{
  TRACE;
  if(!_operand1 || !_operand2) return QVariant();
  QVariant op1Val=_operand1->value();
  QVariant op2Val=_operand2->value();
  switch(_type) {
  case Assign:
    if(!_operand1->isReadOnly()) {
      _operand1->setValue(op2Val);
      return op2Val;
    }
    break;
  case SumAssign:
    if(!_operand1->isReadOnly()) {
      QVariant res=sum(op1Val, op2Val);
      _operand1->setValue(res);
      return res;
    }
    break;
  case SubtractAssign:
    if(!_operand1->isReadOnly()) {
      QVariant res=subtract(op1Val, op2Val);
      _operand1->setValue(res);
      return res;
    }
    break;
  case MultAssign:
    if(!_operand1->isReadOnly()) {
      QVariant res=mult(op1Val, op2Val);
      _operand1->setValue(res);
      return res;
    }
    break;
  case FloatDivAssign:
    if(!_operand1->isReadOnly()) {
      QVariant res=floatDiv(op1Val, op2Val);
      _operand1->setValue(res);
      return res;
    }
    break;
  case Sum:
    return sum(op1Val, op2Val);
  case Subtract:
    return subtract(op1Val, op2Val);
  case Mult:
    return mult(op1Val, op2Val);
  case FloatDiv:
    return floatDiv(op1Val, op2Val);
  case IntDiv: {
      int v2=op2Val.toInt();
      if(v2!=0) return op1Val.toInt()/v2;
    }
    break;
  case IntMod: {
      int v2=op2Val.toInt();
      if(v2!=0) return op1Val.toInt()%v2;
    }
    break;
  case Equal: {
      bool ok;
      bool res=compare(op1Val,op2Val, ok)==0;
      if(ok) return res; else return QVariant();
    }
  case NotEqual: {
      bool ok;
      bool res=compare(op1Val,op2Val, ok)!=0;
      if(ok) return res; else return QVariant();
    }
  case LessThan: {
      bool ok;
      bool res=compare(op1Val,op2Val, ok)<0;
      if(ok) return res; else return QVariant();
    }
  case LessOrEqual: {
      bool ok;
      bool res=compare(op1Val,op2Val, ok)<=0;
      if(ok) return res; else return QVariant();
    }
  case GreaterThan: {
      bool ok;
      bool res=compare(op1Val,op2Val, ok)>0;
      if(ok) return res; else return QVariant();
    }
  case GreaterOrEqual: {
      bool ok;
      bool res=compare(op1Val,op2Val, ok)>=0;
      if(ok) return res; else return QVariant();
    }
  default:
    break;
  }
  return QVariant();
}
virtual const QString& QGpCoreTools::ExpressionOperator::xml_tagName ( ) const [inline, virtual]

Reimplemented from QGpCoreTools::XMLClass.

References TRACE, and QGpCoreTools::XMLClass::xml_save().

{
  TRACE;
  Q_UNUSED(context);
  if(_operand1) _operand1->xml_save(s, context);
  if(_operand2) _operand2->xml_save(s, context);
}

Reimplemented from QGpCoreTools::XMLClass.

References QGpCoreTools::ExpressionAction::Assign, QGpCoreTools::ExpressionAction::CloseBracket, QGpCoreTools::ExpressionAction::CloseSquareBracket, QGpCoreTools::ExpressionAction::Coma, QGpCoreTools::ExpressionAction::EndAction, QGpCoreTools::ExpressionAction::Equal, QGpCoreTools::ExpressionAction::FloatDiv, QGpCoreTools::ExpressionAction::FloatDivAssign, QGpCoreTools::ExpressionAction::Function, QGpCoreTools::ExpressionAction::GreaterOrEqual, QGpCoreTools::ExpressionAction::GreaterThan, QGpCoreTools::ExpressionAction::IntDiv, QGpCoreTools::ExpressionAction::IntMod, QGpCoreTools::ExpressionAction::LessOrEqual, QGpCoreTools::ExpressionAction::LessThan, QGpCoreTools::ExpressionAction::Mult, QGpCoreTools::ExpressionAction::MultAssign, QGpCoreTools::ExpressionAction::NoOperator, QGpCoreTools::ExpressionAction::NotEqual, QGpCoreTools::ExpressionAction::OpenBracket, QGpCoreTools::ExpressionAction::OpenSquareBracket, QGpCoreTools::ExpressionAction::Subtract, QGpCoreTools::ExpressionAction::SubtractAssign, QGpCoreTools::ExpressionAction::Sum, QGpCoreTools::ExpressionAction::SumAssign, TRACE, QGpCoreTools::ExpressionAction::VariableArray, and QGpCoreTools::XMLClass::writeProperty().

{
  TRACE;
  Q_UNUSED(context);
  switch (_type) {
  case Assign:
    writeProperty(s,  "type", "="); break;
  case SumAssign:
    writeProperty(s,  "type", "+="); break;
  case SubtractAssign:
    writeProperty(s,  "type", "-="); break;
  case MultAssign:
    writeProperty(s,  "type", "*="); break;
  case FloatDivAssign:
    writeProperty(s,  "type", "/="); break;
  case Sum:
    writeProperty(s,  "type", "+"); break;
  case Subtract:
    writeProperty(s,  "type", "-"); break;
  case Mult:
    writeProperty(s,  "type", "*"); break;
  case FloatDiv:
    writeProperty(s,  "type", "/"); break;
  case IntDiv:
    writeProperty(s,  "type", "DIV"); break;
  case IntMod:
    writeProperty(s,  "type", "MOD"); break;
  case Equal:
    writeProperty(s,  "type", "=="); break;
  case NotEqual:
    writeProperty(s,  "type", "!="); break;
  case LessThan:
    writeProperty(s,  "type", "<"); break;
  case LessOrEqual:
    writeProperty(s,  "type", "<="); break;
  case GreaterThan:
    writeProperty(s,  "type", ">"); break;
  case GreaterOrEqual:
    writeProperty(s,  "type", ">="); break;
  case Coma:
    writeProperty(s,  "type", ","); break;
  case OpenBracket:
    writeProperty(s,  "type", "("); break;
  case CloseBracket:
    writeProperty(s,  "type", ")"); break;
  case OpenSquareBracket:
    writeProperty(s,  "type", "["); break;
  case CloseSquareBracket:
    writeProperty(s,  "type", "]"); break;
  case Function:
    writeProperty(s,  "type", "function()"); break;
  case VariableArray:
    writeProperty(s,  "type", "array[]"); break;
  case EndAction:
    writeProperty(s,  "type", "END"); break;
  case NoOperator:
    writeProperty(s,  "type", "noOp"); break;
    break;
  }
}

Member Data Documentation

const QString QGpCoreTools::ExpressionOperator::xmlExpressionOperatorTag = "ExpressionOperator" [static]

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines