#if !defined(__alffinif_h) // Sentry, use file only if it's not already included.
#define __alffinif_h
/*  Project Biblio-Tec

	 SUBSYSTEM:    TEC30r.dll Library (TecLib)
	 FILE:         alffinif.h
	 AUTHOR:       Alcindo Ferreira Filho

	 OVERVIEW:
	 ALFFIniFile Class definition and implementation. It defines
    an interface for handling INI Files and hides all S.O.,
    in this case Windows, functions and API.

    COPYRIGHT:    © 1998-2005
                  Alcindo Ferreira Filho
                  <alcindo@inttec.com.br>

    LICENSE:      Biblio-Tec license (BiblTec.txt)
*/
#include "teclall.h"

//{{ALFFInif}}
/*
 * ALFFInif Return Codes
 */
#define INIFILENOTFOUND  -10

/* ALFFInif Controls */

/////////////////////////////////////////////////////////////////////
// ALFFIniFile
// -----------
//
// * Simplified INI File wrapper for turning easy access to
// * INI Files on applications.
//
////////////////////////
class _TECLIBCLASS ALFFIniFile : public ALFFObject
{
 public:

	ALFFIniFile(const char* IniFileName);
	virtual ~ALFFIniFile();
   char far* GetClassName() {return "ALFFIniFile";}
	int GetString(const char* iniSection, const char* iniEntry,
					  const char* defaultString, char* returnBuffer,
					  int bufferSize);
	UINT GetInt  (const char* iniSection,
					  const char* iniEntry,
					  UINT defaultValue);

	long GetLong (const char* iniSection,
					  const char* iniEntry,
					  long defaultValue);

	bool WriteString(const char* iniSection,
						  const char* iniEntry,
						  const char* value);

	bool WriteInt(const char* iniSection,
					  const char* iniEntry,
					  int value);

	bool WriteLong(const char* iniSection,
						const char* iniEntry,
						long value);

 private:
	char* iniFileName;
};

/*
 * IniFile Class Implementation
 */
inline ALFFIniFile::ALFFIniFile(const char* IniFileName) : ALFFObject()
{
 iniFileName = new char[strlen(IniFileName)+1];
 strcpy(iniFileName,IniFileName);
}

inline ALFFIniFile::~ALFFIniFile()
{
 delete [] iniFileName;
}

inline int
ALFFIniFile::GetString(const char* iniSection, const char* iniEntry,
							  const char* defaultString, char* returnBuffer,
							  int bufferSize)
{
 return ::GetPrivateProfileString((LPCSTR)iniSection,
										  (LPCSTR) iniEntry,
										  (LPCSTR) defaultString,
										  (LPSTR)returnBuffer,
										   bufferSize,
										  (LPCSTR)iniFileName);
}

inline UINT
ALFFIniFile::GetInt(const char* iniSection,
					 const char* iniEntry,
					 UINT defaultValue)
{
 return ::GetPrivateProfileInt((LPCSTR)iniSection, (LPCSTR)iniEntry,(UINT)defaultValue,
									  (LPCSTR)iniFileName);
}

inline bool
ALFFIniFile::WriteString(const char* iniSection,
							const char* iniEntry,
							const char* value)
{
 return ::WritePrivateProfileString((LPCSTR)iniSection, (LPCSTR)iniEntry, (LPCSTR)value,
											 (LPCSTR)iniFileName);
}

inline bool
ALFFIniFile::WriteInt(const char* iniSection,
						const char* iniEntry,
						int value)
{
 char buffer[21];
 sprintf(buffer, "%d", value);
 return ::WritePrivateProfileString((LPCSTR)iniSection, (LPCSTR)iniEntry, (LPCSTR)buffer,
											 (LPCSTR)iniFileName);
}

inline long
ALFFIniFile::GetLong(const char* iniSection,
							const char* iniEntry,
							long defaultValue)
{
 char defaultString[36];
 sprintf(defaultString, "%lu", defaultValue);
 char returnBuffer[36];
 int rc = ::GetPrivateProfileString((LPCSTR)iniSection, (LPCSTR)iniEntry, (LPCSTR)defaultString,
											 (LPSTR)returnBuffer, 36,
											 (LPCSTR)iniFileName);
 if (rc)
	return (atol(returnBuffer));
 else return NULL;
}

inline bool
ALFFIniFile::WriteLong(const char* iniSection,
							  const char* iniEntry,
							  long value)
{
 char buffer[21];
 sprintf(buffer, "%lu", value);
 return ::WritePrivateProfileString((LPCSTR)iniSection, (LPCSTR)iniEntry, (LPCSTR)buffer,
											 (LPCSTR)iniFileName);
}

#endif



