<commit_before>/*=========================================================================

  Program:   ORFEO Toolbox
  Language:  C++
  Date:      $Date$
  Version:   $Revision$


  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
  See OTBCopyright.txt for details.


     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#include "otbMath.h"
#include "otbMacro.h"
#include "otbParserX.h"
#include "otbParserXPlugins.h"

namespace otb
{

class ITK_EXPORT ParserXImpl : public itk::LightObject
{
public:
  /** Standard class typedefs. */
  typedef ParserXImpl                               Self;
  typedef itk::LightObject                         Superclass;
  typedef itk::SmartPointer<Self>                  Pointer;
  typedef itk::SmartPointer<const Self>            ConstPointer;

  /** New macro for creation of through a Smart Pointer */
  itkNewMacro(Self);

  /** Run-time type information (and related methods) */
  itkTypeMacro(ParserXImpl, itk::LightObject);

  /** Convenient type definitions */
  //typedef double                                   ValueType;     //chris
  //typedef mu::Parser::exception_type               ExceptionType; //chris
  typedef mup::Value                                ValueType;
  typedef mup::ParserError                          ExceptionType;

  /** Initialize user defined constants */
  virtual void InitConst()
  {
    
    m_MuParserX.DefineConst( "log2e",  CONST_LOG2E );
    m_MuParserX.DefineConst( "log10e", CONST_LOG10E );
    m_MuParserX.DefineConst( "ln2",    CONST_LN2 );
    m_MuParserX.DefineConst( "ln10",   CONST_LN10 );
    m_MuParserX.DefineConst( "euler",  CONST_EULER );

  }

  /** Initialize user defined functions */
  virtual void InitFun()
  {
    //m_MuParserX.DefineFun("ndvi", Self::NDVI); chris
    //m_MuParserX.DefineFun("NDVI", Self::NDVI); chris
    m_MuParserX.DefineFun(new ndvi);

#ifdef OTB_MUPARSER_HAS_CXX_LOGICAL_OPERATORS
    /* Starting with muParser 2.0.0, logical operators have been
       renamed to "&&" and "||", instead of "and" and "or".
       Reintroducing pre-2.0.0 operators, so formulas can be
       defined with "and" and "or" even after 2.0.0
     */
    //m_MuParser.DefineOprt("and", Self::AND); chris
    //m_MuParser.DefineOprt("or",  Self::OR); chris
#endif
  }

  /** Set the expression to be parsed */
  virtual void SetExpr(const std::string & Expression)
  {
    m_MuParserX.SetExpr(Expression);
  }

  /** Trigger the parsing */
  ValueType Eval()
  {
    //ParserX::ValueType result = 0.0;
    ValueType result = 0.0;
    try
      {
      result = m_MuParserX.Eval();
      }
    catch(ExceptionType &e)
      {
      ExceptionHandler(e);
      }
    return result;
  }


  /** Define a variable */
  void DefineVar(const std::string &sName, ValueType *fVar)
  {
    try
      {
      m_MuParserX.DefineVar(sName, mup::Variable(fVar));<commit_msg>otbParserX.cxx cleaned<commit_after>/*=========================================================================

  Program:   ORFEO Toolbox
  Language:  C++
  Date:      $Date$
  Version:   $Revision$


  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
  See OTBCopyright.txt for details.


     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#include "otbMath.h"
#include "otbMacro.h"
#include "otbParserX.h"
#include "otbParserXPlugins.h"

namespace otb
{

class ITK_EXPORT ParserXImpl : public itk::LightObject
{
public:
  /** Standard class typedefs. */
  typedef ParserXImpl                               Self;
  typedef itk::LightObject                         Superclass;
  typedef itk::SmartPointer<Self>                  Pointer;
  typedef itk::SmartPointer<const Self>            ConstPointer;

  /** New macro for creation of through a Smart Pointer */
  itkNewMacro(Self);

  /** Run-time type information (and related methods) */
  itkTypeMacro(ParserXImpl, itk::LightObject);

  /** Convenient type definitions */
  typedef mup::Value                                ValueType;
  typedef mup::ParserError                          ExceptionType;

  /** Initialize user defined constants */
  virtual void InitConst()
  {
    
    m_MuParserX.DefineConst( "log2e",  CONST_LOG2E );
    m_MuParserX.DefineConst( "log10e", CONST_LOG10E );
    m_MuParserX.DefineConst( "ln2",    CONST_LN2 );
    m_MuParserX.DefineConst( "ln10",   CONST_LN10 );
    m_MuParserX.DefineConst( "euler",  CONST_EULER );

  }

  /** Initialize user defined functions */
  virtual void InitFun()
  {
    m_MuParserX.DefineFun(new ndvi);

  }

  /** Set the expression to be parsed */
  virtual void SetExpr(const std::string & Expression)
  {
    m_MuParserX.SetExpr(Expression);
  }

  /** Trigger the parsing */
  ValueType Eval()
  {
    //ParserX::ValueType result = 0.0;
    ValueType result = 0.0;
    try
      {
      result = m_MuParserX.Eval();
      }
    catch(ExceptionType &e)
      {
      ExceptionHandler(e);
      }
    return result;
  }


  /** Define a variable */
  void DefineVar(const std::string &sName, ValueType *fVar)
  {
    try
      {
      m_MuParserX.DefineVar(sName, mup::Variable(fVar));
{'fraction_non_alphanumeric': 0.15213889386074816, 'fraction_numerical': 0.007338464292106676, 'mean_word_length': 2.780784844384303, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4707757', 'n_tokens_mistral': 1762, 'n_tokens_neox': 1644, 'n_words': 422}