CMS 3D CMS Logo

List of all members | Public Member Functions | Private Types | Private Member Functions | Private Attributes
cxxopts::Options Class Reference

#include <cxxopts.h>

Public Member Functions

void add_option (const std::string &group, const std::string &s, const std::string &l, std::string desc, std::shared_ptr< const Value > value, std::string arg_help)
 
OptionAdder add_options (std::string group="")
 
Optionsallow_unrecognised_options ()
 
Optionscustom_help (std::string help_text)
 
const HelpGroupDetailsgroup_help (const std::string &group) const
 
const std::vector< std::string > groups () const
 
std::string help (const std::vector< std::string > &groups={}) const
 
 Options (std::string program, std::string help_string="")
 
ParseResult parse (int &argc, char **&argv)
 
void parse_positional (std::string option)
 
void parse_positional (std::vector< std::string > options)
 
void parse_positional (std::initializer_list< std::string > options)
 
template<typename Iterator >
void parse_positional (Iterator begin, Iterator end)
 
Optionspositional_help (std::string help_text)
 
Optionsshow_positional_help ()
 

Private Types

typedef std::unordered_map< std::string, std::shared_ptr< OptionDetails > > OptionMap
 

Private Member Functions

void add_one_option (const std::string &option, std::shared_ptr< OptionDetails > details)
 
void generate_all_groups_help (String &result) const
 
void generate_group_help (String &result, const std::vector< std::string > &groups) const
 
String help_one_group (const std::string &group) const
 

Private Attributes

bool m_allow_unrecognised
 
std::string m_custom_help
 
std::map< std::string, HelpGroupDetailsm_help
 
String m_help_string
 
std::vector< std::string >::iterator m_next_positional
 
std::shared_ptr< OptionMapm_options
 
std::vector< std::string > m_positional
 
std::string m_positional_help
 
std::unordered_set< std::string > m_positional_set
 
std::string m_program
 
bool m_show_positional
 

Detailed Description

Definition at line 753 of file cxxopts.h.

Member Typedef Documentation

◆ OptionMap

typedef std::unordered_map<std::string, std::shared_ptr<OptionDetails> > cxxopts::Options::OptionMap
private

Definition at line 754 of file cxxopts.h.

Constructor & Destructor Documentation

◆ Options()

cxxopts::Options::Options ( std::string  program,
std::string  help_string = "" 
)
inline

Definition at line 757 of file cxxopts.h.

758  : m_program(std::move(program)),
759  m_help_string(toLocalString(std::move(help_string))),
760  m_custom_help("[OPTION...]"),
761  m_positional_help("positional parameters"),
762  m_show_positional(false),
763  m_allow_unrecognised(false),
764  m_options(std::make_shared<OptionMap>()),
std::vector< std::string > m_positional
Definition: cxxopts.h:833
std::string m_custom_help
Definition: cxxopts.h:827
T toLocalString(T &&t)
Definition: cxxopts.h:142
bool m_allow_unrecognised
Definition: cxxopts.h:830
std::vector< std::string >::iterator m_next_positional
Definition: cxxopts.h:834
bool m_show_positional
Definition: cxxopts.h:829
std::string m_positional_help
Definition: cxxopts.h:828
String m_help_string
Definition: cxxopts.h:826
std::shared_ptr< OptionMap > m_options
Definition: cxxopts.h:832
def move(src, dest)
Definition: eostools.py:511
std::string m_program
Definition: cxxopts.h:825

Member Function Documentation

◆ add_one_option()

void cxxopts::Options::add_one_option ( const std::string &  option,
std::shared_ptr< OptionDetails details 
)
inlineprivate

Definition at line 1238 of file cxxopts.h.

References recoMuon::in, m_options, and fileinputsource_cfi::option.

Referenced by add_option().

1238  {
1239  auto in = m_options->emplace(option, details);
1240 
1241  if (!in.second) {
1242  throw Option_exists_error(option);
1243  }
1244  }
Definition: helper.h:56
std::shared_ptr< OptionMap > m_options
Definition: cxxopts.h:832

◆ add_option()

void cxxopts::Options::add_option ( const std::string &  group,
const std::string &  s,
const std::string &  l,
std::string  desc,
std::shared_ptr< const Value value,
std::string  arg_help 
)
inline

Definition at line 1206 of file cxxopts.h.

References add_one_option(), submitPVResolutionJobs::desc, watchdog::group, MainPageGenerator::l, m_help, eostools::move(), fileinputsource_cfi::option, alignCSCRings::s, cxxopts::toLocalString(), and cxxopts::value().

Referenced by contentValuesCheck.OptionParser::__init__(), contentValuesToDBS.OptionParser::__init__(), contentValuesToRR.OptionParser::__init__(), bookConverter.OptionParser::__init__(), contentValuesFiles.OptionParser::__init__(), and cxxopts::OptionAdder::operator()().

