From: stephan b. <sg...@us...> - 2004-12-31 14:35:37
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/Util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7937/include/pclasses/Util Modified Files: SimpleArgvParser.h Log Message: Default CTor is now public. Index: SimpleArgvParser.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Util/SimpleArgvParser.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- SimpleArgvParser.h 30 Dec 2004 16:38:45 -0000 1.1 +++ SimpleArgvParser.h 31 Dec 2004 14:35:27 -0000 1.2 @@ -2,9 +2,16 @@ #define P_Util_SIMPLEARGVPARSER_HPP_INCLUDED 1 #include <pclasses/Util/SimplePropertyStore.h> -#include <pclasses/Phoenix.h> namespace P { namespace Util { + /** + SimpleArgvParser is a helper for applications which need to + process command-line arguments and don't have strict + requirements for doing so. + + See the parse() function for full information about the + supported argument type. + */ class SimpleArgvParser : public SimplePropertyStore { public: @@ -16,21 +23,80 @@ typedef ParentType::iterator iterator; typedef ParentType::const_iterator const_iterator; + /** + Creats a new argv parser and calls parse(argc,argv) + on it. + */ SimpleArgvParser( int argc, char ** argv ); + + /** + Creates an empty parser. It is pretty useless until + parse() is called or items are explicitely set(). + */ + SimpleArgvParser(); + virtual ~SimpleArgvParser(); + /** + Parsed out arguments in the following formats and + adds them as key/value pairs in this object: + + --ARG=VAL + + --ARG VALUE (same --ARG=VALUE, except that you must + use the equals sign if VALUE starts with a '-'.) + + --ARG="use quotes if it has spaces" + + --ARG [--NONVALUE] same as --ARG=1 + + It does not care if you use - or -- as an argument + prefix: any leading number of dashes are accepted. + + Any entries in argv which are not args or values + ar flags are ignored. + + Each flag entry is entered into this object using + set(), such that get("flag") will return the value + of the --flag parameter. + + Returns the number of arguments parsed out of argv. + + When calling this from main, you can have this + function skip the first argc (the app name) by + callin parse(argc-1,argv+1). + + This function does not clear this object before + parsing: new entries are added to the existing map. + + Note that this type's map is not a multimap, thus + arguments added more than once will take the value + of the most recent one processed. That is, the one + which comes latest in argv. + + Also note that the keys are stored in lexically + sorted order in the map, so there is no way to know + their input order via this class. + */ size_t parse( int argc, char ** argv ); + /** + Populates the shared SimpleArgsParser object. + */ static SimpleArgvParser & args( int argc, char ** argv ); + + /** + Returns a shared SimpleArgvParser. Intended to be + populated from main (or similar) by the overloaded + form of this function. + */ static SimpleArgvParser & args(); + /** + Same as size(). This name is more conventional for + this specific type. + */ int argc() const { return this->size(); } - - private: - SimpleArgvParser(); - typedef ::P::Phoenix< SimpleArgvParser > ArgvPhoenix; - friend class ArgvPhoenix; - }; |