Changeset View
Changeset View
Standalone View
Standalone View
src/util.h
Show All 20 Lines | |||||
#include "tinyformat.h" | #include "tinyformat.h" | ||||
#include "utiltime.h" | #include "utiltime.h" | ||||
#include <atomic> | #include <atomic> | ||||
#include <cstdint> | #include <cstdint> | ||||
#include <exception> | #include <exception> | ||||
#include <map> | #include <map> | ||||
#include <string> | #include <string> | ||||
#include <unordered_set> | |||||
#include <vector> | #include <vector> | ||||
#include <boost/signals2/signal.hpp> | #include <boost/signals2/signal.hpp> | ||||
// Application startup time (used for uptime calculation) | // Application startup time (used for uptime calculation) | ||||
int64_t GetStartupTime(); | int64_t GetStartupTime(); | ||||
/** Signals for translation. */ | /** Signals for translation. */ | ||||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | |||||
#endif | #endif | ||||
} | } | ||||
class ArgsManager { | class ArgsManager { | ||||
protected: | protected: | ||||
mutable CCriticalSection cs_args; | mutable CCriticalSection cs_args; | ||||
std::map<std::string, std::string> mapArgs; | std::map<std::string, std::string> mapArgs; | ||||
std::map<std::string, std::vector<std::string>> mapMultiArgs; | std::map<std::string, std::vector<std::string>> mapMultiArgs; | ||||
std::unordered_set<std::string> m_negated_args; | |||||
public: | public: | ||||
void ParseParameters(int argc, const char *const argv[]); | void ParseParameters(int argc, const char *const argv[]); | ||||
void ReadConfigFile(const std::string &confPath); | void ReadConfigFile(const std::string &confPath); | ||||
/** | /** | ||||
* Return a vector of strings of the given argument | * Return a vector of strings of the given argument | ||||
* | * | ||||
* @param strArg Argument to get (e.g. "-foo") | * @param strArg Argument to get (e.g. "-foo") | ||||
* @return command-line arguments | * @return command-line arguments | ||||
*/ | */ | ||||
std::vector<std::string> GetArgs(const std::string &strArg) const; | std::vector<std::string> GetArgs(const std::string &strArg) const; | ||||
/** | /** | ||||
* Return true if the given argument has been manually set. | * Return true if the given argument has been manually set. | ||||
* | * | ||||
* @param strArg Argument to get (e.g. "-foo") | * @param strArg Argument to get (e.g. "-foo") | ||||
* @return true if the argument has been set | * @return true if the argument has been set | ||||
*/ | */ | ||||
bool IsArgSet(const std::string &strArg) const; | bool IsArgSet(const std::string &strArg) const; | ||||
/** | /** | ||||
* Return true if the argument was originally passed as a negated option, | |||||
* i.e. -nofoo. | |||||
* | |||||
* @param strArg Argument to get (e.g. "-foo") | |||||
* @return true if the argument was passed negated | |||||
*/ | |||||
bool IsArgNegated(const std::string &strArg) const; | |||||
/** | |||||
* Return string argument or default value. | * Return string argument or default value. | ||||
* | * | ||||
* @param strArg Argument to get (e.g. "-foo") | * @param strArg Argument to get (e.g. "-foo") | ||||
* @param default (e.g. "1") | * @param default (e.g. "1") | ||||
* @return command-line argument or default value | * @return command-line argument or default value | ||||
*/ | */ | ||||
std::string GetArg(const std::string &strArg, | std::string GetArg(const std::string &strArg, | ||||
const std::string &strDefault) const; | const std::string &strDefault) const; | ||||
Show All 38 Lines | public: | ||||
void ForceSetArg(const std::string &strArg, const std::string &strValue); | void ForceSetArg(const std::string &strArg, const std::string &strValue); | ||||
// Forces a multi arg setting, used only in testing | // Forces a multi arg setting, used only in testing | ||||
void ForceSetMultiArg(const std::string &strArg, | void ForceSetMultiArg(const std::string &strArg, | ||||
const std::string &strValue); | const std::string &strValue); | ||||
// Remove an arg setting, used only in testing | // Remove an arg setting, used only in testing | ||||
void ClearArg(const std::string &strArg); | void ClearArg(const std::string &strArg); | ||||
private: | |||||
// Munge -nofoo into -foo=0 and track the value as negated. | |||||
void InterpretNegatedOption(std::string &key, std::string &val); | |||||
}; | }; | ||||
extern ArgsManager gArgs; | extern ArgsManager gArgs; | ||||
/** | /** | ||||
* Format a string to be used as group of options in help messages. | * Format a string to be used as group of options in help messages. | ||||
* | * | ||||
* @param message Group name (e.g. "RPC server options:") | * @param message Group name (e.g. "RPC server options:") | ||||
▲ Show 20 Lines • Show All 48 Lines • Show Last 20 Lines |