Universita' di GenovaINFN Sezione di Genova  
AIRWATCH / EUSO Genova

FileParser - source file

// $Id: FileParser.cc,v 1.1 2005/05/19 15:23:57 thea Exp $
// Author: Alessandro Thea   2005/05/17

/*****************************************************************************
 * ESAF: Euso Simulation and Analysis Framework                              *
 *                                                                           *
 *  Id: FileParser                                                           *
 *  Package: <packagename>                                                   *
 *  Coordinator: <coordinator>                                               *
 *                                                                           *
 *****************************************************************************/

//_____________________________________________________________________________
//
// FileParser
//
// <extensive class description>
//
//   Config file parameters
//   ======================
//
//   <parameter name>: <parameter description>
//   -Valid options: <available options>
//

#include "FileParser.hh"
#include "utils.hh"
#include <iostream>

ClassImp(FileParser)

//_____________________________________________________________________________
 FileParser::FileParser( const string& path ) : fPath(path) {
    //
    // Constructor
    //

    fComments.push_back("#");

    fDelimiters = "t ";

}

//_____________________________________________________________________________
 FileParser::~FileParser() {
    //
    // Destructor
    //
}


//______________________________________________________________________________
 Bool_t FileParser::ParseLine( string line ) {

    size_t pos;

    // erase comments

    list<string>::iterator it = fComments.begin();
    while( it != fComments.end() ) {
        Msg(EsafMsg::Info) << ''' << *it << ''' << MsgDispatch;
        pos = line.find(*it);
        if ( pos!=string::npos ) line.erase(pos);
        it++;
    } 
        
    string value;
    list<string> ls;
    line = SwallowSpaces(line);

    while(!line.empty()){
        pos = line.find_first_of(fDelimiters); 
        value = line.substr(0, pos);
        if ( pos == string::npos )
            line.erase();
        else
            line.erase(0,pos+1);
        line = SwallowSpaces(line);
        value = RSwallowSpaces(value);
        ls.push_back(value);
    }
    fWords.push_back(ls);

    return kTRUE;
}

//______________________________________________________________________________
 void FileParser::Dump() const {

    list< list<string> >::const_iterator iRow;
    list<string>::const_iterator iCol;

    for( iRow = fWords.begin(); iRow != fWords.end(); iRow++) {
        for ( iCol = iRow->begin(); iCol != iRow->end(); iCol++ )
            Msg(EsafMsg::Info) << "'" << *iCol << "' " << MsgFlush;
        Msg(EsafMsg::Info) << MsgDispatch;
    } 
}
About Us | EUSO Official Website | Web pages created by Roberto Pesce and Alessandro Thea - Last Update Wed Nov 16 16:57:39 2005 Wed Nov 16 16:29:22 2005