Commit 936da4f2 authored by Jesse Mapel's avatar Jesse Mapel
Browse files

Added logical and/or operators to isisminer's calculator and limit strategies. Fixes #4581.

git-svn-id: http://subversion.wr.usgs.gov/repos/prog/isis3/trunk@7389 41f8697f-d340-4b68-9986-7bafba869bb8
parent bb9e0e23
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -895,6 +895,18 @@ EndObject
        <TD>Bitwise or</TD>
        <TD>x | y</TD>
      </TR>
      <TR>
        <TD>6</TD>
        <TD>&amp;&amp;</TD>
        <TD>Logical and</TD>
        <TD>x &amp;&amp; y</TD>
      </TR>
      <TR>
        <TD>6</TD>
        <TD>||</TD>
        <TD>Logical or</TD>
        <TD>x || y</TD>
      </TR>
      <TR>
        <TD>6</TD>
        <TD>%</TD>
+8 −0
Original line number Diff line number Diff line
@@ -426,6 +426,14 @@ namespace Isis {
          output += " != ";
          i++;
        }
        else if(i < equation.size() - 1 && equation[i] == '|' && equation[i+1] == '|') {
          output += " || ";
          i++;
        }
        else if(i < equation.size() - 1 && equation[i] == '&' && equation[i+1] == '&') {
          output += " && ";
          i++;
        }
        // Take care of scientific notiation where the exponent is negative
        else if((i > 1) && equation[i] == '-' && equation[i-1].toLower() == 'e' && equation[i-2].isLetterOrNumber()) {
          output += equation[i].toLatin1();
+2 −0
Original line number Diff line number Diff line
@@ -55,6 +55,8 @@ namespace Isis {
   *                           ISIS programming standards
   *   @history 2017-01-09 Jesse Mapel - Modified to allow for "_" in variables.
   *                           Fixes #4581.
   *   @history 2017-01-09 Jesse Mapel - Added logical and, or operators.
   *                           Fixes #4581.
   */
  class InfixToPostfix {
    public:
+50 −0
Original line number Diff line number Diff line
@@ -400,6 +400,54 @@ namespace Isis {
  }


  /**
   * Pops the top two vectors off the current stack and performs a logical or
   * on each pair.
   * 
   * @throws IException::Unknown "Failed performing logical or operation, "
   *                             "input vectors are of differnet lengths."
   */
  void InlineCalculator::logicalOr() {
    QVector<double> inputA = Pop();
    QVector<double> inputB = Pop();
    QVector<double> results;
    if ( inputA.size() != inputB.size() ) {
      QString msg = "Failed performing logical or operation, "
                    "input vectors are of differnet lengths.";
      throw IException(IException::Unknown, msg, _FILEINFO_);
    }
    for (int i = 0; i < inputA.size(); i++) {
      results.push_back( inputA[i] || inputB[i] );
    }
    Push(results);
    return;
  }


  /**
   * Pops the top two vectors off the current stack and performs a logical and
   * on each pair.
   * 
   * @throws IException::Unknown "Failed performing logical and operation, "
   *                             "input vectors are of differnet lengths."
   */
  void InlineCalculator::logicalAnd() {
    QVector<double> inputA = Pop();
    QVector<double> inputB = Pop();
    QVector<double> results;
    if ( inputA.size() != inputB.size() ) {
      QString msg = "Failed performing logical and operation, "
                    "input vectors are of differnet lengths.";
      throw IException(IException::Unknown, msg, _FILEINFO_);
    }
    for (int i = 0; i < inputA.size(); i++) {
      results.push_back( inputA[i] && inputB[i] );
    }
    Push(results);
    return;
  }
 

  /**
   * Pushes the PI constant onto the current stack.
   */  
@@ -597,6 +645,8 @@ namespace Isis {
    addFunction(new InlineVoidFx("degs", &InlineCalculator::degrees, this));
    addFunction(new InlineVoidFx("rads", &InlineCalculator::radians, this));
    addFunction(new InlineVoidFx("e", &InlineCalculator::eConstant, this));
    addFunction(new InlineVoidFx("||", &InlineCalculator::logicalOr, this));
    addFunction(new InlineVoidFx("&&", &InlineCalculator::logicalAnd, this));
 
    // Add new functions available for inlining
  //  m_variablePoolList = defaultVariables();
+3 −0
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@ namespace Isis {
   *   @history 2015-03-24 Jeffrey Covington and Jeannie Backer - Improved documentation.
   *   @history 2016-02-21 Kristin Berry - Added unit test and minor coding standard updates.
   *                                       Fixes #2401.
   *   @history 2017-01-09 Jesse Mapel - Added logical and, or operators. Fixes #4581.
   */
  class InlineCalculator : public Calculator {
 
@@ -90,6 +91,8 @@ namespace Isis {
      void floatModulus();
      void radians();
      void degrees();
      void logicalOr();
      void logicalAnd();
      void pi();
      void eConstant();
 
Loading