diff --git a/lib/serialisation/BinaryIO.cc b/lib/serialisation/BinaryIO.cc index 7133adc0..8ddf3c6c 100644 --- a/lib/serialisation/BinaryIO.cc +++ b/lib/serialisation/BinaryIO.cc @@ -28,16 +28,15 @@ Author: paboyle /* END LEGAL */ #include -using namespace Grid; -using namespace std; +NAMESPACE_BEGIN(Grid); // Writer implementation /////////////////////////////////////////////////////// -BinaryWriter::BinaryWriter(const string &fileName) -: file_(fileName, ios::binary|ios::out) +BinaryWriter::BinaryWriter(const std::string &fileName) +: file_(fileName, std::ios::binary|std::ios::out) {} template <> -void BinaryWriter::writeDefault(const string &s, const string &x) +void BinaryWriter::writeDefault(const std::string &s, const std::string &x) { uint64_t sz = x.size(); @@ -48,20 +47,20 @@ void BinaryWriter::writeDefault(const string &s, const string &x) } } -void BinaryWriter::writeDefault(const string &s, const char *x) +void BinaryWriter::writeDefault(const std::string &s, const char *x) { - string sx(x); + std::string sx(x); writeDefault(s, sx); } // Reader implementation /////////////////////////////////////////////////////// -BinaryReader::BinaryReader(const string &fileName) -: file_(fileName, ios::binary|ios::in) +BinaryReader::BinaryReader(const std::string &fileName) +: file_(fileName, std::ios::binary|std::ios::in) {} template <> -void BinaryReader::readDefault(const string &s, string &output) +void BinaryReader::readDefault(const std::string &s, std::string &output) { uint64_t sz; @@ -69,3 +68,5 @@ void BinaryReader::readDefault(const string &s, string &output) output.resize(sz); file_.read((char *)output.data(), sz); } + +NAMESPACE_END(Grid); diff --git a/lib/serialisation/BinaryIO.h b/lib/serialisation/BinaryIO.h index 9cc65aa9..2c3ac98f 100644 --- a/lib/serialisation/BinaryIO.h +++ b/lib/serialisation/BinaryIO.h @@ -93,15 +93,14 @@ void BinaryWriter::writeDefault(const std::string &s, const std::vector &x) } // Reader template implementation //////////////////////////////////////////// +template <> void BinaryReader::readDefault(const std::string &s, std::string &output); + template void BinaryReader::readDefault(const std::string &s, U &output) { file_.read((char *)&output, sizeof(U)); } -template <> -void BinaryReader::readDefault(const std::string &s, std::string &output); - template void BinaryReader::readDefault(const std::string &s, std::vector &output) { diff --git a/lib/serialisation/JSON_IO.cc b/lib/serialisation/JSON_IO.cc index 6a01aa84..2ca6a499 100644 --- a/lib/serialisation/JSON_IO.cc +++ b/lib/serialisation/JSON_IO.cc @@ -27,12 +27,11 @@ /* END LEGAL */ #include -using namespace Grid; -using namespace std; +NAMESPACE_BEGIN(Grid); // Writer implementation /////////////////////////////////////////////////////// -JSONWriter::JSONWriter(const string &fileName) -: fileName_(fileName), ss_("{ ", ostringstream::ate){} +JSONWriter::JSONWriter(const std::string &fileName) +: fileName_(fileName), ss_("{ ", std::ostringstream::ate){} JSONWriter::~JSONWriter(void) { @@ -46,7 +45,7 @@ JSONWriter::~JSONWriter(void) os << std::setw(2) << json::parse(ss_.str()) << std::endl; } -void JSONWriter::push(const string &s) +void JSONWriter::push(const std::string &s) { // adding a nested object if (s.size()) @@ -74,23 +73,19 @@ void JSONWriter::delete_comma() // compiles fine with clang // have to wrap in the Grid namespace // annoying, but necessary for TravisCI -namespace Grid +void JSONWriter::writeDefault(const std::string &s, const std::string &x) { - void JSONWriter::writeDefault(const std::string &s, const std::string &x) - { //std::cout << "JSONWriter::writeDefault(string) : " << s << std::endl; - std::ostringstream os; - os << std::boolalpha << x; - if (s.size()) - ss_ << "\""<< s << "\" : \"" << os.str() << "\" ," ; - else - ss_ << os.str() << " ," ; - } -}// namespace Grid - + std::ostringstream os; + os << std::boolalpha << x; + if (s.size()) + ss_ << "\""<< s << "\" : \"" << os.str() << "\" ," ; + else + ss_ << os.str() << " ," ; +} // Reader implementation /////////////////////////////////////////////////////// -JSONReader::JSONReader(const string &fileName) +JSONReader::JSONReader(const std::string &fileName) : fileName_(fileName) { std::ifstream file(fileName_); @@ -102,7 +97,7 @@ JSONReader::JSONReader(const string &fileName) jcur_ = jobject_; } -bool JSONReader::push(const string &s) +bool JSONReader::push(const std::string &s) { if (s.size()){ jold_.push_back(jcur_); @@ -152,14 +147,14 @@ bool JSONReader::nextElement(const std::string &s) //} jcur_ = *it_; - //cout << "JSONReader::nextElement(string) : " << s << " : "<< jcur_ << endl; + //cout << "JSONReader::nextElement(std::string) : " << s << " : "<< jcur_ << endl; //return true; return false; } template <> -void JSONReader::readDefault(const string &s, string &output) +void JSONReader::readDefault(const std::string &s, std::string &output) { //cout << "JSONReader::readDefault(string) : " << s<< " " << jcur_ << endl; if (s.size()){ @@ -172,3 +167,4 @@ void JSONReader::readDefault(const string &s, string &output) output = jcur_; } } +NAMESPACE_END(Grid); diff --git a/lib/serialisation/MacroMagic.h b/lib/serialisation/MacroMagic.h index 5df2c780..279c1db5 100644 --- a/lib/serialisation/MacroMagic.h +++ b/lib/serialisation/MacroMagic.h @@ -42,8 +42,6 @@ THE SOFTWARE. */ /////////////////////////////////////////// -#define strong_inline __attribute__((always_inline)) inline - #ifndef MAX #define MAX(x,y) ((x)>(y)?(x):(y)) #define MIN(x,y) ((x)>(y)?(y):(x)) diff --git a/lib/serialisation/TextIO.cc b/lib/serialisation/TextIO.cc index 5e27dfbc..4e71adf6 100644 --- a/lib/serialisation/TextIO.cc +++ b/lib/serialisation/TextIO.cc @@ -29,18 +29,16 @@ /* END LEGAL */ #include -using namespace Grid; -using namespace std; +//using namespace Grid; +//using namespace std; #define GRID_TEXT_INDENT 2 //number of spaces for indentation of levels +NAMESPACE_BEGIN(Grid); // Writer implementation /////////////////////////////////////////////////////// -TextWriter::TextWriter(const string &fileName) -: file_(fileName, ios::out) -{} -void TextWriter::push(const string &s) +void TextWriter::push(const std::string &s) { level_++; }; @@ -58,16 +56,16 @@ void TextWriter::indent(void) }; // Reader implementation /////////////////////////////////////////////////////// -TextReader::TextReader(const string &fileName) +TextReader::TextReader(const std::string &fileName) { - file_.open(fileName, ios::in); + file_.open(fileName, std::ios::in); if (!file_.is_open()) { std::cout << GridLogMessage << "TextReader: Error opening file " << fileName << std::endl; exit(1);// write better error handling } } -bool TextReader::push(const string &s) +bool TextReader::push(const std::string &s) { level_++; return true; @@ -91,7 +89,7 @@ void TextReader::checkIndent(void) } if (!check) { - cerr << "TextReader: mismatch on level " << level_ << std::endl; + std::cerr << "TextReader: mismatch on level " << level_ << std::endl; exit(1); } } @@ -100,7 +98,9 @@ void TextReader::checkIndent(void) template <> void TextReader::readDefault(const std::string &s, std::string &output) { - checkIndent(); - output.clear(); - getline(file_, output); + checkIndent(); + output.clear(); + getline(file_, output); } + +NAMESPACE_END(Grid); diff --git a/lib/serialisation/TextIO.h b/lib/serialisation/TextIO.h index ada1aaf6..dd788d84 100644 --- a/lib/serialisation/TextIO.h +++ b/lib/serialisation/TextIO.h @@ -43,7 +43,7 @@ namespace Grid class TextWriter: public Writer { public: - TextWriter(const std::string &fileName); + TextWriter(const std::string &fileName) : file_(fileName, std::ios::out) {}; virtual ~TextWriter(void) = default; void push(const std::string &s); void pop(void); @@ -65,10 +65,8 @@ namespace Grid virtual ~TextReader(void) = default; bool push(const std::string &s); void pop(void); - template - void readDefault(const std::string &s, U &output); - template - void readDefault(const std::string &s, std::vector &output); + template void readDefault(const std::string &s, U &output); + template void readDefault(const std::string &s, std::vector &output); private: void checkIndent(void); private: @@ -97,6 +95,8 @@ namespace Grid } // Reader template implementation //////////////////////////////////////////// + template <> void TextReader::readDefault(const std::string &s, std::string &output); + template void TextReader::readDefault(const std::string &s, U &output) { @@ -106,8 +106,6 @@ namespace Grid fromString(output, buf); } - template <> - void TextReader::readDefault(const std::string &s, std::string &output); template void TextReader::readDefault(const std::string &s, std::vector &output) diff --git a/lib/serialisation/XmlIO.cc b/lib/serialisation/XmlIO.cc index 8ac7422c..6db9439a 100644 --- a/lib/serialisation/XmlIO.cc +++ b/lib/serialisation/XmlIO.cc @@ -28,11 +28,13 @@ Author: paboyle /* END LEGAL */ #include -using namespace Grid; -using namespace std; +//using namespace Grid; +//using namespace std; + +NAMESPACE_BEGIN(Grid); // Writer implementation /////////////////////////////////////////////////////// -XmlWriter::XmlWriter(const string &fileName, string toplev) : fileName_(fileName) +XmlWriter::XmlWriter(const std::string &fileName, std::string toplev) : fileName_(fileName) { if ( toplev == std::string("") ) { node_=doc_; @@ -49,7 +51,7 @@ XmlWriter::~XmlWriter(void) } } -void XmlWriter::push(const string &s) +void XmlWriter::push(const std::string &s) { node_ = node_.append_child(s.c_str()); } @@ -65,14 +67,14 @@ std::string XmlWriter::XmlString(void) return oss.str(); } -XmlReader::XmlReader(const char *xmlstring,string toplev) : fileName_("") +XmlReader::XmlReader(const char *xmlstring,std::string toplev) : fileName_("") { pugi::xml_parse_result result; result = doc_.load_string(xmlstring); if ( !result ) { - cerr << "XML error description (from char *): " << result.description() << "\nXML\n"<< xmlstring << "\n"; - cerr << "XML error offset (from char *) " << result.offset << "\nXML\n"<< xmlstring <<"\n"; - abort(); + std::cerr << "XML error description (from char *): " << result.description() << "\nXML\n"<< xmlstring << "\n"; + std::cerr << "XML error offset (from char *) " << result.offset << "\nXML\n"<< xmlstring <<"\n"; + std::abort(); } if ( toplev == std::string("") ) { node_ = doc_; @@ -82,14 +84,14 @@ XmlReader::XmlReader(const char *xmlstring,string toplev) : fileName_("") } // Reader implementation /////////////////////////////////////////////////////// -XmlReader::XmlReader(const string &fileName,string toplev) : fileName_(fileName) +XmlReader::XmlReader(const std::string &fileName,std::string toplev) : fileName_(fileName) { pugi::xml_parse_result result; result = doc_.load_file(fileName_.c_str()); if ( !result ) { - cerr << "XML error description: " << result.description() <<" "<< fileName_ <<"\n"; - cerr << "XML error offset : " << result.offset <<" "<< fileName_ <<"\n"; - abort(); + std::cerr << "XML error description: " << result.description() <<" "<< fileName_ <<"\n"; + std::cerr << "XML error offset : " << result.offset <<" "<< fileName_ <<"\n"; + std::abort(); } if ( toplev == std::string("") ) { node_ = doc_; @@ -98,7 +100,7 @@ XmlReader::XmlReader(const string &fileName,string toplev) : fileName_(fileName) } } -bool XmlReader::push(const string &s) +bool XmlReader::push(const std::string &s) { if (node_.child(s.c_str())) { @@ -133,7 +135,7 @@ bool XmlReader::nextElement(const std::string &s) } template <> -void XmlReader::readDefault(const string &s, string &output) +void XmlReader::readDefault(const std::string &s, std::string &output) { if (node_.child(s.c_str())) { @@ -147,3 +149,4 @@ void XmlReader::readDefault(const string &s, string &output) output = ""; } } +NAMESPACE_END(Grid); diff --git a/lib/serialisation/XmlIO.h b/lib/serialisation/XmlIO.h index e37eb8d9..b1d84fbf 100644 --- a/lib/serialisation/XmlIO.h +++ b/lib/serialisation/XmlIO.h @@ -73,8 +73,7 @@ namespace Grid bool nextElement(const std::string &s); template void readDefault(const std::string &s, U &output); - template - void readDefault(const std::string &s, std::vector &output); + template void readDefault(const std::string &s, std::vector &output); private: pugi::xml_document doc_; pugi::xml_node node_; @@ -114,6 +113,7 @@ namespace Grid } // Reader template implementation //////////////////////////////////////////// + template <> void XmlReader::readDefault(const std::string &s, std::string &output); template void XmlReader::readDefault(const std::string &s, U &output) { @@ -123,9 +123,6 @@ namespace Grid fromString(output, buf); } - template <> - void XmlReader::readDefault(const std::string &s, std::string &output); - template void XmlReader::readDefault(const std::string &s, std::vector &output) {