Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

ConstList.cpp

Go to the documentation of this file.
00001 #include "ConstList.h"
00002 #include "SimpleTokenizer.h"
00003 #include "TokenMatch.h"
00004 #include <iostream>
00005 
00006 ConstList::~ConstList() { clear(); }
00007 
00008 bool ConstList::parseTerm( AIDA_STD::string a_string , size_t term) {
00009   bool success = false;
00010   // Strip blanks off
00011   while (a_string.find_first_of(' ') != a_string.npos)
00012     a_string.replace (a_string.find_first_of(' '),1,"");
00013   SimpleTokenizer constTokener("=");
00014   AIDA_STD::vector <AIDA_STD::string> tokens = constTokener.tokenize(a_string);
00015   // The term should be XX=nn, so only two terms are expected
00016   if (tokens.size() == 2) {
00017     TokenMatch tokenParser0 (tokens[0]);
00018     TokenMatch tokenParser1 (tokens[1]);
00019     if ((tokenParser0.isId()) && tokenParser1.isNum()) {
00020       pair_names_os.push_back( tokens[0] );
00021       pair_values_os.push_back( tokens[1] );
00022       success = true;    
00023     }
00024   } else
00025     AIDA_STD::cerr << "Syntax error in term no.: "<< term << AIDA_STD::endl;
00026   return success;
00027 }
00028 
00029 bool ConstList::parse( AIDA_STD::string a_string ) {
00030   bool success = true; // Empty string is correct
00031 
00032   int howMany = 0;
00033   size_t tokCounter = 0;
00034   SimpleTokenizer constTokener(";");
00035   AIDA_STD::vector <AIDA_STD::string> tokens = constTokener.tokenize(a_string);
00036   // Clean up everything first:
00037   clear();
00038   // Example of a correct list: xx=2.4; y = 5; z= 9e4
00039   //
00040   while( success && tokCounter < tokens.size() ) {
00041     if (parseTerm(tokens[tokCounter],tokCounter))
00042       howMany++;
00043     else
00044       success = false;
00045     tokCounter++;
00046   }
00047 
00048   if( success ) {
00049     parsing_successful = true;
00050     pair_count = howMany; // New constants count.
00051   } else {
00052     clear();
00053   }
00054   return success;    
00055 }

Generated on Tue May 20 14:50:25 2003 for HepUtilities by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002