1211  {
1212  auto stringDesc = toLocalString(std::move(desc));
1213  auto option = std::make_shared<OptionDetails>(s, l, stringDesc, value);
1214 
1215  if (s.size() > 0) {
1217  }
1218 
1219  if (l.size() > 0) {
1221  }
1222 
1223  //add the help details
1224  auto& options = m_help[group];
1225 
1226  options.options.emplace_back(HelpOptionDetails{s,
1227  l,
1228  stringDesc,
1229  value->has_default(),
1230  value->get_default_value(),
1231  value->has_implicit(),
1232  value->get_implicit_value(),
1233  std::move(arg_help),
1234  value->is_container(),
1235  value->is_boolean()});
1236  }
std::map< std::string, HelpGroupDetails > m_help
Definition: cxxopts.h:838
T toLocalString(T &&t)
Definition: cxxopts.h:142
std::shared_ptr< Value > value()
Definition: cxxopts.h:574
Definition: value.py:1
void add_one_option(const std::string &option, std::shared_ptr< OptionDetails > details)
Definition: cxxopts.h:1238
def move(src, dest)
Definition: eostools.py:511

◆ add_options()

OptionAdder cxxopts::Options::add_options ( std::string  group = "")
inline

Definition at line 956 of file cxxopts.h.

References watchdog::group, and eostools::move().

956 { return OptionAdder(*this, std::move(group)); }
def move(src, dest)
Definition: eostools.py:511

◆ allow_unrecognised_options()

Options& cxxopts::Options::allow_unrecognised_options ( )
inline

Definition at line 782 of file cxxopts.h.

References m_allow_unrecognised.

782  {
783  m_allow_unrecognised = true;
784  return *this;
785  }
bool m_allow_unrecognised
Definition: cxxopts.h:830

◆ custom_help()

Options& cxxopts::Options::custom_help ( std::string  help_text)
inline

Definition at line 772 of file cxxopts.h.

References m_custom_help, and eostools::move().

772  {
773  m_custom_help = std::move(help_text);
774  return *this;
775  }
std::string m_custom_help
Definition: cxxopts.h:827
def move(src, dest)
Definition: eostools.py:511

◆ generate_all_groups_help()

void cxxopts::Options::generate_all_groups_help ( String result) const
inlineprivate

Definition at line 1316 of file cxxopts.h.

References generate_group_help(), watchdog::group, m_help, and mps_fire::result.

Referenced by help().

1316  {
1317  std::vector<std::string> all_groups;
1318  all_groups.reserve(m_help.size());
1319 
1320  for (auto& group : m_help) {
1321  all_groups.push_back(group.first);
1322  }
1323 
1324  generate_group_help(result, all_groups);
1325  }
std::map< std::string, HelpGroupDetails > m_help
Definition: cxxopts.h:838
void generate_group_help(String &result, const std::vector< std::string > &groups) const
Definition: cxxopts.h:1303

◆ generate_group_help()

void cxxopts::Options::generate_group_help ( String result,
const std::vector< std::string > &  groups 
) const
inlineprivate

Definition at line 1303 of file cxxopts.h.

References cxxopts::empty(), help_one_group(), mps_fire::i, and mps_fire::result.

Referenced by generate_all_groups_help(), and help().

1303  {
1304  for (size_t i = 0; i != print_groups.size(); ++i) {
1305  const String& group_help_text = help_one_group(print_groups[i]);
1306  if (empty(group_help_text)) {
1307  continue;
1308  }
1309  result += group_help_text;
1310  if (i < print_groups.size() - 1) {
1311  result += '\n';
1312  }
1313  }
1314  }
String help_one_group(const std::string &group) const
Definition: cxxopts.h:1246
bool empty(const std::string &s)
Definition: cxxopts.h:162
std::string String
Definition: cxxopts.h:139

◆ group_help()

const HelpGroupDetails & cxxopts::Options::group_help ( const std::string &  group) const
inline

Definition at line 1356 of file cxxopts.h.

References watchdog::group, and m_help.

1356 { return m_help.at(group); }
std::map< std::string, HelpGroupDetails > m_help
Definition: cxxopts.h:838

◆ groups()

const std::vector< std::string > cxxopts::Options::groups ( ) const
inline

Definition at line 1345 of file cxxopts.h.

References g, m_help, and HcalDetIdTransform::transform().

1345  {
1346  std::vector<std::string> g;
1347 
1348  std::transform(m_help.begin(),
1349  m_help.end(),
1350  std::back_inserter(g),
1351  [](const std::map<std::string, HelpGroupDetails>::value_type& pair) { return pair.first; });
1352 
1353  return g;
1354  }
std::map< std::string, HelpGroupDetails > m_help
Definition: cxxopts.h:838
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
unsigned transform(const HcalDetId &id, unsigned transformCode)

