Skip to content

Commit a059b36

Browse files
committed
2 parents eac641b + 9ddc116 commit a059b36

File tree

8 files changed

+110
-51
lines changed

8 files changed

+110
-51
lines changed

Application/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ all: lib/libMyTools.so lib/libToolChain.so lib/libStore.so include/Tool.h lib/li
2020

2121
main: src/main.cpp lib/libStore.so lib/libLogging.so lib/libToolChain.so | lib/libMyTools.so lib/libDataModel.so
2222
@echo -e "\e[38;5;214m\n*************** Making " $@ "****************\e[0m"
23-
g++ $(CXXFLAGS) src/main.cpp -o main -I include -L lib -lStore -lMyTools -lToolChain -lDataModel -lLogging -lpthread $(DataModelInclude) $(MyToolsInclude) $(MyToolsLib) $(DataModelib)
23+
g++ $(CXXFLAGS) src/main.cpp -o main -I include -L lib -lStore -lMyTools -lToolChain -lDataModel -lLogging -lpthread $(DataModelInclude) $(MyToolsInclude) $(MyToolsLib) $(DataModelLib)
2424

2525

2626
lib/libStore.so: $(Dependencies)/ToolFrameworkCore/src/Store/*

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ UserTools/Factory/Factory.o: UserTools/Factory/Factory.cpp lib/libStore.so inclu
7272
@echo -e "\e[38;5;214m\n*************** Making " $@ "****************\e[0m"
7373
cp UserTools/Factory/Factory.h include
7474
cp UserTools/Unity.h include
75-
-g++ $(CXXFLAGS) -c -o $@ $< -I include -L lib -lStore -lDataModel -lLogging $(MyToolsInclude) $(MyToolsLib) $(DataModelInclude) $(DataModelib)
75+
-g++ $(CXXFLAGS) -c -o $@ $< -I include -L lib -lStore -lDataModel -lLogging $(MyToolsInclude) $(MyToolsLib) $(DataModelInclude) $(DataModelLib)
7676

7777

7878
UserTools/%.o: UserTools/%.cpp lib/libStore.so include/Tool.h lib/libLogging.so lib/libDataModel.so | include/Tool.h
7979
@echo -e "\e[38;5;214m\n*************** Making " $@ "****************\e[0m"
8080
cp $(shell dirname $<)/*.h include
81-
-g++ $(CXXFLAGS) -c -o $@ $< -I include -L lib -lStore -lDataModel -lLogging $(MyToolsInclude) $(MyToolsLib) $(DataModelInclude) $(DataModelib)
81+
-g++ $(CXXFLAGS) -c -o $@ $< -I include -L lib -lStore -lDataModel -lLogging $(MyToolsInclude) $(MyToolsLib) $(DataModelInclude) $(DataModelLib)
8282

8383

8484
target: remove $(patsubst %.cpp, %.o, $(wildcard UserTools/$(TOOL)/*.cpp))

configfiles/Dummy/ToolChainConfig

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
#ToolChain dynamic setup file
22

33
##### Runtime Paramiters #####
4-
verbose 9
5-
error_level 0 # 0= do not exit, 1= exit on unhandeled errors only, 2= exit on unhandeled errors and handeled errors
6-
attempt_recover 1
4+
verbose 9 # Verbosity level of ToolChain
5+
error_level 0 # 0= do not exit, 1= exit on unhandeled errors only, 2= exit on unhandeled errors and handeled errors
6+
attempt_recover 1 # 1= will attempt to finalise if an execute fails, 0= will not
77

88
###### Logging #####
9-
log_interactive 1 # Interactive=cout; 0=false, 1= true
10-
log_local 0 # Local = local file log; 0=false, 1= true
11-
log_local_path ./log
12-
log_split_files 0 # seperate output and error log files (named x.o and x.e)
9+
log_interactive 1 # Interactive=cout; 0=false, 1= true
10+
log_local 0 # Local = local file log; 0=false, 1= true
11+
log_local_path ./log # file to store logs to if local is active
12+
log_append_time 0 # append seconds since epoch to filename; 0=false, 1= true
13+
log_split_files 0 # seperate output and error log files (named x.o and x.e); 0=false, 1= true
1314

1415
##### Tools To Add #####
15-
Tools_File configfiles/Dummy/ToolsConfig
16+
Tools_File configfiles/Dummy/ToolsConfig # list of tools to run and their config files
1617

1718
##### Run Type #####
18-
Inline 1
19-
Interactive 0
19+
Inline 1 # number of Execute steps in program, -1 infinite loop that is ended by user
20+
Interactive 0 # set to 1 if you want to run the code interactively

configfiles/template/ToolChainConfig

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
##### Runtime Paramiters #####
44
verbose 1 # Verbosity level of ToolChain
55
error_level 2 # 0= do not exit, 1= exit on unhandeled errors only, 2= exit on unhandeled errors and handeled errors
6-
attempt_recover 1 # 1= will attempt to finalise if an execute fails
6+
attempt_recover 1 # 1= will attempt to finalise if an execute fails, 0= will not
77

88
###### Logging #####
99
log_interactive 1 # Interactive=cout; 0=false, 1= true
1010
log_local 0 # Local = local file log; 0=false, 1= true
1111
log_local_path ./log # file to store logs to if local is active
12-
log_split_files 0 # seperate output and error log files (named x.o and x.e)
12+
log_append_time 0 # append seconds since epoch to filename; 0=false, 1= true
13+
log_split_files 0 # seperate output and error log files (named x.o and x.e); 0=false, 1= true
1314

1415
##### Tools To Add #####
1516
Tools_File configfiles/ToolsConfig # list of tools to run and their config files

src/Store/BStore.cpp

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -672,22 +672,49 @@ void BStore::Remove(std::string key){
672672

673673
void BStore::JsonParser(std::string input){
674674

675+
//need to handel arrays and objects properly
676+
675677
int type=0;
676678
std::string key;
677679
std::string value;
678680

679681
for(std::string::size_type i = 0; i < input.size(); ++i) {
680682

681-
if(input[i]=='\"')type++;
682-
else if(type==1)key+=input[i];
683-
else if(type==3)value+=input[i];
684-
else if(type==4){
685-
type=0;
686-
m_variables[key] << value;
687-
key="";
688-
value="";
689-
}
683+
//std::cout<<"i="<<i<<" , "<<input[i]<<" , type="<<type<<std::endl;
684+
685+
//type 0011112233444444550011112233333333001111223366666665500111122337777777555
686+
// { "key" : "value" , "key" : value , "key" : {......} , "key" : [......] }
687+
688+
// types: 0 - pre key
689+
// 1 - key
690+
// 2 - postkey
691+
// 3 - value
692+
// 4 - string value
693+
// 5 - post value
694+
// 6 - object
695+
// 7 - array
696+
697+
if(input[i]=='\"' && type<5) type++;
698+
else if(type==1) key+=input[i];
699+
else if(input[i]==':' && type==2) type=3;
700+
else if((input[i]==',' || input[i]=='}') && (type==5 || type==3)){
701+
type=0;
702+
//std::cout<<"key="<<key<<" , value="<<value<<std::endl;
703+
m_variables[key] << value;
704+
key="";
705+
value="";
706+
}
707+
else if(type==3 && !(input[i]==' ' || input[i]=='{' || input[i]=='[')) value+=input[i];
708+
else if(type==3 && input[i]=='{'){ value+=input[i]; type=6; }
709+
else if(type==6 && input[i]=='}'){ value+=input[i]; type=5; }
710+
else if(type==3 && input[i]=='['){ value+=input[i]; type=7; }
711+
else if(type==7 && input[i]==']'){ value+=input[i]; type=5; }
712+
else if(type==4 || type==6 || type==7) value+=input[i];
690713
}
714+
715+
716+
717+
691718
}
692719

693720

src/Store/Store.cpp

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -53,36 +53,46 @@ void Store::Delete(){
5353
void Store::JsonParser(std::string input){
5454

5555
int type=0;
56-
std::string key;
57-
std::string value;
56+
std::string key="";
57+
std::string value="";
5858

5959
for(std::string::size_type i = 0; i < input.size(); ++i) {
60-
61-
if(input[i]=='\"')type++;
62-
else if(type==1)key+=input[i];
63-
else if(type==3)value+=input[i];
64-
else if(type==4){
65-
type=0;
66-
m_variables[key]=value;
67-
key="";
68-
value="";
69-
}
70-
71-
72-
/*
73-
if(input[i]!=',' && input[i]!='{' && input[i]!='}' && input[i]!='\"' && input[i]!=':' && input[i]!=',')pair<<input[i];
74-
else if(input[i]==':')pair<<" ";
75-
else if(input[i]==',') {
76-
std::cout<<" i = "<<i<<" pair = "<<pair<<std::endl;
77-
78-
pair>>key>>value;
79-
*/
80-
//pair.clear();
81-
82-
//}
60+
61+
//std::cout<<"i="<<i<<" , "<<input[i]<<" , type="<<type<<std::endl;
62+
63+
//type 0011112233444444550011112233333333001111223366666665500111122337777777555
64+
// { "key" : "value" , "key" : value , "key" : {......} , "key" : [......] }
65+
66+
// types: 0 - pre key
67+
// 1 - key
68+
// 2 - postkey
69+
// 3 - value
70+
// 4 - string value
71+
// 5 - post value
72+
// 6 - object
73+
// 7 - array
74+
75+
if(input[i]=='\"' && type<5) type++;
76+
else if(type==1) key+=input[i];
77+
else if(input[i]==':' && type==2) type=3;
78+
else if((input[i]==',' || input[i]=='}') && (type==5 || type==3)){
79+
type=0;
80+
//std::cout<<"key="<<key<<" , value="<<value<<std::endl;
81+
m_variables[key]=value;
82+
key="";
83+
value="";
84+
}
85+
else if(type==3 && !(input[i]==' ' || input[i]=='{' || input[i]=='[')) value+=input[i];
86+
else if(type==3 && input[i]=='{'){ value+=input[i]; type=6; }
87+
else if(type==6 && input[i]=='}'){ value+=input[i]; type=5; }
88+
else if(type==3 && input[i]=='['){ value+=input[i]; type=7; }
89+
else if(type==7 && input[i]==']'){ value+=input[i]; type=5; }
90+
else if(type==4 || type==6 || type==7) value+=input[i];
8391
}
84-
92+
8593
}
94+
95+
8696

