Universita' di GenovaINFN Sezione di Genova  
AIRWATCH / EUSO Genova

StringsFileParser - source file

// ESAF : Euso Simulation and Analysis Framework
// $Id: StringsFileParser.cc,v 1.3 2005/02/16 23:18:14 thea Exp $
// Daniel De Marco created Jan, 28 2002

#include "StringsFileParser.hh"
#include "utils.hh"

ClassImp(StringsFileParser)

//______________________________________________________________________________
 StringsFileParser::StringsFileParser(const string &fn): fFileName(fn), fZombie(0) {
    //
    // Constructor: open and parse the file
    //
    // open file
    ifstream in(fFileName.c_str());
    if(!in)  {
        Msg(EsafMsg::Warning) << "Cannot open "+fFileName << MsgDispatch;
        MakeZombie();
        return;
    }
    
    string dummy;
    Int_t ln(0);
    while(getline(in, dummy)) {
        size_t pos;
        ln++;
        // erase comments
        pos=dummy.find('#');
        if(pos!=string::npos) dummy.erase(pos);
        
        // swallow spaces
        dummy=swallow_spaces(dummy);

        // skip blank lines
        if(dummy.empty()) continue;
        
        // we expect something like that:
        // string string string "string with spaces" ...

        list<string> ls;
        while(!dummy.empty()) {
            // get value
            string value;
            pos=dummy.find('"');
            if(pos==0) {
                // string starts with "

                // erase first "
                dummy.erase(0, 1);
                pos=dummy.find('"');
                if(pos==string::npos) {
                    // " not closed
                    MsgForm(EsafMsg::Warning,"Quoted string not complete in 
                            file %s, at line %d",fFileName.c_str(),ln);

                    MakeZombie();
                    return;
                }
                    

                value=dummy.substr(0, pos);
                // erase used value
                dummy.erase(0, pos+1);
                dummy=swallow_spaces(dummy);
            } else {
                value=dummy.substr(0, dummy.find_first_of("t ""));
                // erase used value
                dummy.erase(0, dummy.find_first_of("t ""));
                dummy=swallow_spaces(dummy);
            }

            ls.push_back(value);
    
        } 
        fLines.push_back(ls);
    } 
}

//______________________________________________________________________________
 StringsFileParser::~StringsFileParser() {
    //
    // Destructor
    //
}
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