Index:
[thread]
[date]
[subject]
[author]
From: Garrett Mitchener <wgm2@acpub.duke.edu>
To :
Date: 28 Feb 1999 19:26:32 -0500
Re: getopt
Luke <lop@duke.edu> writes:
> I am having a little trouble understanding the getopt library
> implentation.
>
> The specifications call for iterators and const iterators. What is the
> difference? I'm assuming we need something in the order of begin() and
> end() and operators ++ and * for incrementation and derefrencing,
> respectively, and a public iterator type so that users of the class can
> declare iterators.
When you do *plainIter, the value isn't const. As in your iterator class
might look like this:
class FooIterator
{
public:
Foo & operator *();
};
When you do *constIter, the value is const:
class ConstFooIterator
{
public:
const Foo & operator *();
};
> Changing things so GetOpt uses strings and vectors shouldn't be too
> hard. However, the C getopt has several static C variables that aren't
> really passed anywhere and just appear in the program, namely char
> *optarg and int optind. This seems kinda sloppy for a
> C++ implementation. I'm assuming converting the first to a static
> string, leaving the second as is, and just using it the same way that it
> would be in C is not a good idea?? Would it be better to pass an int
> and a string to getopt by reference and do it that way?
Global variables are just something you have to put up with in old C
code. Your parser class may use them, but don't attempt to replace
them -- it won't work. Your parser should also not just publicly
expose them. It should be possible, if you wanted, to re-write your
parser to behave exactly the same way without calling getopt, and you
don't want global variables to be inherent in your design.
> My next question is about classes in this library. The assignment makes
> it seem like we should have a lot of classes here- I can see having one
> for getopt and one for readenv, or something like that, but what else?
> I'm assuming we need to have sorters, but should we try to integrate
> them with the sorters in scandir?
Depending on how you design it, it can take from 2 to 64 classes to do
this assignment. You should at least have a parser class, a scanner
class, various iterator classes, some means of filtering, and some
means of specifying a sort order.
> Also, is anyone else just a little frustrated that the link to
> usegetopt.cc doesn't work and this thing is due monday?
>
> I am confused. PLEASE HELP!!!
> -Luke
There is other getopt documentation available. Look at the links on
the help page (call it up and search for getopt w/ netscapes find
command), and heed the warning about switch statements.
-- garrett :-)
Index:
[thread]
[date]
[subject]
[author]