ProgramOptions.ih
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
14 /** \file
15  \brief ProgramOptions internal header */
16 
17 #ifndef IH_SENF_Scheduler_Console_ProgramOptions_
18 #define IH_SENF_Scheduler_Console_ProgramOptions_ 1
19 
20 // Custom includes
21 #include <boost/scoped_ptr.hpp>
22 #include "Parse.hh"
23 
24 //-/////////////////////////////////////////////////////////////////////////////////////////////////
25 
26 namespace senf {
27 namespace console {
28 namespace detail {
29 
30 #ifndef DOXYGEN
31 
32  class ProgramOptionsSource : public ConfigSource
33  {
34  public:
35  typedef boost::intrusive_ptr<ProgramOptionsSource> ptr;
36 
37  static ptr create(int argc, char const ** argv);
38 
39  template <class Container>
40  ProgramOptionsSource & nonOptions(Container & container);
41  ProgramOptionsSource & alias(char letter, std::string const & longOpt, bool withArg=false);
42 
43  private:
44  ProgramOptionsSource(int argc, char const ** argv);
45 
46  virtual void v_parse(RestrictedExecutor & executor);
47 
48  void parseLongOption(std::string const & arg, RestrictedExecutor & executor);
49  void parseNonOption(std::string const & arg, RestrictedExecutor & executor);
50 
51  struct NonOptionContainer
52  {
53  virtual ~NonOptionContainer();
54  virtual void clear() = 0;
55  virtual void push_back(std::string const & value) = 0;
56  };
57 
58  template <class Container>
59  struct NonOptionContainerImpl
60  : public NonOptionContainer
61  {
62  NonOptionContainerImpl(Container & c);
63 
64  void clear();
65  void push_back(std::string const & value);
66 
67  Container & c_;
68  };
69 
70  struct ShortOption
71  {
72  ShortOption(bool withArg, std::string const & longOpt);
73  bool withArg;
74  std::string longOpt;
75  };
76 
77  typedef std::map<char, ShortOption> ShortOptions;
78 
79  int argc_;
80  char const ** argv_;
81  CommandParser parser_;
82  ShortOptions shortOptions_;
83  boost::scoped_ptr<NonOptionContainer> nonOptions_;
84  };
85 
86 #endif
87 
88 }}}
89 
90 //-/////////////////////////////////////////////////////////////////////////////////////////////////
91 #endif
92 
93 
94 // Local Variables:
95 // mode: c++
96 // fill-column: 100
97 // comment-column: 40
98 // c-file-style: "senf"
99 // indent-tabs-mode: nil
100 // ispell-local-dictionary: "american"
101 // compile-command: "scons -u test"
102 // End: