OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
import_export::ExpressionParser Class Reference

#include <ExpressionParser.h>

Classes

struct  ParserDeleter
 

Public Member Functions

 ExpressionParser ()
 
void setExpression (const std::string &expression)
 
void setStringConstant (const std::string &name, const std::string &value)
 
void setIntConstant (const std::string &name, const int value)
 
std::string evalAsString ()
 
int evalAsInt ()
 
double evalAsDouble ()
 
bool evalAsBool ()
 

Private Attributes

std::unique_ptr< mup::ParserX,
ParserDeleter
parser_
 

Detailed Description

Definition at line 34 of file ExpressionParser.h.

Constructor & Destructor Documentation

import_export::ExpressionParser::ExpressionParser ( )

Definition at line 357 of file ExpressionParser.cpp.

358  : parser_{new mup::ParserX(mup::pckCOMMON | mup::pckUNIT | mup::pckNON_COMPLEX |
359  mup::pckSTRING)} {
360  // custom operators and functions
361  parser_->DefineFun(new Function_substr());
362  parser_->DefineFun(new Function_regex_match());
363  parser_->DefineFun(new Function_split_part());
364  parser_->DefineFun(new Function_int());
365  parser_->DefineFun(new Function_float());
366  parser_->DefineFun(new Function_double());
367  parser_->DefineFun(new Function_str());
368  parser_->DefineFun(new Function_bool());
369  parser_->DefineInfixOprt(new Operator_not());
370 }
std::unique_ptr< mup::ParserX, ParserDeleter > parser_

Member Function Documentation

bool import_export::ExpressionParser::evalAsBool ( )

Definition at line 409 of file ExpressionParser.cpp.

References import_export::anonymous_namespace{ExpressionParser.cpp}::evaluate(), parser_, and run_benchmark_import::result.

409  {
410  auto result = evaluate(parser_.get());
411  if (result.GetType() != 'b') {
412  throw std::runtime_error("Expression is not a boolean");
413  }
414  return result.GetBool();
415 }
std::unique_ptr< mup::ParserX, ParserDeleter > parser_

+ Here is the call graph for this function:

double import_export::ExpressionParser::evalAsDouble ( )

Definition at line 401 of file ExpressionParser.cpp.

References import_export::anonymous_namespace{ExpressionParser.cpp}::evaluate(), parser_, and run_benchmark_import::result.

401  {
402  auto result = evaluate(parser_.get());
403  if (result.GetType() != 'f') {
404  throw std::runtime_error("Expression is not a float/double");
405  }
406  return static_cast<double>(result.GetFloat());
407 }
std::unique_ptr< mup::ParserX, ParserDeleter > parser_

+ Here is the call graph for this function:

int import_export::ExpressionParser::evalAsInt ( )

Definition at line 393 of file ExpressionParser.cpp.

References import_export::anonymous_namespace{ExpressionParser.cpp}::evaluate(), parser_, and run_benchmark_import::result.

393  {
394  auto result = evaluate(parser_.get());
395  if (result.GetType() != 'i') {
396  throw std::runtime_error("Expression is not an int");
397  }
398  return static_cast<int>(result.GetInteger());
399 }
std::unique_ptr< mup::ParserX, ParserDeleter > parser_

+ Here is the call graph for this function:

std::string import_export::ExpressionParser::evalAsString ( )

Definition at line 385 of file ExpressionParser.cpp.

References import_export::anonymous_namespace{ExpressionParser.cpp}::evaluate(), import_export::anonymous_namespace{ExpressionParser.cpp}::ms_to_ss(), parser_, and run_benchmark_import::result.

Referenced by import_export::parse_add_metadata_columns().

385  {
386  auto result = evaluate(parser_.get());
387  if (result.GetType() != 's') {
388  throw std::runtime_error("Expression is not a string");
389  }
390  return ms_to_ss(result.GetString());
391 }
std::unique_ptr< mup::ParserX, ParserDeleter > parser_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void import_export::ExpressionParser::setExpression ( const std::string &  expression)

Definition at line 381 of file ExpressionParser.cpp.

References parser_, and import_export::anonymous_namespace{ExpressionParser.cpp}::ss_to_ms().

Referenced by import_export::parse_add_metadata_columns().

381  {
382  parser_->SetExpr(ss_to_ms(expression));
383 }
std::unique_ptr< mup::ParserX, ParserDeleter > parser_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void import_export::ExpressionParser::setIntConstant ( const std::string &  name,
const int  value 
)

Definition at line 377 of file ExpressionParser.cpp.

References parser_, and import_export::anonymous_namespace{ExpressionParser.cpp}::ss_to_ms().

377  {
378  parser_->DefineConst(ss_to_ms(name), static_cast<mup::int_type>(value));
379 }
std::unique_ptr< mup::ParserX, ParserDeleter > parser_
string name
Definition: setup.in.py:72

+ Here is the call graph for this function:

void import_export::ExpressionParser::setStringConstant ( const std::string &  name,
const std::string &  value 
)

Definition at line 372 of file ExpressionParser.cpp.

References parser_, and import_export::anonymous_namespace{ExpressionParser.cpp}::ss_to_ms().

Referenced by import_export::parse_add_metadata_columns().

373  {
374  parser_->DefineConst(ss_to_ms(name), ss_to_ms(value));
375 }
std::unique_ptr< mup::ParserX, ParserDeleter > parser_
string name
Definition: setup.in.py:72

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

std::unique_ptr<mup::ParserX, ParserDeleter> import_export::ExpressionParser::parser_
private

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