ProgramOptions.cci
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 inline non-template implementation */
16 
17 #include "ProgramOptions.ih"
18 
19 // Custom includes
20 
21 #define prefix_ inline
22 //-/////////////////////////////////////////////////////////////////////////////////////////////////
23 
24 //-/////////////////////////////////////////////////////////////////////////////////////////////////
25 // senf::console::detail::ProgramOptionsSource
26 
27 prefix_ senf::console::detail::ProgramOptionsSource::ptr
28 senf::console::detail::ProgramOptionsSource::create(int argc, char const ** argv)
29 {
30  return ptr(new ProgramOptionsSource(argc,argv));
31 }
32 
33 prefix_ senf::console::detail::ProgramOptionsSource::ProgramOptionsSource(int argc,
34  char const ** argv)
35  : argc_ (argc), argv_ (argv)
36 {}
37 
38 prefix_ senf::console::detail::ProgramOptionsSource &
39 senf::console::detail::ProgramOptionsSource::alias(char letter, std::string const & longOpt,
40  bool withArg)
41 {
42  shortOptions_.insert(std::make_pair(letter, ShortOption(withArg, longOpt)));
43  return *this;
44 }
45 
46 //-/////////////////////////////////////////////////////////////////////////////////////////////////
47 // senf::console::detail::ProgramOptionsSource::ShortOption
48 
49 prefix_ senf::console::detail::ProgramOptionsSource::ShortOption::
50 ShortOption(bool withArg_, std::string const & longOpt_)
51  : withArg (withArg_), longOpt (longOpt_)
52 {}
53 
54 //-/////////////////////////////////////////////////////////////////////////////////////////////////
55 // senf::console::ProgramOptions
56 
57 prefix_ senf::console::ProgramOptions::ProgramOptions(int argc, char const ** argv,
58  DirectoryNode & root)
59  : detail::BundleMixin (root), config_ (add(detail::ProgramOptionsSource::create(argc, argv)))
60 {}
61 
62 prefix_ senf::console::ProgramOptions &
63 senf::console::ProgramOptions::alias(char letter, std::string const & longOpt, bool withArg)
64 {
65  config_.alias(letter, longOpt, withArg);
66  return *this;
67 }
68 
69 //-/////////////////////////////////////////////////////////////////////////////////////////////////
70 
71 prefix_ senf::console::detail::ProgramOptionsSource::ptr
72 senf::console::OptionsConfig(int argc, char const ** argv)
73 {
74  return detail::ProgramOptionsSource::create(argc, argv);
75 }
76 
77 //-/////////////////////////////////////////////////////////////////////////////////////////////////
78 #undef prefix_
79 
80 
81 // Local Variables:
82 // mode: c++
83 // fill-column: 100
84 // comment-column: 40
85 // c-file-style: "senf"
86 // indent-tabs-mode: nil
87 // ispell-local-dictionary: "american"
88 // compile-command: "scons -u test"
89 // End: