/************************************************************************

ＩＮＩファイルをロードしてＭＡＰ化するクラス
セーブも可能。 


こんな感じで使います。

static void foo(void)
{
	char str[0x100];

	static uji::seq::IniLoader iniLoader;

	if( !iniLoader.Load( L"sdmc:/sdcard.ini" ) )
	{
		NN_LOG( "LOAD FAILED" );
	}

	strcpy( str, "" );
	iniLoader.Get( "TEST", str );
	NN_LOG( "VAL=%s\n", str );

}

static void bar(void)
{
	char str[0x100];

	static uji::seq::IniLoader iniLoader;

	if( !iniLoader.Load( L"rom:/ini/config.ini" ) )
	{
		NN_LOG( "LOAD FAILED" );
	}

	strcpy( str, "" );
	iniLoader.Get( "TEST", str );
	NN_LOG( "VAL=%s\n", str );


}


 *************************************************************************/

/* 多重インクルードの回避 */
#ifndef SYS_INIFILE_H_INCLUDED
#define SYS_INIFILE_H_INCLUDED

#include <stdio.h>
#include <string.h>
#include <vector>
#include <nn.h>
namespace uji{
namespace sys{


/************************************************************************
ＩＮＩファイル
************************************************************************/
class IniFile
{
public:
	class Element;

	IniFile(){}
	~IniFile(){}
	
	bool Load( const wchar_t *fileName );
	bool Save( const wchar_t *fileName );
	void Get( const char *key, char *value );
	int  GetInteger( const char *key );
	void Add( const char *key, const char *value );
	void Add( const char *key, int value );
	std::vector<IniFile::Element>::iterator Find( const char *key );


	void Clear( void )
	{
		m_IniVector.clear();
	}

private:
	std::vector<Element> m_IniVector;
};

/************************************************************************
ＶＥＣＴＯＲに格納するクラス
************************************************************************/
class IniFile::Element
{
public:
	Element()
	{
		strcpy( m_Key, "" );
		strcpy( m_Value, "" );
	}
	Element( const char *key, const char *value )
	{
		strncpy( m_Key, key, sizeof(m_Key) );
		strncpy( m_Value, value, sizeof(m_Value) );
	}
	~Element(){}

	static const int MAX_KEY_SIZE = 0x20;
	static const int MAX_VALUE_SIZE = 0x100;
	char m_Key[MAX_KEY_SIZE];		//検索キー
	char m_Value[MAX_VALUE_SIZE];	//値格納

};




} // namespace sys
} // namespace uji

/* 多重インクルードの回避 */
#endif
