Xmipp  v3.23.11-Nereus
Public Member Functions | Public Attributes | List of all members
ArgumentDef Class Reference

#include <argsparser.h>

Inheritance diagram for ArgumentDef:
Inheritance graph
[legend]
Collaboration diagram for ArgumentDef:
Collaboration graph
[legend]

Public Member Functions

 ArgumentDef (ArgLexer *lexer, ASTNode *parent)
 
 ~ArgumentDef ()
 
virtual bool parse ()
 
virtual void check (std::stringstream &errors)
 
bool acceptArguments (std::stringstream &errors, size_t &argIndex, std::vector< const char *> &cmdArguments)
 This function will take an index and check if there are enougth arguments. More...
 
- Public Member Functions inherited from ASTNode
 ASTNode (ArgLexer *lexer=NULL, ASTNode *parent=NULL)
 
virtual ~ASTNode ()
 
virtual bool consume (ArgTokenType type)
 
ArgTokenType lookahead () const
 
bool lookahead (ArgTokenType type) const
 
ArgTokencurrentToken () const
 
void nextToken ()
 
bool parseCommentList (CommentList &comments)
 
void error (String msg)
 
void unexpectedToken (String msg="")
 

Public Attributes

String argDefault
 
bool isList
 
bool isType
 
std::vector< ParamDef * > subParams
 
bool hasDefault
 
- Public Attributes inherited from ASTNode
ASTNodeparent
 
ArgLexerpLexer
 
ArgToken token
 
String name
 
int visible
 

Detailed Description

Definition at line 169 of file argsparser.h.

Constructor & Destructor Documentation

◆ ArgumentDef()

ArgumentDef::ArgumentDef ( ArgLexer lexer,
ASTNode parent 
)

Definition at line 421 of file argsparser.cpp.

421  :
422  ASTNode(lexer, parent)
423 {
424  isList = false;
425  hasDefault = false;
426 }
bool hasDefault
Definition: argsparser.h:176
ASTNode(ArgLexer *lexer=NULL, ASTNode *parent=NULL)
Definition: argsparser.cpp:349

◆ ~ArgumentDef()

ArgumentDef::~ArgumentDef ( )

Definition at line 428 of file argsparser.cpp.

429 {
430  for (size_t i = 0; i < subParams.size(); ++i)
431  delete subParams[i];
432 }
#define i
std::vector< ParamDef * > subParams
Definition: argsparser.h:175

Member Function Documentation

◆ acceptArguments()

bool ArgumentDef::acceptArguments ( std::stringstream &  errors,
size_t &  argIndex,
std::vector< const char *> &  cmdArguments 
)

This function will take an index and check if there are enougth arguments.

Definition at line 469 of file argsparser.cpp.

470 {
472  if (index == cmdArguments.size())
473  {
474  if (hasDefault)
475  {
476  cmdArguments.push_back(argDefault.c_str());
477  }
478  else
479  {
480  errors << "Not enough arguments, <" << name << "> has not default. ";
481  return false;
482  }
483  }
484 
485  if (isList)
486  return true;
487 
488  if (!subParams.empty())
489  {
490  bool found = false;
491  String optionValue = (String)cmdArguments[index];
492  for (size_t i = 0; i < subParams.size(); ++i)
493  {
494  if (subParams[i]->name == optionValue)
495  {
496  found = true;
497  ++index;
498 
499  if (!subParams[i]->checkRequires(errors, prog))
500  return false;
501 
502  for (size_t j = 0; j < subParams[i]->arguments.size(); ++j)
503  if (!subParams[i]->arguments[j]->acceptArguments(errors, index, cmdArguments))
504  return false;
505  break;
506  }
507  }
508  if (!found)
509  {
510  errors << optionValue << " is not a valid option for <" << name <<"> ";
511  return false;
512  }
513  return true;//not increment index when found subparams, already incremented
514  }
515 
516  //if not list increment index
517  ++index;
518 
519  return true;
520 }
String name
Definition: argsparser.h:152
bool acceptArguments(std::stringstream &errors, size_t &argIndex, std::vector< const char *> &cmdArguments)
This function will take an index and check if there are enougth arguments.
Definition: argsparser.cpp:469
ASTNode * parent
Definition: argsparser.h:147
bool hasDefault
Definition: argsparser.h:176
#define i
ProgTransformDimRed * prog
if(fabs(c[*nmax+ *nmax *c_dim1])==0.e0)
viol index
std::vector< ParamDef * > subParams
Definition: argsparser.h:175
#define j
String argDefault
Definition: argsparser.h:172
std::string String
Definition: xmipp_strings.h:34

◆ check()

virtual void ArgumentDef::check ( std::stringstream &  errors)
inlinevirtual

Implements ASTNode.

Definition at line 181 of file argsparser.h.

182  {
183  }

◆ parse()

bool ArgumentDef::parse ( )
virtual

Implements ASTNode.

Definition at line 434 of file argsparser.cpp.

435 {
436  // A -> < ID DEF > | <...>
437  // DEF -> = VALUE | e
438  // VALUE -> INT | FLOAT | STRING
439  consume(TOK_LAN);
440  if (lookahead(TOK_ID))
441  {
442  consume(TOK_ID);
443  name = token.lexeme;
444  if (lookahead(TOK_EQ))
445  {
446  consume(TOK_EQ);
447  //Consume a value, that can be int, float or string
448  ArgTokenType t = lookahead();
449 
450  if (t == TOK_INT || t == TOK_FLOAT || t == TOK_STR || t == TOK_ID)
451  consume(t);
452  else
453  unexpectedToken(" expecting INT, FLOAT, STRING or ID.");
454 
455  hasDefault = true;
457  }
458  }
459  else
460  {
461  consume(TOK_ETC);
462  name = token.lexeme;
463  isList = true;
464  }
465  consume(TOK_RAN);
466  return true;
467 }
virtual bool consume(ArgTokenType type)
Definition: argsparser.cpp:376
String name
Definition: argsparser.h:152
bool hasDefault
Definition: argsparser.h:176
ArgTokenType
Definition: argsparser.h:43
String argDefault
Definition: argsparser.h:172
ArgToken token
Definition: argsparser.h:151
void unexpectedToken(String msg="")
Definition: argsparser.cpp:413
String lexeme
the string literal value of the token
Definition: argsparser.h:76
ArgTokenType lookahead() const
Definition: argsparser.cpp:356

Member Data Documentation

◆ argDefault

String ArgumentDef::argDefault

Definition at line 172 of file argsparser.h.

◆ hasDefault

bool ArgumentDef::hasDefault

Definition at line 176 of file argsparser.h.

◆ isList

bool ArgumentDef::isList

Definition at line 173 of file argsparser.h.

◆ isType

bool ArgumentDef::isType

Definition at line 174 of file argsparser.h.

◆ subParams

std::vector<ParamDef*> ArgumentDef::subParams

Definition at line 175 of file argsparser.h.


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