/******************************************************************************** * Copyright (C) 2014-2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * * * * This software is distributed under the terms of the * * GNU Lesser General Public Licence (LGPL) version 3, * * copied verbatim in the file "LICENSE" * ********************************************************************************/ /* * File: FairMQProgOptions.cxx * Author: winckler * * Created on March 11, 2015, 10:20 PM */ #include "FairMQLogger.h" #include "FairMQProgOptions.h" #include "FairMQParser.h" #include "FairMQSuboptParser.h" #include "tools/Unique.h" #include #include #include // join/split #include #include #include #include #include #include using namespace std; using namespace fair::mq; using boost::any_cast; namespace po = boost::program_options; template ostream& operator<<(ostream& os, const vector& v) { for (unsigned int i = 0; i < v.size(); ++i) { os << v[i]; if (i != v.size() - 1) { os << ", "; } } return os; } template pair getString(const boost::any& v, const string& label) { return { to_string(any_cast(v)), label }; } template pair getStringPair(const boost::any& v, const string& label) { stringstream ss; ss << any_cast(v); return { ss.str(), label }; } unordered_map(*)(const boost::any&)> FairMQProgOptions::fValInfos = { { type_index(typeid(string)), [](const boost::any& v) { return pair{ any_cast(v), "" }; } }, { type_index(typeid(int)), [](const boost::any& v) { return getString(v, ""); } }, { type_index(typeid(size_t)), [](const boost::any& v) { return getString(v, ""); } }, { type_index(typeid(uint32_t)), [](const boost::any& v) { return getString(v, ""); } }, { type_index(typeid(uint64_t)), [](const boost::any& v) { return getString(v, ""); } }, { type_index(typeid(long)), [](const boost::any& v) { return getString(v, ""); } }, { type_index(typeid(long long)), [](const boost::any& v) { return getString(v, ""); } }, { type_index(typeid(unsigned)), [](const boost::any& v) { return getString(v, ""); } }, { type_index(typeid(unsigned long)), [](const boost::any& v) { return getString(v, ""); } }, { type_index(typeid(unsigned long long)), [](const boost::any& v) { return getString(v, ""); } }, { type_index(typeid(float)), [](const boost::any& v) { return getString(v, ""); } }, { type_index(typeid(double)), [](const boost::any& v) { return getString(v, ""); } }, { type_index(typeid(long double)), [](const boost::any& v) { return getString(v, ""); } }, { type_index(typeid(bool)), [](const boost::any& v) { stringstream ss; ss << boolalpha << any_cast(v); return pair{ ss.str(), "" }; } }, { type_index(typeid(vector)), [](const boost::any& v) { stringstream ss; ss << boolalpha << any_cast>(v); return pair{ ss.str(), ">" }; } }, { type_index(typeid(boost::filesystem::path)), [](const boost::any& v) { return getStringPair(v, ""); } }, { type_index(typeid(vector)), [](const boost::any& v) { return getStringPair>(v, ">"); } }, { type_index(typeid(vector)), [](const boost::any& v) { return getStringPair>(v, ">"); } }, { type_index(typeid(vector)), [](const boost::any& v) { return getStringPair>(v, ">"); } }, { type_index(typeid(vector)), [](const boost::any& v) { return getStringPair>(v, ">"); } }, { type_index(typeid(vector)), [](const boost::any& v) { return getStringPair>(v, ">"); } }, { type_index(typeid(vector)), [](const boost::any& v) { return getStringPair>(v, ">"); } }, { type_index(typeid(vector)), [](const boost::any& v) { return getStringPair>(v, ">"); } }, { type_index(typeid(vector)), [](const boost::any& v) { return getStringPair>(v, ">"); } }, { type_index(typeid(vector)), [](const boost::any& v) { return getStringPair>(v, ">"); } }, { type_index(typeid(vector)), [](const boost::any& v) { return getStringPair>(v, ">"); } }, { type_index(typeid(vector)), [](const boost::any& v) { return getStringPair>(v, ">"); } }, { type_index(typeid(vector)), [](const boost::any& v) { return getStringPair>(v, ">"); } }, { type_index(typeid(vector)), [](const boost::any& v) { return getStringPair>(v, ">"); } }, { type_index(typeid(vector)), [](const boost::any& v) { return getStringPair>(v, ">"); } }, }; namespace fair { namespace mq { ValInfo ConvertVarValToValInfo(const po::variable_value& v) { string origin; if (v.defaulted()) { origin = "[default]"; } else if (v.empty()) { origin = "[empty]"; } else { origin = "[provided]"; } try { pair info = FairMQProgOptions::fValInfos.at(v.value().type())(v.value()); return {info.first, info.second, origin}; } catch (out_of_range& oor) { return {string("[unidentified]"), string("[unidentified]"), origin}; } }; string ConvertVarValToString(const po::variable_value& v) { return ConvertVarValToValInfo(v).value; } } // namespace mq } // namespace fair FairMQProgOptions::FairMQProgOptions() : fVarMap() , fFairMQChannelMap() , fAllOptions("FairMQ Command Line Options") , fGeneralOptions("General options") , fMQOptions("FairMQ device options") , fParserOptions("FairMQ channel config parser options") , fMtx() , fChannelInfo() , fChannelKeyMap() , fUnregisteredOptions() , fEvents() { fGeneralOptions.add_options() ("help,h", "Print help") ("version,v", "Print version") ("severity", po::value()->default_value("debug"), "Log severity level: trace, debug, info, state, warn, error, fatal, nolog") ("verbosity", po::value()->default_value("medium"), "Log verbosity level: veryhigh, high, medium, low") ("color", po::value()->default_value(true), "Log color (true/false)") ("log-to-file", po::value()->default_value(""), "Log output to a file.") ("print-options", po::value()->implicit_value(true), "Print options in machine-readable format (