DDS  ver. 3.6
BoostHelper.h
Go to the documentation of this file.
1 // Copyright 2014 GSI, Inc. All rights reserved.
2 //
3 // Helpers for BOOST libraries
4 //
5 #ifndef _DDS_BOOSTHELPER_H_
6 #define _DDS_BOOSTHELPER_H_
7 
8 // DDS
9 #include "MiscUtils.h"
10 // Boost
11 #include <boost/format.hpp>
12 #include <boost/program_options/variables_map.hpp>
13 
14 namespace dds::misc
15 {
16  inline std::string get_temp_dir(const std::string& _prefix)
17  {
18  std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
19  std::time_t nowTimeT = std::chrono::system_clock::to_time_t(now);
20  struct std::tm* ptm = std::localtime(&nowTimeT);
21  char buffer[128];
22  std::strftime(buffer, 128, "%Y-%m-%d-%H-%M-%S-", ptm);
23  std::chrono::milliseconds ms = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch());
24  std::stringstream timeSS;
25  timeSS << _prefix << "_" << buffer << boost::format("%03i") % (ms.count() % 1000);
26  return timeSS.str();
27  }
28 
40  inline void conflicting_options(const boost::program_options::variables_map& _vm,
41  const char* _opt1,
42  const char* _opt2)
43  {
44  if (_vm.count(_opt1) && !_vm[_opt1].defaulted() && _vm.count(_opt2) && !_vm[_opt2].defaulted())
45  {
46  std::string str("Command line parameter \"%1\" conflicts with \"%2\"");
47  replace<std::string>(&str, "%1", _opt1);
48  replace<std::string>(&str, "%2", _opt2);
49  throw std::runtime_error(str);
50  }
51  }
63  inline void option_dependency(const boost::program_options::variables_map& _vm,
64  const char* _for_what,
65  const char* _required_option)
66  {
67  if (_vm.count(_for_what) && !_vm[_for_what].defaulted() &&
68  (!_vm.count(_required_option) || _vm[_required_option].defaulted()))
69  {
70  std::string str("Command line parameter \"%1\" must be used with \"%2\"");
71  replace<std::string>(&str, "%1", _for_what);
72  replace<std::string>(&str, "%2", _required_option);
73  throw std::runtime_error(str);
74  }
75  }
76 }; // namespace dds::misc
77 
78 #endif /*_DDS_BOOSTHELPER_H_*/
void conflicting_options(const boost::program_options::variables_map &_vm, const char *_opt1, const char *_opt2)
The conflicting_options function used to check that 'opt1' and 'opt2' are not specified at the same t...
Definition: BoostHelper.h:40
std::string get_temp_dir(const std::string &_prefix)
Definition: BoostHelper.h:16
void option_dependency(const boost::program_options::variables_map &_vm, const char *_for_what, const char *_required_option)
The option_dependency function used to check that if 'for_what' is specified, then 'required_option' ...
Definition: BoostHelper.h:63
Definition: BoostHelper.h:14