// configmgr.h: interface for the ConfigFile class.
// Compile options needed: /GX
//////////////////////////////////////////////////////////////////////

#ifndef CONFIGFILE_H
#define CONFIGFILE_H

#include "configitem.h"
#include "types.h"
#include <stdio.h>
#include <vector>

using namespace std ;

struct ConfigFileItem
{
	ConfigItemWrapper cfgitem;
	int pos;
	char *comment;
};

typedef vector<ConfigFileItem> CONFIGITEM;

inline 
bool operator== (const ConfigFileItem& bw1, const ConfigFileItem& w2) {
    return false;
}

inline 
bool operator< (const ConfigFileItem& bw1, const ConfigFileItem& w2) {
    return false;
}

class ConfigFile  
{
public:	
	
	// Constructor. <filename> is the file containing config items to parse, and
	// maintain. <filename> must have read and write permission.
	ConfigFile();

	// Destructor
	virtual ~ConfigFile();

	// Opens <filename>,if successful calls private method parse() 
	Status initialize(const char *filename);

	// Searches vector <_configItems> for a ConfigItem with <name>. Returns the
	// TRUE and the ConfigItem <item> if found, else returns FALSE.
	MBool searchForItem(const char * name, ConfigItemWrapper &item);	

	// Find the item with <item> name, and replace
	void replaceItem(const ConfigItemWrapper item);

	// Save configuration file to disk.  This will overwrite the existing
	// file with changed parameters.
	void write();

	// Print all the items contained in the config file to stdout
	void dump();

	// Creates a config item and adds it to the private config item list <_configItems>
	// <name> = name of item
	// <argv> = argument string to add to item
	// Returns FALSE if cannot create item, TRUE otherwise.
	MBool createCfgItem(const char *name, const char *argvs);

private:
	// Empty any existing config items from member vector _configItems.
	void emptyConfigItems();

	// Parses data from <stream> and store all string token pairs in vector configItems
	// Returns 0 on success
	 Status parse(FILE *stream);

	CONFIGITEM _configItems;
	char _file[80];
};

#endif