8797
bool Store::Has(std::string key){
8898

src/Tool/Tool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
class Tool{
1919

2020
public:
21-
21+
Tool(){};
2222
virtual bool Initialise(std::string configfile,DataModel &data)=0; ///< virtual Initialise function that reads in the assigned config file and optain DataMoodel reference @param configfile Path and name of config file to read in. @param data Reference to DataModel.
2323
virtual bool Execute()=0; ///< Virtual Execute function.
2424
virtual bool Finalise()=0; ///< Virtual Finalise function.

src/ToolChain/ToolChain.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ ToolChain::ToolChain(std::string configfile, int argc, char* argv[]){
1717
if(!m_data->vars.Get("log_local",m_log_local)) m_log_local=false;
1818
if(!m_data->vars.Get("log_split_files",m_log_split_files)) m_log_split_files=false;
1919
if(!m_data->vars.Get("log_local_path",m_log_local_path)) m_log_local_path="./log";
20+
bool log_append_time=false;
21+
m_data->vars.Get("log_append_time", log_append_time);
22+
if(log_append_time){
23+
std::stringstream tmp;
24+
tmp<<m_log_local_path<<"."<<time(NULL);
25+
m_log_local_path= tmp.str();
26+
}
27+
2028

2129
if(!m_data->vars.Get("Inline",m_inline)) m_inline=1;
2230
if(!m_data->vars.Get("Interactive",m_interactive)) m_interactive=false;
@@ -129,6 +137,10 @@ int ToolChain::Initialise(){
129137

130138
#ifndef DEBUG
131139
}
140+
catch(std::exception& e){
141+
*m_log<<MsgL(0,m_verbose)<<red<<e.what()<<"\n"<<std::endl;
142+
throw;
143+
}
132144
catch(...){
133145
*m_log<<MsgL(0,m_verbose)<<red<<"WARNING !!!!! "<<m_toolnames.at(i)<<" Failed to initialise (uncaught error)\n"<<std::endl;
134146
result=2;
@@ -204,6 +216,10 @@ int ToolChain::Execute(int repeates){
204216
#ifndef DEBUG
205217
}
206218

219+
catch(std::exception& e){
220+
*m_log<<MsgL(0,m_verbose)<<red<<e.what()<<"\n"<<std::endl;
221+
throw;
222+
}
207223
catch(...){
208224
*m_log<<MsgL(0,m_verbose)<<red<<"WARNING !!!!!! "<<m_toolnames.at(i)<<" Failed to execute (uncaught error)\n"<<std::endl;
209225

@@ -263,6 +279,10 @@ int ToolChain::Finalise(){
263279
#ifndef DEBUG
264280
}
265281

282+
catch(std::exception& e){
283+
*m_log<<MsgL(0,m_verbose)<<red<<e.what()<<"\n"<<std::endl;
284+
throw;
285+
}
266286
catch(...){
267287
*m_log<<MsgL(0,m_verbose)<<red<<"WARNING !!!!!!! "<<m_toolnames.at(i)<<" Finalised successfully (uncaught error)\n"<<std::endl;
268288

0 commit comments

Comments
 (0)