DDS  ver. 3.5.3.8.g5fe284b
dds-octopus/src/Options.h
Go to the documentation of this file.
1 // Copyright 2016 GSI, Inc. All rights reserved.
2 //
3 //
4 //
5 #ifndef DDS_OCTOPUS_OPTIONS_H
6 #define DDS_OCTOPUS_OPTIONS_H
7 //=============================================================================
8 // STD
9 #include <iostream>
10 // BOOST
11 #include <boost/program_options/options_description.hpp>
12 #include <boost/program_options/parsers.hpp>
13 #include <boost/program_options/variables_map.hpp>
14 // DDS
15 #include "version.h"
16 //=============================================================================
17 namespace bpo = boost::program_options;
18 //=============================================================================
19 namespace dds
20 {
21  namespace dds_octopus
22  {
23  typedef struct SOptions
24  {
26  : m_taskCount(0)
27  {
28  }
29 
30  size_t m_taskCount;
31  } SOptions_t;
32  //=============================================================================
33  inline void PrintVersion()
34  {
35  std::cout << " v" << PROJECT_VERSION_STRING << "\n"
36  << "DDS configuration"
37  << " v" << USER_DEFAULTS_CFG_VERSION << std::endl;
38  }
39  //=============================================================================
40  // Command line parser
41  inline bool ParseCmdLine(int _argc, char* _argv[], SOptions* _options)
42  {
43  if (nullptr == _options)
44  throw std::runtime_error("Internal error: options' container is empty.");
45 
46  // Generic options
47  bpo::options_description options("dds-octopus options");
48  options.add_options()("help,h", "Produce help message");
49  options.add_options()(
50  "number,n", bpo::value<size_t>(&_options->m_taskCount)->default_value(0), "Task count");
51 
52  // Parsing command-line
53  bpo::variables_map vm;
54  bpo::store(bpo::command_line_parser(_argc, _argv).options(options).run(), vm);
55  bpo::notify(vm);
56 
57  if (vm.count("help") || vm.empty())
58  {
59  std::cout << options << std::endl;
60  return false;
61  }
62 
63  return true;
64  }
65  } // namespace dds_octopus
66 } // namespace dds
67 #endif
size_t m_taskCount
Definition: dds-octopus/src/Options.h:30
Definition: dds-octopus/src/Options.h:23
void PrintVersion()
Definition: dds-octopus/src/Options.h:33
Definition: AgentConnectionManager.h:13
SOptions()
Definition: dds-octopus/src/Options.h:25
bool ParseCmdLine(int _argc, char *_argv[], SOptions *_options)
Definition: dds-octopus/src/Options.h:41
struct dds::dds_octopus::SOptions SOptions_t