/* * Copyright (C) 2007-2010 Xagasoft, All rights reserved. * * This file is part of the libbu++ library and is released under the * terms of the license contained in the file LICENSE. */ #ifndef BU_OPT_PARSER_H #define BU_OPT_PARSER_H #include "bu/fstring.h" #include "bu/list.h" #include "bu/hash.h" #include "bu/signals.h" #include "bu/array.h" #include "bu/membuf.h" #include "bu/formatter.h" namespace Bu { typedef Bu::Array StrArray; /** * POSIX/Gnu style command line parser. Handles long and short options in * a variety of fun and useful ways, along with singal based callbacks and * automatic variable setting. It's pretty easy to use, and very flexible. * * OptParser supports it's own builtin help mechanism which automatically * enumerates the available options and their help in a well formatted and * easy to read way, automatically formatting your help text per option and * allows for addition "help banners" which can be placed wherever you * would like. */ class OptParser { private: class _ValueProxy { public: _ValueProxy(); virtual ~_ValueProxy(); virtual void setValue( const Bu::FString & )=0; virtual _ValueProxy *clone()=0; }; template class ValueProxy : public _ValueProxy { public: ValueProxy( ptype &v ) : v( v ) { } virtual ~ValueProxy() { } virtual void setValue( const Bu::FString &sVal ) { Bu::MemBuf mb( sVal ); Bu::Formatter f( mb ); f >> v; } virtual _ValueProxy *clone() { return new ValueProxy( v ); } private: ptype &v; }; public: typedef Signal1 OptionSignal; class Option { public: Option(); Option( const Option &rSrc ); virtual ~Option(); char cOpt; Bu::FString sOpt; Bu::FString sHelp; OptionSignal sUsed; _ValueProxy *pProxy; Bu::FString sOverride; Bu::FString sHelpDefault; }; private: typedef Bu::List