From 07bcfd813a9fd9eb8699b5f1100583e0417d7ae5 Mon Sep 17 00:00:00 2001 From: Marcus O'Flaherty Date: Sun, 22 Aug 2021 07:14:29 +0900 Subject: [PATCH 1/5] add GetMap and Erase methods to Store --- src/Store/Store.cpp | 10 ++++++++++ src/Store/Store.h | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/Store/Store.cpp b/src/Store/Store.cpp index e02ed24..56ec330 100644 --- a/src/Store/Store.cpp +++ b/src/Store/Store.cpp @@ -87,3 +87,13 @@ bool Store::Has(std::string key){ return (m_variables.count(key)!=0); } + +const std::map* Store::GetMap(){ + return &m_variables; +} + +bool Store::Erase(std::string key){ + if(not Has(key)) return false; + m_variables.erase(key); + return true; +} diff --git a/src/Store/Store.h b/src/Store/Store.h index aaa2171..6ad11fd 100644 --- a/src/Store/Store.h +++ b/src/Store/Store.h @@ -7,6 +7,9 @@ #include #include #include +#include +#include +#include /** * \class Store @@ -29,6 +32,8 @@ class Store{ void Print(); ///< Prints the contents of the Store. void Delete(); ///< Deletes all entries in the Store. bool Has(std::string key); ///* GetMap(); + bool Erase(std::string key); ///>out; - return !stream.fail(); + + if(stream.fail()) return false; + // the trouble here is that if we have a string "4cds" and stream it into a numeric, + // then stream.fail will be false, but only the leading numeric chars will be output. + // c++11's std::is_arithmetic(T) would be ideal here, but without c++11 we do it the long way... + if(typeid(float).name()==typeid(T).name()){ + char* pEnd; + float f1 = strtof(stream.str().c_str(), &pEnd); + if(strcmp(pEnd,"")!=0) return false; + } else if(typeid(double).name()==typeid(T).name()){ + char* pEnd; + double d1 = strtod(stream.str().c_str(), &pEnd); + if(strcmp(pEnd,"")!=0) return false; + } else if(typeid(T).name()==typeid(short int).name() || + typeid(T).name()==typeid(int).name() || + typeid(T).name()==typeid(long int).name() || +// typeid(T).name()==typeid(long long int).name() || + typeid(T).name()==typeid(unsigned char).name() || + typeid(T).name()==typeid(unsigned short int).name() || + typeid(T).name()==typeid(unsigned int).name() || + typeid(T).name()==typeid(unsigned long int).name()){ +// typeid(T).name()==typeid(unsigned long long int).name()){ + char* pEnd; + long l1 = strtol(stream.str().c_str(), &pEnd,10); + if(strcmp(pEnd,"")!=0) return false; + } + // else the data type we're streaming into is probably a string + // TODO check whether the held value is numeric and warn if so..? + return true; } else return false; From 0dbba2cfd4267e97261362c0e887ec319810313a Mon Sep 17 00:00:00 2001 From: Marcus O'Flaherty Date: Thu, 2 Sep 2021 18:08:35 +0900 Subject: [PATCH 2/5] update heap instance when getting pointer from BStore --- src/Store/BStore.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Store/BStore.h b/src/Store/BStore.h index 311d3b7..10b5622 100644 --- a/src/Store/BStore.h +++ b/src/Store/BStore.h @@ -101,12 +101,13 @@ class BStore: public SerialisableObject{ T* tmp=new T; m_ptrs[name]=new PointerWrapper(tmp); - ret*=Get(name,*tmp); } PointerWrapper* tmp=static_cast* >(m_ptrs[name]); - out=tmp->pointer; + T* internal = tmp->pointer; + ret*=Get(name,*internal); // update internally held item based on Store contents + out=internal; return ret; From 6100b07d8e6bb22f0c5c0b3af40cb8c8a9c64736 Mon Sep 17 00:00:00 2001 From: Marcus O'Flaherty Date: Fri, 30 Jun 2023 18:54:42 +0900 Subject: [PATCH 3/5] fix missing return values, add exception printing to ToolChain, add GetKeys function to BStore --- src/Logging/Logging.cpp | 2 +- src/Logging/Logging.h | 1 + src/Store/BStore.cpp | 18 +++++++++++++++--- src/Store/BStore.h | 3 ++- src/ToolChain/ToolChain.cpp | 15 +++++++++++++-- 5 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/Logging/Logging.cpp b/src/Logging/Logging.cpp index 43e38f6..b20a1fb 100644 --- a/src/Logging/Logging.cpp +++ b/src/Logging/Logging.cpp @@ -85,6 +85,6 @@ bool Logging::MyStreamBuf::ChangeOutFile(std::string localpath){ psbuf = file.rdbuf(); output.rdbuf(psbuf); } - + return true; } diff --git a/src/Logging/Logging.h b/src/Logging/Logging.h index b3bcb88..1f978d4 100644 --- a/src/Logging/Logging.h +++ b/src/Logging/Logging.h @@ -167,6 +167,7 @@ class Logging: public std::ostream { Logging& operator<<(std::ostream& (*foo)(std::ostream&)) { std::cout<::iterator it=m_variables.begin(); it!=m_variables.end(); ++it){ @@ -400,6 +400,18 @@ void BStore::Print(bool values){ } } + return true; +} + +std::vector BStore::GetKeys(){ + std::vector keys; + for (std::map::iterator it=m_variables.begin(); it!=m_variables.end(); ++it){ + keys.push_back(it->first); + } + for (std::map::iterator it=m_ptrs.begin(); it!=m_ptrs.end(); ++it){ + if(m_variables.count(it->first)==0) keys.push_back(it->first); + } + return keys; } diff --git a/src/Store/BStore.h b/src/Store/BStore.h index 10b5622..a9def8f 100644 --- a/src/Store/BStore.h +++ b/src/Store/BStore.h @@ -36,6 +36,7 @@ class BStore: public SerialisableObject{ bool WriteFlags(); bool Save(unsigned int entry=-1); bool GetHeader(); + std::vector GetKeys(); bool GetEntry(unsigned int entry_request); bool DeleteEntry(unsigned int entry_request); bool Close(); @@ -55,7 +56,7 @@ class BStore: public SerialisableObject{ void JsonParser(std::string input); ///< Converts a flat JSON formatted string to Store entries in the form of key value pairs. @param input The input flat JSON string. bool Print(); - void Print(bool values); ///< Prints the contents of the BoostStore. @param values If true values and keys are printed. If false just keys are printed + bool Print(bool values); ///< Prints the contents of the BoostStore. @param values If true values and keys are printed. If false just keys are printed void Delete(); ///< Deletes all entries in the BoostStore. void Remove(std::string key); ///< Removes a single entry from the BoostStore. @param key The key of the entry to remove. std::string Type(std::string key); ///< Queries the type of an entry if type checking is turned on. @param key The key of the entry to check. @return A string encoding the type info. diff --git a/src/ToolChain/ToolChain.cpp b/src/ToolChain/ToolChain.cpp index 5dd78e0..38db995 100644 --- a/src/ToolChain/ToolChain.cpp +++ b/src/ToolChain/ToolChain.cpp @@ -179,7 +179,11 @@ int ToolChain::Initialise(){ #ifndef DEBUG } - catch(...){ + catch(std::exception& e){ + logmessage <Log( logmessage.str(),0,m_verbose); logmessage.str(""); @@ -277,7 +281,10 @@ int ToolChain::Execute(int repeates){ #ifndef DEBUG } - + catch(std::exception& e){ + logmessage<Log( logmessage.str(),0,m_verbose); @@ -357,6 +364,10 @@ int ToolChain::Finalise(){ #ifndef DEBUG } + catch(std::exception& e){ + logmessage<Log( logmessage.str(),0,m_verbose); From dd54eae48fecf5894661d3486189455dab446a72 Mon Sep 17 00:00:00 2001 From: Marcus O'Flaherty Date: Tue, 15 Aug 2023 02:04:01 +0900 Subject: [PATCH 4/5] remove logging verbosity indicator, add verbosity constants --- src/Logging/Logging.cpp | 6 ++++-- src/Tool/Tool.h | 11 ++++++++--- src/ToolChain/ToolChain.cpp | 1 + 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Logging/Logging.cpp b/src/Logging/Logging.cpp index b20a1fb..e4d4851 100644 --- a/src/Logging/Logging.cpp +++ b/src/Logging/Logging.cpp @@ -41,7 +41,8 @@ int Logging::MyStreamBuf::sync ( ) if(m_mode=="Local"){ - output<< "{"< void Log(T message, int messagelevel=1, int verbosity=1){m_data->Log->Log(message,messagelevel,verbosity);} template void Log(T message, int messagelevel){m_data->Log->Log(message,messagelevel,m_verbose);} ///< Logging fuction for printouts. @param message Templated message string. @param messagelevel The verbosity level at which to show the message. Checked against internal verbosity level - + int get_ok; + std::string logmessage; + static const int v_error=0; + static const int v_warning=1; + static const int v_message=2; + static const int v_debug=3; private: - - }; #endif diff --git a/src/ToolChain/ToolChain.cpp b/src/ToolChain/ToolChain.cpp index 38db995..5dc489c 100644 --- a/src/ToolChain/ToolChain.cpp +++ b/src/ToolChain/ToolChain.cpp @@ -126,6 +126,7 @@ void ToolChain::Add(std::string name,Tool *tool,std::string configfile){ m_data.Log->Log(logmessage.str(),1,m_verbose); logmessage.str(""); + tool->m_unique_name = name; m_tools.push_back(tool); m_toolnames.push_back(name); m_configfiles.push_back(configfile); From 47aeec57c325fb453b252ee55d4325ffe97beff9 Mon Sep 17 00:00:00 2001 From: Marcus O'Flaherty Date: Thu, 31 Aug 2023 03:32:01 +0900 Subject: [PATCH 5/5] unsigned vs signed warning fixes --- src/Store/BinaryStream.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Store/BinaryStream.h b/src/Store/BinaryStream.h index 5af2b6c..17cfcc4 100644 --- a/src/Store/BinaryStream.h +++ b/src/Store/BinaryStream.h @@ -196,7 +196,7 @@ class BinaryStream : public SerialisableObject{ bool ret=true; unsigned int tmp=rhs.size(); ret*=(*this) << tmp; - for(int i=0; i> tmp; rhs.resize(tmp); - for(int i=0; i> rhs.at(i); } return ret; @@ -244,7 +244,7 @@ class BinaryStream : public SerialisableObject{ bool ret=true; unsigned int tmp=0; ret*=(*this) >> tmp; - for (int i=0; i> key; @@ -304,7 +304,7 @@ class BinaryStream : public SerialisableObject{ bool ret=true; unsigned int tmp=rhs.size(); ret*=(*this) << tmp; - for(int i=0; i> tmp; rhs.resize(tmp); - for(int i=0; i> rhs.at(i); } return ret;