//Editor-Info: -*- C++ -*-
//
//Subject: TOVE project / TESTING
//
//File: testfileparser.cpp
//
//Version: $Revision: 1.1 $
//
//State: $State: Exp $
//
//Date: $Date: 1999/02/17 15:20:15 $
//
//Organisation:
//      Helsinki University of Technology
//      Laboratory of Telecommunications Software and Multimedia
//
//Author:
//      Timo Pärnänen
//
//Description:
//      Test/example file for using pfFileParser class.
//
//Copyright:
//      Copyright 1999 Helsinki University of Technology
//      ALL RIGHTS RESERVED BETWEEN JANUARY 1996 AND JUNE 1999.
//
//Licence:
//
//
//History: 

#include "pf/fileparser.h"
#include "pf/exception.h"
#include "pf/debug.h"

void printValues(pfFileParser &file_, string &varName_)
{
    string value;
    cout << varName_ << " : ";
    
    // Iterate values founded in line
    for (file_.initLine(varName_); file_.getNextValue(value);)
    {
        cout << value << " ";
    }
    cout << endl;
    return;
}

int main(void)
{
    debugOutputCout();

    string fileName("test.cfg");

    // Create parser and set comment line character
    pfFileParser file(fileName);
    file.setCommentCharacter('#');

    try
    {
        // Parse file
        file.parseFile();

        string varName;

        // Iterate founded variables
        for (file.initMap(); file.getNextVariable(varName);)
        {
            // Print values founded in each line (mapped with variable)
            printValues(file, varName);
        }
    }
    catch (pfException &exception)
    {
        cout << "File parsing failed or Values not found" << endl;
    }
    return 0;
}