◆ help()

std::string cxxopts::Options::help ( const std::vector< std::string > &  groups = {}) const
inline

Definition at line 1327 of file cxxopts.h.

References generate_all_groups_help(), generate_group_help(), m_custom_help, m_help_string, m_positional, m_positional_help, m_program, mps_fire::result, cxxopts::toLocalString(), and cxxopts::toUTF8String().

1327  {
1329 
1330  if (m_positional.size() > 0 && m_positional_help.size() > 0) {
1332  }
1333 
1334  result += "\n\n";
1335 
1336  if (help_groups.size() == 0) {
1338  } else {
1339  generate_group_help(result, help_groups);
1340  }
1341 
1342  return toUTF8String(result);
1343  }
std::vector< std::string > m_positional
Definition: cxxopts.h:833
std::string m_custom_help
Definition: cxxopts.h:827
T toLocalString(T &&t)
Definition: cxxopts.h:142
void generate_all_groups_help(String &result) const
Definition: cxxopts.h:1316
std::string String
Definition: cxxopts.h:139
void generate_group_help(String &result, const std::vector< std::string > &groups) const
Definition: cxxopts.h:1303
std::string m_positional_help
Definition: cxxopts.h:828
std::string toUTF8String(T &&t)
Definition: cxxopts.h:158
String m_help_string
Definition: cxxopts.h:826
std::string m_program
Definition: cxxopts.h:825

◆ help_one_group()

String cxxopts::Options::help_one_group ( const std::string &  group) const
inlineprivate

Definition at line 1246 of file cxxopts.h.

References ztail::d, dqm-mbProfile::format, g, watchdog::group, m_help, m_positional_set, m_show_positional, WZElectronSkims53X_cff::max, SiStripPI::min, EcalTangentSkim_cfg::o, mps_fire::result, alignCSCRings::s, AlCaHLTBitMon_QueryRunRegistry::string, cxxopts::stringLength(), and cxxopts::toLocalString().

Referenced by generate_group_help().

1246  {
1247  typedef std::vector<std::pair<String, String>> OptionHelp;
1248 
1249  auto group = m_help.find(g);
1250  if (group == m_help.end()) {
1251  return "";
1252  }
1253 
1254  OptionHelp format;
1255 
1256  size_t longest = 0;
1257 
1258  String result;
1259 
1260  if (!g.empty()) {
1261  result += toLocalString(" " + g + " options:\n");
1262  }
1263 
1264  for (const auto& o : group->second.options) {
1265  if (o.is_container && m_positional_set.find(o.l) != m_positional_set.end() && !m_show_positional) {
1266  continue;
1267  }
1268 
1269  auto s = format_option(o);
1270  longest = (std::max)(longest, stringLength(s));
1271  format.push_back(std::make_pair(s, String()));
1272  }
1273 
1274  longest = (std::min)(longest, static_cast<size_t>(OPTION_LONGEST));
1275 
1276  //widest allowed description
1277  auto allowed = size_t{76} - longest - OPTION_DESC_GAP;
1278 
1279  auto fiter = format.begin();
1280  for (const auto& o : group->second.options) {
1281  if (o.is_container && m_positional_set.find(o.l) != m_positional_set.end() && !m_show_positional) {
1282  continue;
1283  }
1284 
1285  auto d = format_description(o, longest + OPTION_DESC_GAP, allowed);
1286 
1287  result += fiter->first;
1288  if (stringLength(fiter->first) > longest) {
1289  result += '\n';
1290  result += toLocalString(std::string(longest + OPTION_DESC_GAP, ' '));
1291  } else {
1292  result += toLocalString(std::string(longest + OPTION_DESC_GAP - stringLength(fiter->first), ' '));
1293  }
1294  result += d;
1295  result += '\n';
1296 
1297  ++fiter;
1298  }
1299 
1300  return result;
1301  }
std::map< std::string, HelpGroupDetails > m_help
Definition: cxxopts.h:838
T toLocalString(T &&t)
Definition: cxxopts.h:142
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
d
Definition: ztail.py:151
bool m_show_positional
Definition: cxxopts.h:829
std::string String
Definition: cxxopts.h:139
std::unordered_set< std::string > m_positional_set
Definition: cxxopts.h:835
size_t stringLength(const String &s)
Definition: cxxopts.h:146

◆ parse()

ParseResult cxxopts::Options::parse ( int &  argc,
char **&  argv 
)
inline

Definition at line 1073 of file cxxopts.h.

References dir2webdir::argc, GCPpyPlots::argv, m_allow_unrecognised, m_options, m_positional, and mps_fire::result.

