Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/Logging/Logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ int Logging::MyStreamBuf::sync ( )


if(m_mode=="Local"){
output<< "{"<<t<<"} ["<<m_messagelevel<<"]: " << str();
//output<< "{"<<t<<"} ["<<m_messagelevel<<"]: " << str();
output<<str();
str("");
output.flush();

Expand All @@ -65,7 +66,8 @@ int Logging::MyStreamBuf::sync ( )

output<<"\033[38;5;"<<code<<"m["<<m_messagelevel<<"]: " << str()<<"\033[0m";
*/
output<<"["<<m_messagelevel<<"]: " << str();
//output<<"["<<m_messagelevel<<"]: " << str();
output<<str();
str("");
output.flush();
}
Expand All @@ -85,6 +87,6 @@ bool Logging::MyStreamBuf::ChangeOutFile(std::string localpath){
psbuf = file.rdbuf();
output.rdbuf(psbuf);
}

return true;
}

1 change: 1 addition & 0 deletions src/Logging/Logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ class Logging: public std::ostream {
Logging& operator<<(std::ostream& (*foo)(std::ostream&)) {

std::cout<<plain<<std::endl;
return *this;

}

Expand Down
18 changes: 15 additions & 3 deletions src/Store/BStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ bool BStore::Initnew(std::string filename, enum_type type, bool header, bool typ
}

m_update=false;

return true;
}

/*
Expand Down Expand Up @@ -380,9 +380,9 @@ bool BStore::Close(){
}
//importing

bool BStore::Print(){ Print(false);}
bool BStore::Print(){ Print(false); return true;}

void BStore::Print(bool values){
bool BStore::Print(bool values){

for (std::map<std::string,BinaryStream>::iterator it=m_variables.begin(); it!=m_variables.end(); ++it){

Expand All @@ -400,6 +400,18 @@ void BStore::Print(bool values){
}
}

return true;
}

std::vector<std::string> BStore::GetKeys(){
std::vector<std::string> keys;
for (std::map<std::string,BinaryStream>::iterator it=m_variables.begin(); it!=m_variables.end(); ++it){
keys.push_back(it->first);
}
for (std::map<std::string,PointerWrapperBase*>::iterator it=m_ptrs.begin(); it!=m_ptrs.end(); ++it){
if(m_variables.count(it->first)==0) keys.push_back(it->first);
}
return keys;
}


Expand Down
8 changes: 5 additions & 3 deletions src/Store/BStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class BStore: public SerialisableObject{
bool WriteFlags();
bool Save(unsigned int entry=-1);
bool GetHeader();
std::vector<std::string> GetKeys();
bool GetEntry(unsigned int entry_request);
bool DeleteEntry(unsigned int entry_request);
bool Close();
Expand All @@ -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.
Expand Down Expand Up @@ -101,12 +102,13 @@ class BStore: public SerialisableObject{

T* tmp=new T;
m_ptrs[name]=new PointerWrapper<T>(tmp);
ret*=Get(name,*tmp);
}


PointerWrapper<T>* tmp=static_cast<PointerWrapper<T>* >(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;

Expand Down
10 changes: 5 additions & 5 deletions src/Store/BinaryStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; i++){
for(unsigned int i=0; i<tmp; i++){
ret*=(*this) << rhs.at(i);
}
return ret;
Expand All @@ -210,7 +210,7 @@ class BinaryStream : public SerialisableObject{
unsigned int tmp=0;
ret*=(*this) >> tmp;
rhs.resize(tmp);
for(int i=0; i<tmp; i++){
for(unsigned int i=0; i<tmp; i++){
ret*=(*this) >> rhs.at(i);
}
return ret;
Expand Down Expand Up @@ -244,7 +244,7 @@ class BinaryStream : public SerialisableObject{
bool ret=true;
unsigned int tmp=0;
ret*=(*this) >> tmp;
for (int i=0; i<tmp; i++){
for (unsigned int i=0; i<tmp; i++){
T key;
U value;
ret*=(*this) >> key;
Expand Down Expand Up @@ -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; i++){
for(unsigned int i=0; i<tmp; i++){
ret*=(*this) << rhs.at(i);
}
return ret;
Expand All @@ -318,7 +318,7 @@ class BinaryStream : public SerialisableObject{
unsigned int tmp=0;
ret*=(*this) >> tmp;
rhs.resize(tmp);
for(int i=0; i<tmp; i++){
for(unsigned int i=0; i<tmp; i++){
ret*=(*this) >> rhs.at(i);
}
return ret;
Expand Down
10 changes: 10 additions & 0 deletions src/Store/Store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,13 @@ bool Store::Has(std::string key){
return (m_variables.count(key)!=0);

}

const std::map<std::string,std::string>* Store::GetMap(){
return &m_variables;
}

bool Store::Erase(std::string key){
if(not Has(key)) return false;
m_variables.erase(key);
return true;
}
35 changes: 34 additions & 1 deletion src/Store/Store.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
#include <map>
#include <iostream>
#include <sstream>
#include <typeinfo>
#include <cstring>
#include <cstdlib>

/**
* \class Store
Expand All @@ -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); ///<Returns bool based on if store contains entry given by sting @param string key to comapre.
const std::map<std::string,std::string>* GetMap();
bool Erase(std::string key); ///<Erase the element from the store, if it exists

/**
Templated getter function for tore content. Assignment is templated and via reference.
Expand All @@ -42,7 +47,35 @@ class Store{

std::stringstream stream(m_variables[name]);
stream>>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;
Expand Down
11 changes: 8 additions & 3 deletions src/Tool/Tool.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class Tool{
virtual bool Finalise()=0; ///< Virtual Finalise function.
virtual ~Tool(){}; ///< virtual destructor.

std::string m_unique_name;

protected:

Store m_variables; ///< Store used to store configuration varaibles
Expand All @@ -35,13 +37,16 @@ class Tool{
template <typename T> void Log(T message, int messagelevel=1, int verbosity=1){m_data->Log->Log(message,messagelevel,verbosity);}
template <typename T> 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
16 changes: 14 additions & 2 deletions src/ToolChain/ToolChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -179,7 +180,11 @@ int ToolChain::Initialise(){

#ifndef DEBUG
}
catch(...){
catch(std::exception& e){
logmessage <<e.what()<<std::endl;
throw;
}
catch(...){
logmessage<<red<<"WARNING !!!!! "<<m_toolnames.at(i)<<" Failed to initialise (uncaught error)"<<plain<<std::endl;
m_data.Log->Log( logmessage.str(),0,m_verbose);
logmessage.str("");
Expand Down Expand Up @@ -277,7 +282,10 @@ int ToolChain::Execute(int repeates){

#ifndef DEBUG
}

catch(std::exception& e){
logmessage<<e.what()<<std::endl;
throw;
}
catch(...){
logmessage<<red<<"WARNING !!!!!! "<<m_toolnames.at(i)<<" Failed to execute (uncaught error)"<<plain<<std::endl;
m_data.Log->Log( logmessage.str(),0,m_verbose);
Expand Down Expand Up @@ -357,6 +365,10 @@ int ToolChain::Finalise(){
#ifndef DEBUG
}

catch(std::exception& e){
logmessage<<e.what()<<std::endl;
throw;
}
catch(...){
logmessage<<red<<"WARNING !!!!!!! "<<m_toolnames.at(i)<<" Finalised successfully (uncaught error)"<<plain<<std::endl;
m_data.Log->Log( logmessage.str(),0,m_verbose);
Expand Down