TIVI-153: Add as dependency for iputils
[profile/ivi/opensp.git] / include / Options.h
1 // Copyright (c) 1996 James Clark, 1999 Matthias Clasen
2 // See the file COPYING for copying permission.
3
4 #ifndef Options_INCLUDED
5 #define Options_INCLUDED 1
6
7 #include "Boolean.h"
8 #include "Vector.h"
9
10 #ifdef SP_NAMESPACE
11 namespace SP_NAMESPACE {
12 #endif
13
14 // This is a mildly C++ified version of getopt().
15 // (extended to include getopt_long() functionality.)
16 // It never prints any message.
17
18 template<class T>
19 class LongOption {
20 public:
21   const T *name;
22   T key;
23   T value;
24   bool hasArgument;
25 };
26  
27 template<class T>
28 class Options {
29 public:
30   Options(int argc, T *const *, const Vector<LongOption<T> > &);
31   // Returns false if there are no more options.
32   bool get(T &);
33   T *arg() const { return arg_; } // optarg
34   T opt() const { return opt_; }  // optopt
35   int ind() const { return ind_; } // optind
36   int longIndex() const { return optInd_; } // longindex
37 private:
38   bool search(T);
39   bool searchLong(const T *);
40   T *const *argv_;
41   int argc_;
42   int ind_;
43   T opt_;
44   T *arg_;
45   int sp_;
46   Vector<LongOption<T> > opts_;
47   int optInd_;
48 };
49
50 #ifdef SP_NAMESPACE
51 }
52 #endif
53
54 #endif /* not Options_INCLUDED */
55
56 #ifdef SP_DEFINE_TEMPLATES
57 #include "Options.cxx"
58 #endif