This is the mail archive of the cygwin-apps@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

GetOpt++


I've created a little library based around the design I created for
command line options in setup.exe. I did the design after I had a good
look round on the web and couldn't see any good object orientated
command line approach. It's configured to build with the setup String++
class, or to use the libstdc++ string class. I'm seriously considering
removing the setup.exe code and dropping the library in instead
(integrated into the single-build process of course).

The library isn't feature complete, but I'll be using it for all my c++
code from here on in, so unlike the GUI resource editor/windres, I can
guarantee that this will see a resonable commit rate :}. It's GPL
licenced if anyone is interested, and builds both shared and static
versions OOTB.

Anyway, I've called it GetOpt++, and am looking for a home site (CVS + a
web page or two. If it gets lots of mail, then a mailing list I guess).
So Chris, is this a cyg-apps or sources.redhat.com repository candidate,
or do I toddle off to sourceforge or an equivalent site?

For the curious, the key design goals of the library are:
1) Object based, not procedural. Some immediate corollaries are that
there is minimal footprint in main.cc, and no header or source changes
outside the user of an option when the option is altered/a new option
added. 
2) Multiple option sets can co-exist safely. The default option set is a
singleton, but additional static sets can be created and used.
3) Easy to use. I've removed the need to subclass Option from the
design, adding a new option is now simply a case of adding a static
variable for the option, in the scope that the option needs to be
visible - be that class scope or translation unit scope. There are (will
be when feature complete) multiple concrete Option classes provided
(currently BoolOption is the only one implemented).

On a further note, the difference between libGetOpt++ and the GNU libg++
GetOpt class is this: the GNU libg++ GetOpt class is procedural in
nature (99% of it's use is the same as for normal getopt) whereas
GetOpt++ uses getopt.h to do the grunt work and exposes an object based
interface. You could almost call GetOpt++  a C++ binding to getopt, but
I feel the design approach is different enough that it's more than a
simple language binding.

Rob

p.s. here is a sample program using it, as proof that it's not onerous
to use :]

#include <getopt++/GetOption.h>
#include <getopt++/BoolOption.h>

static BoolOption testoption (false, 't', "testoption", 
"Tests the use of boolean options");

int
main (int argc, char **argv)
{
  if (!GetOption::GetInstance().Process (argc, argv))
    {
      cout << "Failed to process options" << endl;
      return 1;
    }
  if (testoption)
    {
      cout << "Option used" << endl;
      return 1;
    }
  else
    {
      cout << "Option not used" << endl;
      return 0;
    }
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]