summaryrefslogtreecommitdiff
path: root/src/optparser.h
blob: 39f048d32eab0a9c766eb1e0ef5269eac89544e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#ifndef BU_OPT_PARSER_H
#define BU_OPT_PARSER_H

#include "bu/fstring.h"
#include "bu/list.h"
#include "bu/hash.h"

namespace Bu
{
	class OptParser
	{
	public:
		class Option
		{
		public:
			Option();
			virtual ~Option();

			char cOpt;
			Bu::FString sOpt;
			Bu::FString sDesc;
		};

	public:
		OptParser();
		virtual ~OptParser();

		void parse( int argc, char *argv[] );

		void addOption( const Option &opt );

		template<typename c>
		void callback( c *pObj, int (c::*fnc)( int, char *[] ) )
		{
			(pObj->*fnc)( 0, NULL );
		}

	private:
		Bu::FString format( const Bu::FString &sIn, int iWidth, int iIndent );

		typedef Bu::List<Option> OptionList;
		typedef Bu::Hash<char, Option *> ShortOptionHash;
		typedef Bu::Hash<Bu::FString, Option *> LongOptionHash;

		OptionList lOption;
		ShortOptionHash hsOption;
		LongOptionHash hlOption;
	};
};

#endif