1
0
mirror of https://github.com/paboyle/Grid.git synced 2025-04-11 14:40:46 +01:00

Serial IO code cleaning for std:: convention

This commit is contained in:
Antonin Portelli 2018-03-27 17:11:50 +01:00
parent 8a0cf0194f
commit 5ec903044d
4 changed files with 31 additions and 35 deletions

View File

@ -29,15 +29,14 @@ Author: paboyle <paboyle@ph.ed.ac.uk>
#include <Grid/GridCore.h> #include <Grid/GridCore.h>
using namespace Grid; using namespace Grid;
using namespace std;
// Writer implementation /////////////////////////////////////////////////////// // Writer implementation ///////////////////////////////////////////////////////
BinaryWriter::BinaryWriter(const string &fileName) BinaryWriter::BinaryWriter(const std::string &fileName)
: file_(fileName, ios::binary|ios::out) : file_(fileName, std::ios::binary|std::ios::out)
{} {}
template <> 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(); 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); writeDefault(s, sx);
} }
// Reader implementation /////////////////////////////////////////////////////// // Reader implementation ///////////////////////////////////////////////////////
BinaryReader::BinaryReader(const string &fileName) BinaryReader::BinaryReader(const std::string &fileName)
: file_(fileName, ios::binary|ios::in) : file_(fileName, std::ios::binary|std::ios::in)
{} {}
template <> template <>
void BinaryReader::readDefault(const string &s, string &output) void BinaryReader::readDefault(const std::string &s, std::string &output)
{ {
uint64_t sz; uint64_t sz;

View File

@ -28,11 +28,10 @@
#include <Grid/Grid.h> #include <Grid/Grid.h>
using namespace Grid; using namespace Grid;
using namespace std;
// Writer implementation /////////////////////////////////////////////////////// // Writer implementation ///////////////////////////////////////////////////////
JSONWriter::JSONWriter(const string &fileName) JSONWriter::JSONWriter(const std::string &fileName)
: fileName_(fileName), ss_("{ ", ostringstream::ate){} : fileName_(fileName), ss_("{ ", std::ostringstream::ate){}
JSONWriter::~JSONWriter(void) JSONWriter::~JSONWriter(void)
{ {
@ -46,7 +45,7 @@ JSONWriter::~JSONWriter(void)
os << std::setw(2) << json::parse(ss_.str()) << std::endl; 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 // adding a nested object
if (s.size()) if (s.size())
@ -90,7 +89,7 @@ namespace Grid
// Reader implementation /////////////////////////////////////////////////////// // Reader implementation ///////////////////////////////////////////////////////
JSONReader::JSONReader(const string &fileName) JSONReader::JSONReader(const std::string &fileName)
: fileName_(fileName) : fileName_(fileName)
{ {
std::ifstream file(fileName_); std::ifstream file(fileName_);
@ -102,7 +101,7 @@ JSONReader::JSONReader(const string &fileName)
jcur_ = jobject_; jcur_ = jobject_;
} }
bool JSONReader::push(const string &s) bool JSONReader::push(const std::string &s)
{ {
if (s.size()){ if (s.size()){
jold_.push_back(jcur_); jold_.push_back(jcur_);
@ -159,7 +158,7 @@ bool JSONReader::nextElement(const std::string &s)
} }
template <> 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; //cout << "JSONReader::readDefault(string) : " << s<< " " << jcur_ << endl;
if (s.size()){ if (s.size()){

View File

@ -30,17 +30,16 @@
#include <Grid/GridCore.h> #include <Grid/GridCore.h>
using namespace Grid; using namespace Grid;
using namespace std;
#define GRID_TEXT_INDENT 2 //number of spaces for indentation of levels #define GRID_TEXT_INDENT 2 //number of spaces for indentation of levels
// Writer implementation /////////////////////////////////////////////////////// // Writer implementation ///////////////////////////////////////////////////////
TextWriter::TextWriter(const string &fileName) TextWriter::TextWriter(const std::string &fileName)
: file_(fileName, ios::out) : file_(fileName, std::ios::out)
{} {}
void TextWriter::push(const string &s) void TextWriter::push(const std::string &s)
{ {
level_++; level_++;
}; };
@ -58,16 +57,16 @@ void TextWriter::indent(void)
}; };
// Reader implementation /////////////////////////////////////////////////////// // 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()) { if (!file_.is_open()) {
std::cout << GridLogMessage << "TextReader: Error opening file " << fileName << std::endl; std::cout << GridLogMessage << "TextReader: Error opening file " << fileName << std::endl;
exit(1);// write better error handling exit(1);// write better error handling
} }
} }
bool TextReader::push(const string &s) bool TextReader::push(const std::string &s)
{ {
level_++; level_++;
return true; return true;
@ -91,7 +90,7 @@ void TextReader::checkIndent(void)
} }
if (!check) if (!check)
{ {
cerr << "TextReader: mismatch on level " << level_ << std::endl; std::cerr << "TextReader: mismatch on level " << level_ << std::endl;
exit(1); exit(1);
} }
} }

View File

@ -29,10 +29,9 @@ Author: paboyle <paboyle@ph.ed.ac.uk>
#include <Grid/GridCore.h> #include <Grid/GridCore.h>
using namespace Grid; using namespace Grid;
using namespace std;
// Writer implementation /////////////////////////////////////////////////////// // 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("") ) { if ( toplev == std::string("") ) {
node_=doc_; node_=doc_;
@ -49,7 +48,7 @@ XmlWriter::~XmlWriter(void)
} }
} }
void XmlWriter::push(const string &s) void XmlWriter::push(const std::string &s)
{ {
node_ = node_.append_child(s.c_str()); node_ = node_.append_child(s.c_str());
} }
@ -65,13 +64,13 @@ std::string XmlWriter::XmlString(void)
return oss.str(); 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; pugi::xml_parse_result result;
result = doc_.load_string(xmlstring); result = doc_.load_string(xmlstring);
if ( !result ) { if ( !result ) {
cerr << "XML error description (from char *): " << result.description() << "\nXML\n"<< xmlstring << "\n"; std::cerr << "XML error description (from char *): " << result.description() << "\nXML\n"<< xmlstring << "\n";
cerr << "XML error offset (from char *) " << result.offset << "\nXML\n"<< xmlstring <<"\n"; std::cerr << "XML error offset (from char *) " << result.offset << "\nXML\n"<< xmlstring <<"\n";
abort(); abort();
} }
if ( toplev == std::string("") ) { if ( toplev == std::string("") ) {
@ -82,13 +81,13 @@ XmlReader::XmlReader(const char *xmlstring,string toplev) : fileName_("")
} }
// Reader implementation /////////////////////////////////////////////////////// // 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; pugi::xml_parse_result result;
result = doc_.load_file(fileName_.c_str()); result = doc_.load_file(fileName_.c_str());
if ( !result ) { if ( !result ) {
cerr << "XML error description: " << result.description() <<" "<< fileName_ <<"\n"; std::cerr << "XML error description: " << result.description() <<" "<< fileName_ <<"\n";
cerr << "XML error offset : " << result.offset <<" "<< fileName_ <<"\n"; std::cerr << "XML error offset : " << result.offset <<" "<< fileName_ <<"\n";
abort(); abort();
} }
if ( toplev == std::string("") ) { if ( toplev == std::string("") ) {
@ -98,7 +97,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())) if (node_.child(s.c_str()))
{ {
@ -133,7 +132,7 @@ bool XmlReader::nextElement(const std::string &s)
} }
template <> 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())) if (node_.child(s.c_str()))
{ {