modules::parser Namespace Reference

Namespaces

namespace  errors

Classes

struct  Constructor_t

Functions

int TokeniseByDelimiter (const std::string &input, std::vector< std::string > &output, const char *delim)
int TokeniseByWhiteSpace (const std::string &input, std::vector< std::string > &output)
std::string GetOneWord (const std::string &in, size_t start=0, size_t stop=std::string::npos)
Constructor_t ParseConstructor (const std::string &input, char open='(', char close=')') throw (modules::parser::errors::unmatched_parenthesis)
void ToCppValid (std::string &input)
const std::string & ToCppValid (const std::string &input)
void ReplaceAll (std::string &input, const std::string &search, const std::string &replace)
void ReplaceWords (std::string &input, const std::string &search, const std::string &replace)
const std::string & ReplaceAll (const std::string &input, const std::string &search, const std::string &replace)
size_t RemoveWhitespace (std::string &input)
size_t RemoveWhitespace (std::string &input, std::string::iterator start, std::string::iterator end)
void TrimWhiteSpaceBeforeAfter (std::string &input)
bool IsWhitespace (char in)
bool IsDigit (char in)
bool IsDecimal (char in)
bool IsFloatChar (char in)
bool IsNotFloatChar (char in)
bool IsNumber (const std::string &input)
int GetNumber (const std::string &input)
bool IsTrue (const std::string &input)
double GetDouble (const std::string &input, size_t start=0, size_t stop=std::string::npos)
bool iequals (const std::string &a, const std::string &b)
bool iequals (const char a, const char b)

Variables

const int max_line = 2048

Function Documentation

double modules::parser::GetDouble ( const std::string &  input,
size_t  start = 0,
size_t  stop = std::string::npos 
)

Definition at line 161 of file ModulesParser.cpp.

00161                                                                                 {
00162         TString tstr=input.substr(start,stop-start);
00163         double value=tstr.Atof();
00164         return value;
00165 }

int modules::parser::GetNumber ( const std::string &  input  ) 

Definition at line 155 of file ModulesParser.cpp.

Referenced by ExportPulse::ParseRequest().

00155                                                   {
00156         int val;
00157         sscanf ( input.c_str(), "%d", &val );
00158         return val;
00159 }

std::string modules::parser::GetOneWord ( const std::string &  in,
size_t  start = 0,
size_t  stop = std::string::npos 
)

Definition at line 33 of file ModulesParser.cpp.

Referenced by MakeAnalysedPulses::ParseGeneratorList().

00033                                                                                  {
00034         std::stringstream ss(in.substr(start,stop-start));
00035         std::string word;
00036         ss>>word;
00037         return word;
00038 }

bool modules::parser::iequals ( const char  a,
const char  b 
)

Definition at line 167 of file ModulesParser.cpp.

00167                                                      {
00168     return ( a=='_' && b=='-' ) ||
00169            ( a=='-' && b=='_' ) ||
00170            ( tolower(a) == tolower(b));
00171 }

bool modules::parser::iequals ( const std::string &  a,
const std::string &  b 
)

Definition at line 173 of file ModulesParser.cpp.

Referenced by MakeAnalysedPulses::BeforeFirstEntry(), SetupNavigator::GetBank(), IDs::channel::GetDetectorEnum(), IDs::channel::GetSlowFastEnum(), and IDs::channel::operator=().

00173                                                                  {
00174   unsigned int sz = a.size();
00175   if (b.size() != sz) return false;
00176   for (unsigned int i = 0; i < sz; ++i){
00177       if (! iequals(a[i],b[i])) return false;
00178   }
00179   return true;
00180 }

bool modules::parser::IsDecimal ( char  in  ) 

Definition at line 139 of file ModulesParser.cpp.

Referenced by IsFloatChar().

00139                                     {
00140         return in=='.';
00141 }

bool modules::parser::IsDigit ( char  in  ) 

Definition at line 129 of file ModulesParser.cpp.

Referenced by IsFloatChar().

