mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-08 03:33:32 +01:00
Util: Create ArgsManager class...
- Introduce ArgsManager::GetArgs() - Adapt util_tests.cpp to ArgsManager
This commit is contained in:
28
src/util.cpp
28
src/util.cpp
@@ -13,7 +13,6 @@
|
||||
#include "fs.h"
|
||||
#include "random.h"
|
||||
#include "serialize.h"
|
||||
#include "sync.h"
|
||||
#include "utilstrencodings.h"
|
||||
#include "utiltime.h"
|
||||
|
||||
@@ -92,8 +91,7 @@
|
||||
const char * const BITCOIN_CONF_FILENAME = "bitcoin.conf";
|
||||
const char * const BITCOIN_PID_FILENAME = "bitcoind.pid";
|
||||
|
||||
CCriticalSection cs_args;
|
||||
std::map<std::string, std::string> mapArgs;
|
||||
ArgsManager gArgs;
|
||||
static std::map<std::string, std::vector<std::string> > _mapMultiArgs;
|
||||
const std::map<std::string, std::vector<std::string> >& mapMultiArgs = _mapMultiArgs;
|
||||
bool fPrintToConsole = false;
|
||||
@@ -384,7 +382,7 @@ static void InterpretNegativeSetting(std::string& strKey, std::string& strValue)
|
||||
}
|
||||
}
|
||||
|
||||
void ParseParameters(int argc, const char* const argv[])
|
||||
void ArgsManager::ParseParameters(int argc, const char* const argv[])
|
||||
{
|
||||
LOCK(cs_args);
|
||||
mapArgs.clear();
|
||||
@@ -420,13 +418,19 @@ void ParseParameters(int argc, const char* const argv[])
|
||||
}
|
||||
}
|
||||
|
||||
bool IsArgSet(const std::string& strArg)
|
||||
std::vector<std::string> ArgsManager::GetArgs(const std::string& strArg)
|
||||
{
|
||||
LOCK(cs_args);
|
||||
return mapMultiArgs.at(strArg);
|
||||
}
|
||||
|
||||
bool ArgsManager::IsArgSet(const std::string& strArg)
|
||||
{
|
||||
LOCK(cs_args);
|
||||
return mapArgs.count(strArg);
|
||||
}
|
||||
|
||||
std::string GetArg(const std::string& strArg, const std::string& strDefault)
|
||||
std::string ArgsManager::GetArg(const std::string& strArg, const std::string& strDefault)
|
||||
{
|
||||
LOCK(cs_args);
|
||||
if (mapArgs.count(strArg))
|
||||
@@ -434,7 +438,7 @@ std::string GetArg(const std::string& strArg, const std::string& strDefault)
|
||||
return strDefault;
|
||||
}
|
||||
|
||||
int64_t GetArg(const std::string& strArg, int64_t nDefault)
|
||||
int64_t ArgsManager::GetArg(const std::string& strArg, int64_t nDefault)
|
||||
{
|
||||
LOCK(cs_args);
|
||||
if (mapArgs.count(strArg))
|
||||
@@ -442,7 +446,7 @@ int64_t GetArg(const std::string& strArg, int64_t nDefault)
|
||||
return nDefault;
|
||||
}
|
||||
|
||||
bool GetBoolArg(const std::string& strArg, bool fDefault)
|
||||
bool ArgsManager::GetBoolArg(const std::string& strArg, bool fDefault)
|
||||
{
|
||||
LOCK(cs_args);
|
||||
if (mapArgs.count(strArg))
|
||||
@@ -450,7 +454,7 @@ bool GetBoolArg(const std::string& strArg, bool fDefault)
|
||||
return fDefault;
|
||||
}
|
||||
|
||||
bool SoftSetArg(const std::string& strArg, const std::string& strValue)
|
||||
bool ArgsManager::SoftSetArg(const std::string& strArg, const std::string& strValue)
|
||||
{
|
||||
LOCK(cs_args);
|
||||
if (mapArgs.count(strArg))
|
||||
@@ -459,7 +463,7 @@ bool SoftSetArg(const std::string& strArg, const std::string& strValue)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SoftSetBoolArg(const std::string& strArg, bool fValue)
|
||||
bool ArgsManager::SoftSetBoolArg(const std::string& strArg, bool fValue)
|
||||
{
|
||||
if (fValue)
|
||||
return SoftSetArg(strArg, std::string("1"));
|
||||
@@ -467,7 +471,7 @@ bool SoftSetBoolArg(const std::string& strArg, bool fValue)
|
||||
return SoftSetArg(strArg, std::string("0"));
|
||||
}
|
||||
|
||||
void ForceSetArg(const std::string& strArg, const std::string& strValue)
|
||||
void ArgsManager::ForceSetArg(const std::string& strArg, const std::string& strValue)
|
||||
{
|
||||
LOCK(cs_args);
|
||||
mapArgs[strArg] = strValue;
|
||||
@@ -589,7 +593,7 @@ fs::path GetConfigFile(const std::string& confPath)
|
||||
return pathConfigFile;
|
||||
}
|
||||
|
||||
void ReadConfigFile(const std::string& confPath)
|
||||
void ArgsManager::ReadConfigFile(const std::string& confPath)
|
||||
{
|
||||
fs::ifstream streamConfig(GetConfigFile(confPath));
|
||||
if (!streamConfig.good())
|
||||
|
||||
Reference in New Issue
Block a user