//Editor-Info: -*- C++ -*-
//
//Subject: TOVE project / PF
//
//File: fileparser.h
//
//Version: $Revision: 1.4 $
//
//State: $State: Exp $
//
//Date: $Date: 1999/03/02 14:48:49 $
//
//Organisation:
//      Helsinki University of Technology
//      Laboratory of Telecommunications Software and Multimedia
//
//Author:
//      Timo Pärnänen
//
//Description:
//      Class to provide a parser functions for text file.
//      The text file can contain comment lines and lines containing
//      a variable with one or more values. User can iterate variables
//      and lines mapped with variable.
//
//Copyright:
//      Copyright 1999 Helsinki University of Technology
//      ALL RIGHTS RESERVED BETWEEN JANUARY 1996 AND JUNE 1999.
//
//Licence:
//
//
//History: 

#ifndef __PF_FILEPARSER_H__
#define __PF_FILEPARSER_H__

#include <typeinfo>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include "types.h"

//
//Class: pfFileParser
//

class pfFileParser
{
    public:
        pfFileParser(const string &fileName_);
        virtual ~pfFileParser(void);

        void parseFile(void);
        void setCommentCharacter(char commentCharacter_);

        // Iterate map
        void initMap(void);
        bool getNextVariable(string &variable_);

        // Iterate line
        bool initLine(string variable_);
        bool getNextValue(string &value_);

        // Special get methods
        bool getIntegerValue(string variable_, pfUlong &value_);
        bool getStringValue(string variable_, string &value_);

    private:
        typedef list<string> lineType;
        typedef lineType::iterator lineIteratorType;

        typedef map<string, lineType*, less<string> > mapType;
        typedef mapType::iterator mapIteratorType;

        string _fileName;
        ifstream _fileStream;
        char _commentCharacter;

        mapType _lineMap;

        mapIteratorType _current;
        mapIteratorType _end;
         
        lineIteratorType _currentValue;
        lineIteratorType _endLine;
        bool _initDone;
};

#endif // __PF_FILEPARSER_H__