00129                                   {
00130         bool retval=false;
00131         switch(in){
00132                 case '0': case '1': case '2': case '3': case '4':
00133                 case '5': case '6': case '7': case '8': case '9':
00134                         retval=true;
00135         }
00136         return retval;
00137 }

bool modules::parser::IsFloatChar ( char  in  ) 

Definition at line 143 of file ModulesParser.cpp.

References IsDecimal(), and IsDigit().

Referenced by IsNotFloatChar().

00143                                       {
00144         return IsDecimal(in) || IsDigit(in);
00145 }

bool modules::parser::IsNotFloatChar ( char  in  ) 

Definition at line 147 of file ModulesParser.cpp.

References IsFloatChar().

Referenced by IsNumber().

00147                                          {
00148         return !IsFloatChar(in);
00149 }

bool modules::parser::IsNumber ( const std::string &  input  ) 

Definition at line 151 of file ModulesParser.cpp.

References IsNotFloatChar().

Referenced by ExportPulse::ParseRequest().

00151                                                   {
00152         return std::find_if(input.begin(),input.end(),IsNotFloatChar) == input.end();
00153 }

bool modules::parser::IsTrue ( const std::string &  input  ) 

Definition at line 182 of file ModulesParser.cpp.

Referenced by modules::options::GetBool().

00182                                               {
00183     return  (val=="true")|| (val=="TRUE")|| (val=="YES")|| (val=="yes")|| (val=="on")|| (val=="ON")|| (val=="1");
00184 }

bool modules::parser::IsWhitespace ( char  in  ) 

Definition at line 117 of file ModulesParser.cpp.

Referenced by RemoveWhitespace().

00117                                        {
00118         bool retval=false;
00119         switch(in){
00120                 case ' ': case '\t':
00121                         retval=true;
00122                         break;
00123                 default:
00124                         retval=false;
00125         }
00126         return retval;
00127 }

modules::parser::Constructor_t modules::parser::ParseConstructor ( const std::string &  input,
char  open = '(',
char  close = ')' 
) throw (modules::parser::errors::unmatched_parenthesis)

Definition at line 41 of file ModulesParser.cpp.

References modules::parser::Constructor_t::before, modules::parser::Constructor_t::inside, and TrimWhiteSpaceBeforeAfter().

Referenced by modules::reader::AddModule(), ExportPulse::BeforeFirstEntry(), modules::reader::findSectionName(), and MakeDetectorPulses::ParseGeneratorList().

00042                                                                {
00043     size_t end_br=std::string::npos;
00044     size_t start_br=input.find(open);
00045     Constructor_t retVal;
00046     // cut out the string before the first open character
00047     retVal.before=input.substr(0,start_br);
00048     // trim whitespace from the start and end of retVal.before string
00049     TrimWhiteSpaceBeforeAfter(retVal.before);
00050     // Look for the requested brackets
00051     if(start_br!=std::string::npos){
00052        end_br=input.rfind(close);
00053        if(end_br==std::string::npos){
00054                // No matching close, although there was an open
00055                throw modules::parser::errors::unmatched_parenthesis(open,close);
00056        }
00057        retVal.inside=input.substr(start_br+1,end_br-start_br-1);
00058        TrimWhiteSpaceBeforeAfter(retVal.inside);
00059     }
00060     return retVal;
00061 }

size_t modules::parser::RemoveWhitespace ( std::string &  input,
std::string::iterator  start,
std::string::iterator  end 
)

Definition at line 67 of file ModulesParser.cpp.

References IsWhitespace().

00067                                                                                                      {
00068         std::string::iterator new_end=std::remove_if(start,end,modules::parser::IsWhitespace);
00069         input.erase(new_end,end);
00070         return input.size();
00071 }

size_t modules::parser::RemoveWhitespace ( std::string &  input  ) 

Definition at line 63 of file ModulesParser.cpp.

Referenced by ExportPulse::ParseRequest(), and TrimWhiteSpaceBeforeAfter().

