Skip to content

Commit 01d76a1

Browse files
marc1ukMarcus O'Flahertybrichards64
authored
add insertion operator << definition to Store class (#26)
* add insertion operator << definition to Store class * Update Store.cpp * second comma update --------- Co-authored-by: Marcus O'Flaherty <moflaherty1@sheffield.ac.uk> Co-authored-by: brichards64 <benjamin.richards@warwick.ac.uk>
1 parent 3d0f9c2 commit 01d76a1

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

src/Store/Store.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "Store.h"
22

3-
using namespace ToolFramework;
3+
namespace ToolFramework {
44

55
Store::Store(){}
66

@@ -211,3 +211,17 @@ bool Store::Destring(std::string key){
211211
return true;
212212

213213
}
214+
215+
std::ostream& operator<<(std::ostream& stream, const Store& s){
216+
stream<<"{";
217+
bool first=true;
218+
for(auto it=s.m_variables.begin(); it!=s.m_variables.end(); ++it){
219+
if (!first) stream<<", ";
220+
stream<<"\""<<it->first<<"\":"<< it->second;
221+
first=false;
222+
}
223+
stream<<"}";
224+
return stream;
225+
}
226+
227+
}

src/Store/Store.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@ namespace ToolFramework{
204204
stream<<"{";
205205
bool first=true;
206206
for (std::map<std::string,std::string>::iterator it=m_variables.begin(); it!=m_variables.end(); ++it){
207-
if (!first) stream<<",";
208-
stream<<"\""<<it->first<<"\":"<< it->second<<" ";
207+
if (!first) stream<<", ";
208+
stream<<"\""<<it->first<<"\":"<< it->second;
209209

210210
first=false;
211211
}
@@ -215,6 +215,8 @@ namespace ToolFramework{
215215

216216
}
217217

218+
friend std::ostream& operator<<(std::ostream &stream, const Store &s);
219+
218220
std::map<std::string, std::string>::iterator begin() { return m_variables.begin(); }
219221
std::map<std::string, std::string>::iterator end() { return m_variables.end(); }
220222

@@ -227,6 +229,7 @@ namespace ToolFramework{
227229

228230
};
229231

230-
}
232+
} // end ToolFramework namespace
233+
231234

232235
#endif

0 commit comments

Comments
 (0)