/*Parses a simple line-oriented ASCII parameter file with format:
 <key>  =  <value> 
Whitespace and empty lines are ignored.  ! and # start comments anywhere.  
Strings may be quoted.

  Orion Sky Lawlor, olawlor@acm.org, 10/25/2001
*/
#ifndef __OSL_PARAMFILE_H
#define __OSL_PARAMFILE_H

#include <stdio.h>

class parameterFile {
	bool forWrite; //File opened for output
	FILE *f; //File to write, or NULL
	char buf[1024];//Temporary buffer to parse a line of the file
	char *cur; //Current location in character buffer
	void reset(void);//Start file over again
	bool nextLine(void);//Advance to the next nonempty line
	bool eatWhite(void); //Advance over white space
	bool isKey(const char *key);//True if current data matches key
	char *fieldParse(void);//Skips equal sign, returns unquoted field
	char *findKey(const char *key);//Return the data associated with the next occurence of key, or NULL
public:
	parameterFile(const char *paramFileName,bool forWrite);
	~parameterFile();
	bool operator() (const char *key,const char *desc,bool defaultValue);
	int operator() (const char *key,const char *desc,int defaultValue);
	double operator() (const char *key,const char *desc,double defaultValue);
	const char *operator() (const char *key,const char *desc,const char *defaultValue);
};

#endif
