diff --git a/client/client_application.cpp b/client/client_application.cpp index c3835da..f2dcd8a 100644 --- a/client/client_application.cpp +++ b/client/client_application.cpp @@ -49,7 +49,7 @@ void ClientApplication::Init(int argc, char* argv[]) { //load the prerequisites ConfigUtility& config = ConfigUtility::GetSingleton(); - config.Load("rsc/config.cfg", argc, argv); + config.Load("rsc/config.cfg", false, argc, argv); //------------------------- //Initialize the APIs diff --git a/client/main.cpp b/client/main.cpp index 087a537..1278f91 100644 --- a/client/main.cpp +++ b/client/main.cpp @@ -36,7 +36,7 @@ int main(int argc, char* argv[]) { ConfigUtility::CreateSingleton(); UDPNetworkUtility::CreateSingleton(); - //call the server's routines + //call the client's routines ClientApplication::CreateSingleton(); ClientApplication& app = ClientApplication::GetSingleton(); diff --git a/common/debugging/timer.cpp b/common/debugging/timer.cpp index 302ddb5..b99ee10 100644 --- a/common/debugging/timer.cpp +++ b/common/debugging/timer.cpp @@ -39,7 +39,7 @@ void Timer::Stop() { std::ostream& operator<<(std::ostream& os, Timer& t) { os << t.GetName() << ": "; - os << std::chrono::duration_cast(t.GetTime()).count(); - os << "ms"; + os << std::chrono::duration_cast(t.GetTime()).count(); + os << "us"; return os; } diff --git a/common/debugging/timer.hpp b/common/debugging/timer.hpp index e5139d3..847f585 100644 --- a/common/debugging/timer.hpp +++ b/common/debugging/timer.hpp @@ -34,8 +34,8 @@ public: Timer(std::string s); ~Timer() = default; - inline void Start(); - inline void Stop(); + void Start(); + void Stop(); //accessors and mutators Clock::duration GetTime() { return timeSpan; } diff --git a/common/utilities/config_utility.cpp b/common/utilities/config_utility.cpp index 2c47929..832680e 100644 --- a/common/utilities/config_utility.cpp +++ b/common/utilities/config_utility.cpp @@ -27,13 +27,13 @@ #include #include -void ConfigUtility::Load(std::string fname, int argc, char* argv[]) { +void ConfigUtility::Load(std::string fname, bool skipMissingFile, int argc, char* argv[]) { //clear the stored configuration configMap.clear(); //use the default file if (argc < 2) { - configMap = Read(fname); + configMap = Read(fname, skipMissingFile); return; } @@ -47,7 +47,9 @@ void ConfigUtility::Load(std::string fname, int argc, char* argv[]) { for (int i = 1; i < argc; ++i) { //read from a specified config file if (!strncmp(argv[i], "-config=", 8)) { - redirectedFile = Read(argv[i] + 8); + //older specified files take precedence + table_t tmp = Read(argv[i] + 8, skipMissingFile); + redirectedFile.insert(tmp.begin(), tmp.end()); redirectUsed = true; continue; } @@ -73,18 +75,21 @@ void ConfigUtility::Load(std::string fname, int argc, char* argv[]) { //finally, construct the final config table if (!redirectUsed) { - redirectedFile = Read(fname); + redirectedFile = Read(fname, skipMissingFile); } configMap.insert(cmdLineParams.begin(), cmdLineParams.end()); configMap.insert(redirectedFile.begin(), redirectedFile.end()); } -ConfigUtility::table_t ConfigUtility::Read(std::string fname) { +ConfigUtility::table_t ConfigUtility::Read(std::string fname, bool skipMissingFile) { //read in and return this file's data table_t retTable; std::ifstream is(fname); if (!is.is_open()) { + if (skipMissingFile) { + return {}; //empty table + } std::ostringstream os; os << "Failed to open a config file: " << fname; throw(std::runtime_error( os.str() )); @@ -143,7 +148,7 @@ ConfigUtility::table_t ConfigUtility::Read(std::string fname) { //load in any subordinate config files if (retTable.find("config.next") != retTable.end()) { - table_t subTable = Read(retTable["config.next"]); + table_t subTable = Read(retTable["config.next"], skipMissingFile); retTable.insert(subTable.begin(), subTable.end()); } diff --git a/common/utilities/config_utility.hpp b/common/utilities/config_utility.hpp index 0f97dbd..a63ed17 100644 --- a/common/utilities/config_utility.hpp +++ b/common/utilities/config_utility.hpp @@ -27,9 +27,9 @@ #include #include -class ConfigUtility : public Singleton { +class ConfigUtility: public Singleton { public: - void Load(std::string fname, int argc = 0, char* argv[] = nullptr); + void Load(std::string fname, bool skipMissingFile = false, int argc = 0, char* argv[] = nullptr); //convert to a type std::string& String(std::string); @@ -47,10 +47,7 @@ private: friend Singleton; - ConfigUtility() = default; - ~ConfigUtility() = default; - - table_t Read(std::string fname); + table_t Read(std::string fname, bool skipMissingFile); table_t configMap; }; diff --git a/server/server_logic.cpp b/server/server_logic.cpp index 0fc2fe5..df88632 100644 --- a/server/server_logic.cpp +++ b/server/server_logic.cpp @@ -43,7 +43,7 @@ void ServerApplication::Init(int argc, char* argv[]) { std::cout << "Beginning " << argv[0] << std::endl; //load the config settings - config.Load("rsc/config.cfg", argc, argv); + config.Load("rsc/config.cfg", false, argc, argv); //------------------------- //Initialize the APIs