1073  {
1075  return result;
1076  }
std::vector< std::string > m_positional
Definition: cxxopts.h:833
bool m_allow_unrecognised
Definition: cxxopts.h:830
std::shared_ptr< OptionMap > m_options
Definition: cxxopts.h:832

◆ parse_positional() [1/4]

void cxxopts::Options::parse_positional ( std::string  option)
inline

Definition at line 1058 of file cxxopts.h.

References eostools::move(), and fileinputsource_cfi::option.

Referenced by parse_positional().

1058  {
1059  parse_positional(std::vector<std::string>{std::move(option)});
1060  }
void parse_positional(std::string option)
Definition: cxxopts.h:1058
def move(src, dest)
Definition: eostools.py:511

◆ parse_positional() [2/4]

void cxxopts::Options::parse_positional ( std::vector< std::string >  options)
inline

Definition at line 1062 of file cxxopts.h.

References m_next_positional, m_positional, m_positional_set, and eostools::move().

1062  {
1064  m_next_positional = m_positional.begin();
1065 
1066  m_positional_set.insert(m_positional.begin(), m_positional.end());
1067  }
std::vector< std::string > m_positional
Definition: cxxopts.h:833
std::vector< std::string >::iterator m_next_positional
Definition: cxxopts.h:834
std::unordered_set< std::string > m_positional_set
Definition: cxxopts.h:835
def move(src, dest)
Definition: eostools.py:511

◆ parse_positional() [3/4]

void cxxopts::Options::parse_positional ( std::initializer_list< std::string >  options)
inline

Definition at line 1069 of file cxxopts.h.

References eostools::move(), and parse_positional().

1069  {
1070  parse_positional(std::vector<std::string>(std::move(options)));
1071  }
void parse_positional(std::string option)
Definition: cxxopts.h:1058
def move(src, dest)
Definition: eostools.py:511

◆ parse_positional() [4/4]

template<typename Iterator >
void cxxopts::Options::parse_positional ( Iterator  begin,
Iterator  end 
)
inline

Definition at line 806 of file cxxopts.h.

References parse_positional().

806  {
807  parse_positional(std::vector<std::string>{begin, end});
808  }
void parse_positional(std::string option)
Definition: cxxopts.h:1058

◆ positional_help()

Options& cxxopts::Options::positional_help ( std::string  help_text)
inline

Definition at line 767 of file cxxopts.h.

References m_positional_help, and eostools::move().

767  {
768  m_positional_help = std::move(help_text);
769  return *this;
770  }
std::string m_positional_help
Definition: cxxopts.h:828
def move(src, dest)
Definition: eostools.py:511

◆ show_positional_help()

Options& cxxopts::Options::show_positional_help ( )
inline

Definition at line 777 of file cxxopts.h.

References m_show_positional.

777  {
778  m_show_positional = true;
779  return *this;
780  }
bool m_show_positional
Definition: cxxopts.h:829

Member Data Documentation

◆ m_allow_unrecognised

bool cxxopts::Options::m_allow_unrecognised
private

Definition at line 830 of file cxxopts.h.

Referenced by allow_unrecognised_options(), and parse().

◆ m_custom_help

std::string cxxopts::Options::m_custom_help
private

Definition at line 827 of file cxxopts.h.

Referenced by custom_help(), and help().

◆ m_help

std::map<std::string, HelpGroupDetails> cxxopts::Options::m_help
private

Definition at line 838 of file cxxopts.h.

Referenced by add_option(), generate_all_groups_help(), group_help(), groups(), and help_one_group().

◆ m_help_string

String cxxopts::Options::m_help_string
private

Definition at line 826 of file cxxopts.h.

Referenced by help().

◆ m_next_positional

std::vector<std::string>::iterator cxxopts::Options::m_next_positional
private

Definition at line 834 of file cxxopts.h.

Referenced by parse_positional().

◆ m_options

std::shared_ptr<OptionMap> cxxopts::Options::m_options
private

Definition at line 832 of file cxxopts.h.

Referenced by add_one_option(), and parse().

◆ m_positional

std::vector<std::string> cxxopts::Options::m_positional
private

Definition at line 833 of file cxxopts.h.

Referenced by help(), parse(), and parse_positional().

◆ m_positional_help

std::string cxxopts::Options::m_positional_help
private

Definition at line 828 of file cxxopts.h.

Referenced by help(), and positional_help().

◆ m_positional_set

std::unordered_set<std::string> cxxopts::Options::m_positional_set
private

Definition at line 835 of file cxxopts.h.

Referenced by help_one_group(), and parse_positional().

◆ m_program

std::string cxxopts::Options::m_program
private

Definition at line 825 of file cxxopts.h.

Referenced by help().

◆ m_show_positional

bool cxxopts::Options::m_show_positional
private

Definition at line 829 of file cxxopts.h.

Referenced by help_one_group(), and show_positional_help().