/*
//½d¨Ò
//¨ú°Ñ¼Æ¥Î argc , argv

void main( int argc, char *argv[] )
{
	// Instance of Arguments...
	// The last parameter sets the possible option markers. It is not necessary to 
	// to use it in this case because "-/" is the default value of this paremeter...
	
	Arguments cArg( "argtest", "(C) 2001 NOVACOM GmbH", "-/" );
	{
		// Add option "-h" with explanation...
		cArg.AddOption('h', "display usage help");
		
		// Add option "-2" with a non optional parameter...
		{
			Arguments::Option	cOpt( '2', "define additional input file" );
			cOpt.AddArgument( "outfile2", "additional input filename" );
			cArg.AddOption( cOpt );
		}
		
		// Add option "-w" with optional parameter "workingdir"
		// (default="./")...
		{
			Arguments::Option	cOpt( 'w', "" );
			cOpt.AddArgument( "workingdir", "working directoy", "./" );
			cArg.AddOption( cOpt );
		}
		
		// add non optionl argument "infile"...
		cArg.AddArgument( "infile", "filename to read" );
		
		// add optional argument "outfile" (default="stdout")...
		cArg.AddArgument( "outfile", "filename for output", "stdout" );
		
		// Argumente parsen...
		if( !cArg.Parse( argc, argv ) )
			exit(-1);
	}
	
	// request option "h" and print out manual if set...
	if( cArg['h'] )
	{
		cArg.Usage();
		exit(0);
	}
	
	// request argument of option "-2"...
	if( cArg['2'] )
		cout << "Option -2 set, outfile2 = " << cArg['2']["outfile2"] << endl;
	else
		cout << "Option -2 not set" << endl;
	
	// Request argument of option "-w"...
	if( cArg['w'] )
		cout << "Option -w set, workingdir = " << cArg['w']["workingdir"] << endl;
	else
		cout << "Option -w no set, workingdir = " << cArg['w']["workingdir"] 
		<< endl;
	
	// request argument "infile"...
	cout << "infile = " << cArg["infile"] << endl;
	
	// request argument "outfile"...
	cout << "outfile = " << cArg["outfile"] << endl;
}
*/

// Arguments.h: interface for the Arguments class.
//
// (C) 2001 NOVACOM GmbH, Berlin, www.novacom.net
// Author: Patrick Hoffmann, 03/21/2001
//
//////////////////////////////////////////////////////////////////////

#pragma warning (disable : 4786) 

#if !defined(AFX_ARGUMENTS_H__1F0E328D_C72D_4709_8A74_7654888217A6__INCLUDED_)
#define AFX_ARGUMENTS_H__1F0E328D_C72D_4709_8A74_7654888217A6__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <string>
#include <vector>
#include <map>

using namespace std;

#ifndef TCHAR
typedef char TCHAR;
#define _T(a) a
typedef string tstring;
#else
typedef basic_string<TCHAR> tstring;
#endif

inline ostream &operator<<(ostream& ostr, tstring& tstr )
{
	ostr << tstr.c_str();
	return ostr;
}

class Arguments  
{
	tstring	m_strOptionmarkers;
	tstring	m_strDescription;
	tstring	m_strCommandName;

public:
	static tstring	UnknownArgument;

	class Option;

	class Argument
	{
		friend class Arguments;
		friend class Option;
		
		tstring	m_strName;
		tstring	m_strDescription;
		tstring	m_strValue;
		tstring	m_strDefault;
		bool	m_bOptional;

	public:
		Argument( tstring strName, tstring strDescription=_T(""), tstring strDefault=_T("") );
	};

	typedef vector<Argument>	ArgVector;

	class Option
	{
		friend class Arguments;
		static Option	Empty;
		
		TCHAR			m_chName;
		ArgVector		m_vArguments;
		tstring			m_strDescription;
		bool			m_bSet;
		
	public:
		Option( TCHAR chName, tstring strDescription=_T("") );
		bool AddArgument( tstring strName, tstring strDescription=_T(""), tstring strDefault = _T("") );
		tstring &operator[]( int n );
		tstring &operator[]( tstring strArgumentName );
		tstring &operator[]( const TCHAR *pszArgumentName );
		operator bool();
		void Set( bool bSet = true );
		tstring GetName();
	};

private:
	typedef map<TCHAR,Option,less<TCHAR>,allocator<Option> > OptionMap;
	
	OptionMap			m_mOptions;
	ArgVector			m_vArguments;

public:
	bool IsOption( TCHAR chOptionName );
	bool Usage();
	bool AddOption( TCHAR chOptionName, tstring strDescription=_T("") );
	bool AddOption( Option &option );
	bool AddArgument( tstring strName, tstring strDescription=_T(""), tstring strDefault = _T("") );
	bool Parse(int argc, TCHAR* argv[]);
	bool Parse(TCHAR *pszCommandLine);
	bool Parse();
	
	tstring &operator[]( int n );
	tstring &operator[]( tstring strArgumentName );
	Option &operator[]( TCHAR chOptionName );
	
	Arguments( tstring strCommandName, tstring strDescription=_T(""), tstring strOptionmarkers=_T("-/") );
	virtual ~Arguments();
};

#pragma warning (disable : 4786) 

#endif // !defined(AFX_ARGUMENTS_H__1F0E328D_C72D_4709_8A74_7654888217A6__INCLUDED_)
