1
0
mirror of https://github.com/paboyle/Grid.git synced 2024-11-10 07:55:35 +00: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>
using namespace Grid;
using namespace std;
// 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;

View File

@ -28,11 +28,10 @@
#include <Grid/Grid.h>
using namespace Grid;
using namespace std;
// 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())
@ -90,7 +89,7 @@ namespace Grid
// Reader implementation ///////////////////////////////////////////////////////
JSONReader::JSONReader(const string &fileName)
JSONReader::JSONReader(const std::string &fileName)
: fileName_(fileName)
{
std::ifstream file(fileName_);
@ -102,7 +101,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_);
@ -159,7 +158,7 @@ bool JSONReader::nextElement(const std::string &s)
}
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()){

View File

@ -30,17 +30,16 @@
#include <Grid/GridCore.h>
using namespace Grid;
using namespace std;
#define GRID_TEXT_INDENT 2 //number of spaces for indentation of levels
// Writer implementation ///////////////////////////////////////////////////////
TextWriter::TextWriter(const string &fileName)
: file_(fileName, ios::out)
TextWriter::TextWriter(const std::string &fileName)
: file_(fileName, std::ios::out)
{}
void TextWriter::push(const string &s)
void TextWriter::push(const std::string &s)
{
level_++;
};
@ -58,16 +57,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 +90,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);
}
}

View File

@ -29,10 +29,9 @@ Author: paboyle <paboyle@ph.ed.ac.uk>
#include <Grid/GridCore.h>
using namespace Grid;
using namespace std;
// 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 +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());
}
@ -65,13 +64,13 @@ 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";
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";
abort();
}
if ( toplev == std::string("") ) {
@ -82,13 +81,13 @@ 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";
std::cerr << "XML error description: " << result.description() <<" "<< fileName_ <<"\n";
std::cerr << "XML error offset : " << result.offset <<" "<< fileName_ <<"\n";
abort();
}
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()))
{
@ -133,7 +132,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()))
{