// Settings.h

#ifndef __SETTINGS_H__
#define __SETTINGS_H__

#include "general.H"
#include <stdio.h>

class Settings {
protected:
	int readMode;
public:
	Settings (void);
	virtual ~Settings (void);

	int Reading (void) { return (readMode); };
	virtual int Value (const char *name, int *value, int def = 0) = 0;
	virtual int Value (const char *name, double *value, double def = 0) = 0;
	virtual int Value (const char *name, char *value, int maxlen, const char *def = "") = 0;
	virtual int Value (const char *name, char **value, const char *def = "") = 0;
//	virtual int Value (const char *name, BOOL *value, BOOL *def = 0) = 0;
};




class ReadDefaultSettings : public Settings {
public:
	ReadDefaultSettings (void);
	virtual ~ReadDefaultSettings (void);
	virtual int Value (const char *name, int *value, int def = 0);
	virtual int Value (const char *name, double *value, double def = 0);
	virtual int Value (const char *name, char *value, int maxlen, const char *def = "");
	virtual int Value (const char *name, char **value, const char *def = "");
//	virtual int Value (const char *name, BOOL *value, BOOL *def = 0);
};

class WriteFileSettings : public Settings {
public:
	WriteFileSettings (const char *file, const char *thesection,
			 int *status);
	virtual ~WriteFileSettings (void);
	virtual int Value (const char *name, int *value, int def = 0);
	virtual int Value (const char *name, double *value, double def = 0);
	virtual int Value (const char *name, char *value, int maxlen, const char *def = "");
	virtual int Value (const char *name, char **value, const char *def = "");
//	virtual int Value (const char *name, BOOL *value, BOOL *def = 0);
private:
	FILE *output;
};

class ReadFileSettings : public ReadDefaultSettings {
public:
	ReadFileSettings (const char *file, const char *thesection,
			 int *status, int useDefaults = 1);
	virtual ~ReadFileSettings (void);
	virtual int Value (const char *name, int *value, int def = 0);
	virtual int Value (const char *name, double *value, double def = 0);
	virtual int Value (const char *name, char *value, int maxlen, const char *def = "");
	virtual int Value (const char *name, char **value, const char *def = "");
//	virtual int Value (const char *name, BOOL *value, BOOL *def = 0);
private:
	FILE *input;
	char inputbuffer [256];
	char *GetSetting (const char *name);
	int usingDefaults;
	long startOfSection;
};

#ifdef WINDOWS
class WriteRegistrySettings : public Settings {
public:
	WriteRegistrySettings (const char *hiearchy, const char *file,
				 int *status);
	virtual ~WriteRegistrySettings (void);
	virtual int Value (const char *name, int *value, int def = 0);
	virtual int Value (const char *name, double *value, double def = 0);
	virtual int Value (const char *name, char *value, int maxlen, const char *def = "");
/*	virtual int Value (const char *name, char **value, const char *def = ""); */
//	virtual int Value (const char *name, BOOL *value, BOOL *def = 0);
private:
	HKEY hKey;
};


class ReadRegistrySettings : public ReadFileSettings {
public:
	ReadRegistrySettings (const char *hiearchy, char *file, int *status, int useDefaults = 1);
	virtual ~ReadRegistrySettings (void);
	virtual int Value (const char *name, int *value, int def = 0);
	virtual int Value (const char *name, double *value, double def = 0);
	virtual int Value (const char *name, char *value, int maxlen, const char *def = "");
/*	virtual int Value (const char *name, char **value, const char *def = ""); */
//	virtual int Value (const char *name, BOOL *value, BOOL *def = 0);
private:
	HKEY hKey;
};
#endif

#endif
