Mixed Data Coincidence Analysis Software 1.0
A program to analyze files produced by the EventMixer software.
Public Member Functions | Private Attributes
CommandLineInterpreter Class Reference

Interprets command line arguments according to a list of CommandLineArguments (acceptable flags), and throws an exception if unknown flags are encountered. More...

#include <CommandLineInterpreter.hh>

List of all members.

Public Member Functions

 CommandLineInterpreter (int argc, char *argv[], list< CommandLineArgument > myAcceptableFlags)
 Constructor.

Exceptions:
CommandLineExceptionif the CommandLineArguments does not match argv and argc (if there are unknown flags).

vector< string > readFlaggedCommand (string flag)
 Returns a vector<string> containing all arguments for a specific flag. Returns an empty vector if there are no arguments for this flag.
vector< string > readFlaglessCommands ()
 Returns all arguments without flags.

Private Attributes

map< string, vector< string > > myFlaggedCommands
 The current flagged commands.
vector< string > myFlaglessCommands
 The current flagless commands.

Detailed Description

Interprets command line arguments according to a list of CommandLineArguments (acceptable flags), and throws an exception if unknown flags are encountered.

Author:
Rikard Lundmark

Definition at line 42 of file CommandLineInterpreter.hh.


Constructor & Destructor Documentation

CommandLineInterpreter::CommandLineInterpreter ( int  argc,
char *  argv[],
list< CommandLineArgument myAcceptableFlags 
)

Constructor.

Exceptions:
CommandLineExceptionif the CommandLineArguments does not match argv and argc (if there are unknown flags).

Parameters:
argcThe number of command line arguments.
argvThe actual arguments.
myAcceptableFlagsThe flags which should be accepted by this interpreter.

Definition at line 3 of file CommandLineInterpreter.cc.

References myFlaggedCommands, and myFlaglessCommands.

{
  for(int i = 0; i<argc; i++)
    {
      string temp(argv[i]);
      if(temp[0]=='-') //we have a flag...
        {
          temp = temp.substr(1,temp.size());
          bool found = false;
          for(list<CommandLineArgument>::iterator it = myAcceptableFlags.begin(); it!=myAcceptableFlags.end(); it++)
            {
              if(temp.compare(it->flag)==0)
                {
                  if(i+it->numberOfArguments>argc)
                    throw CommandLineException("Insufficient arguments for flag.\n");
                  vector<string> myList;
                  for(int k = i+1; k<=i+it->numberOfArguments; k++)
                    {
                      string tmp(argv[k]);
                      myList.push_back(tmp);
                    }
                  myFlaggedCommands[temp] = myList;
                  i+=it->numberOfArguments;
                  found=true;
                }
            }
          if(!found)
            throw CommandLineException("Command flag not recognized");    
        }
      else
        {
          myFlaglessCommands.push_back(argv[i]);
        }
    }
}

Member Function Documentation

vector< string > CommandLineInterpreter::readFlaggedCommand ( string  flag)

Returns a vector<string> containing all arguments for a specific flag. Returns an empty vector if there are no arguments for this flag.

Parameters:
flagThe flag to read

Definition at line 39 of file CommandLineInterpreter.cc.

References myFlaggedCommands.

Referenced by decodeInput(), and initSettings().

{
  if(myFlaggedCommands.find(flag)!=myFlaggedCommands.end())
    {
      if(myFlaggedCommands[flag].empty())
        myFlaggedCommands[flag].push_back("");
      return myFlaggedCommands[flag];
    }
  else
    {
      return vector<string>();
    }
}

The documentation for this class was generated from the following files:
 All Classes Files Functions Variables Defines

Back to the main page of the Precalibrated Ion Beam Identification Detector project

Created by Rikard Lundmark