00063                                                       {
00064         return RemoveWhitespace(input, input.begin(),input.end());
00065 }

const std::string & modules::parser::ReplaceAll ( const std::string &  input,
const std::string &  search,
const std::string &  replace 
)

Definition at line 81 of file ModulesParser.cpp.

00081                                                                                                                    {
00082     static std::string output;
00083     output.clear();
00084     for(std::string::const_iterator i_char=input.begin(); i_char!=input.end();++i_char){
00085         if(std::find(search.begin(),search.end(), *i_char)!=search.end()){
00086             output+=replace;
00087         } else{
00088             output+=*i_char;
00089         }
00090     }
00091     return output;
00092 }

void modules::parser::ReplaceAll ( std::string &  input,
const std::string &  search,
const std::string &  replace 
)

Definition at line 94 of file ModulesParser.cpp.

Referenced by ToCppValid().

00094                                                                                                   {
00095     input=ReplaceAll(const_cast<const std::string&>(input),search,replace);
00096 }

void modules::parser::ReplaceWords ( std::string &  input,
const std::string &  search,
const std::string &  replace 
)

Definition at line 98 of file ModulesParser.cpp.

Referenced by modules::options::CheckValid(), and PulseViewer::ParseTriggerString().

00098                                                                                                    {
00099     size_t match_start;
00100     for( match_start=input.find(search);
00101          match_start!=std::string::npos;
00102          match_start=input.find(search)){
00103         input=input.substr(0,match_start) + replace + input.substr(match_start+search.length());
00104     }
00105 }

const std::string & modules::parser::ToCppValid ( const std::string &  input  ) 

Definition at line 73 of file ModulesParser.cpp.

References ReplaceAll().

00073                                                                 {
00074     return ReplaceAll(input," :{}#*()-=+$%^&!.,/?","_" );
00075 }

void modules::parser::ToCppValid ( std::string &  input  ) 
int modules::parser::TokeniseByDelimiter ( const std::string &  input,
std::vector< std::string > &  output,
const char *  delim 
)

Definition at line 21 of file ModulesParser.cpp.

References max_line.

Referenced by TemplateFactory< BaseModule, OptionsType >::addArguments(), modules::reader::AddModule(), and MakeDetectorPulses::ParseGeneratorList().

00021                                                                                                              {
00022     char line[modules::parser::max_line];
00023     strcpy(line,input.c_str());
00024     char* word = strtok(line,delim);
00025     while(word != NULL){ 
00026             //std::cout<<"ModulesOptions:GetVectorStringsByDelimiter() "<<word<<std::endl;
00027         output.push_back(word);
00028         word = strtok(NULL,delim);
00029     }
00030     return output.size();
00031 }

int modules::parser::TokeniseByWhiteSpace ( const std::string &  input,
std::vector< std::string > &  output 
)

Definition at line 14 of file ModulesParser.cpp.

Referenced by modules::reader::ProcessGlobalOption().

00014                                                                                            {
00015     std::stringstream ss(input);
00016     std::string val;
00017     while(ss>>val) output.push_back(val);
00018     return output.size();
00019 }

void modules::parser::TrimWhiteSpaceBeforeAfter ( std::string &  input  ) 

Definition at line 107 of file ModulesParser.cpp.

References RemoveWhitespace().

Referenced by modules::reader::AddModule(), modules::options::GetString(), and ParseConstructor().

00107                                                             {
00108         size_t not_white=line.find_first_not_of(" \t");
00109         if(not_white!=std::string::npos)
00110            RemoveWhitespace(line, line.begin(),line.begin()+not_white+1);
00111 
00112         not_white=line.find_last_not_of(" \t");
00113         if(not_white!=std::string::npos)
00114            RemoveWhitespace(line, line.begin()+not_white+1,line.end());
00115 }


Variable Documentation

const int modules::parser::max_line = 2048

Definition at line 41 of file ModulesParser.h.

Referenced by TokeniseByDelimiter().


Generated on 15 Jun 2016 for AlcapDAQ by  doxygen 1.6.1