DDS  ver. 2.0
dds-test/src/Options.h
Go to the documentation of this file.
1 // Copyright 2014 GSI, Inc. All rights reserved.
2 //
3 //
4 //
5 #ifndef DDS_TEST_OPTIONS_H
6 #define DDS_TEST_OPTIONS_H
7 //=============================================================================
8 // BOOST
9 #include <boost/program_options/options_description.hpp>
10 #include <boost/program_options/parsers.hpp>
11 // DDS
12 #include "ProtocolCommands.h"
13 #include "Res.h"
14 #include "version.h"
15 //=============================================================================
16 namespace bpo = boost::program_options;
17 //=============================================================================
18 namespace dds
19 {
20  namespace test_cmd
21  {
23  typedef struct SOptions
24  {
26  : m_transportTest(false)
27  , m_verbose(false)
28  {
29  }
30 
32  bool m_verbose;
33  } SOptions_t;
34  //=============================================================================
35  inline void PrintVersion()
36  {
37  LOG(MiscCommon::log_stdout) << " v" << PROJECT_VERSION_STRING << "\n"
38  << "DDS configuration"
39  << " v" << USER_DEFAULTS_CFG_VERSION << "\n"
41  }
42  //=============================================================================
43  // Command line parser
44  inline bool ParseCmdLine(int _argc, char* _argv[], SOptions* _options)
45  {
46  if (nullptr == _options)
47  throw std::runtime_error("Internal error: options' container is empty.");
48 
49  // Generic options
50  bpo::options_description options("dds-getlog options");
51  options.add_options()("help,h", "Produce help message");
52  options.add_options()("version,v", "Version information");
53  options.add_options()("transport,t", "Start transport test");
54  options.add_options()("verbose", "Verbose output");
55 
56  // Parsing command-line
57  bpo::variables_map vm;
58  bpo::store(bpo::command_line_parser(_argc, _argv).options(options).run(), vm);
59  bpo::notify(vm);
60 
61  if (vm.count("help") || vm.empty())
62  {
63  LOG(MiscCommon::log_stdout) << options;
64  return false;
65  }
66  if (vm.count("version"))
67  {
68  PrintVersion();
69  return false;
70  }
71  if (vm.count("transport"))
72  {
73  _options->m_transportTest = true;
74  }
75  if (vm.count("verbose"))
76  {
77  _options->m_verbose = true;
78  }
79 
80  return true;
81  }
82  }
83 }
84 #endif
Definition: def.h:154
struct dds::test_cmd::SOptions SOptions_t
dds-getlog&#39;s container of options
void PrintVersion()
Definition: dds-test/src/Options.h:35
bool m_transportTest
Definition: dds-test/src/Options.h:31
dds-getlog&#39;s container of options
Definition: dds-test/src/Options.h:23
#define LOG(severity)
Definition: Logger.h:54
const LPCSTR g_cszReportBugsAddr("Report bugs/comments to fairroot@gsi.de")
Definition: dds-agent/src/AgentConnectionManager.h:18
bool ParseCmdLine(int _argc, char *_argv[], SOptions *_options)
Definition: dds-test/src/Options.h:44
bool m_verbose
Definition: dds-test/src/Options.h:32
SOptions()
Definition: dds-test/src/Options.h:25