1
0
mirror of https://github.com/paboyle/Grid.git synced 2025-04-25 21:25:56 +01:00

Namespace, nvcc warning elimination.

This commit is contained in:
paboyle 2018-01-24 13:14:43 +00:00
parent 87ee592176
commit 22d137d4e5
8 changed files with 67 additions and 75 deletions

View File

@ -28,16 +28,15 @@ Author: paboyle <paboyle@ph.ed.ac.uk>
/* END LEGAL */ /* END LEGAL */
#include <Grid/GridCore.h> #include <Grid/GridCore.h>
using namespace Grid; NAMESPACE_BEGIN(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;
@ -69,3 +68,5 @@ void BinaryReader::readDefault(const string &s, string &output)
output.resize(sz); output.resize(sz);
file_.read((char *)output.data(), sz); file_.read((char *)output.data(), sz);
} }
NAMESPACE_END(Grid);

View File

@ -93,15 +93,14 @@ void BinaryWriter::writeDefault(const std::string &s, const std::vector<U> &x)
} }
// Reader template implementation //////////////////////////////////////////// // Reader template implementation ////////////////////////////////////////////
template <> void BinaryReader::readDefault(const std::string &s, std::string &output);
template <typename U> template <typename U>
void BinaryReader::readDefault(const std::string &s, U &output) void BinaryReader::readDefault(const std::string &s, U &output)
{ {
file_.read((char *)&output, sizeof(U)); file_.read((char *)&output, sizeof(U));
} }
template <>
void BinaryReader::readDefault(const std::string &s, std::string &output);
template <typename U> template <typename U>
void BinaryReader::readDefault(const std::string &s, std::vector<U> &output) void BinaryReader::readDefault(const std::string &s, std::vector<U> &output)
{ {

View File

@ -27,12 +27,11 @@
/* END LEGAL */ /* END LEGAL */
#include <Grid/Grid.h> #include <Grid/Grid.h>
using namespace Grid; NAMESPACE_BEGIN(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())
@ -74,23 +73,19 @@ void JSONWriter::delete_comma()
// compiles fine with clang // compiles fine with clang
// have to wrap in the Grid namespace // have to wrap in the Grid namespace
// annoying, but necessary for TravisCI // 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::cout << "JSONWriter::writeDefault(string) : " << s << std::endl;
std::ostringstream os; std::ostringstream os;
os << std::boolalpha << x; os << std::boolalpha << x;
if (s.size()) if (s.size())
ss_ << "\""<< s << "\" : \"" << os.str() << "\" ," ; ss_ << "\""<< s << "\" : \"" << os.str() << "\" ," ;
else else
ss_ << os.str() << " ," ; ss_ << os.str() << " ," ;
} }
}// 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 +97,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_);
@ -152,14 +147,14 @@ bool JSONReader::nextElement(const std::string &s)
//} //}
jcur_ = *it_; jcur_ = *it_;
//cout << "JSONReader::nextElement(string) : " << s << " : "<< jcur_ << endl; //cout << "JSONReader::nextElement(std::string) : " << s << " : "<< jcur_ << endl;
//return true; //return true;
return false; return false;
} }
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()){
@ -172,3 +167,4 @@ void JSONReader::readDefault(const string &s, string &output)
output = jcur_; output = jcur_;
} }
} }
NAMESPACE_END(Grid);

View File

@ -42,8 +42,6 @@ THE SOFTWARE.
*/ */
/////////////////////////////////////////// ///////////////////////////////////////////
#define strong_inline __attribute__((always_inline)) inline
#ifndef MAX #ifndef MAX
#define MAX(x,y) ((x)>(y)?(x):(y)) #define MAX(x,y) ((x)>(y)?(x):(y))
#define MIN(x,y) ((x)>(y)?(y):(x)) #define MIN(x,y) ((x)>(y)?(y):(x))

View File

@ -29,18 +29,16 @@
/* END LEGAL */ /* END LEGAL */
#include <Grid/GridCore.h> #include <Grid/GridCore.h>
using namespace Grid; //using namespace Grid;
using namespace std; //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
NAMESPACE_BEGIN(Grid);
// Writer implementation /////////////////////////////////////////////////////// // 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_++; level_++;
}; };
@ -58,16 +56,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 +89,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);
} }
} }
@ -100,7 +98,9 @@ void TextReader::checkIndent(void)
template <> template <>
void TextReader::readDefault(const std::string &s, std::string &output) void TextReader::readDefault(const std::string &s, std::string &output)
{ {
checkIndent(); checkIndent();
output.clear(); output.clear();
getline(file_, output); getline(file_, output);
} }
NAMESPACE_END(Grid);

View File

@ -43,7 +43,7 @@ namespace Grid
class TextWriter: public Writer<TextWriter> class TextWriter: public Writer<TextWriter>
{ {
public: public:
TextWriter(const std::string &fileName); TextWriter(const std::string &fileName) : file_(fileName, std::ios::out) {};
virtual ~TextWriter(void) = default; virtual ~TextWriter(void) = default;
void push(const std::string &s); void push(const std::string &s);
void pop(void); void pop(void);
@ -65,10 +65,8 @@ namespace Grid
virtual ~TextReader(void) = default; virtual ~TextReader(void) = default;
bool push(const std::string &s); bool push(const std::string &s);
void pop(void); void pop(void);
template <typename U> template <typename U> void readDefault(const std::string &s, U &output);
void readDefault(const std::string &s, U &output); template <typename U> void readDefault(const std::string &s, std::vector<U> &output);
template <typename U>
void readDefault(const std::string &s, std::vector<U> &output);
private: private:
void checkIndent(void); void checkIndent(void);
private: private:
@ -97,6 +95,8 @@ namespace Grid
} }
// Reader template implementation //////////////////////////////////////////// // Reader template implementation ////////////////////////////////////////////
template <> void TextReader::readDefault(const std::string &s, std::string &output);
template <typename U> template <typename U>
void TextReader::readDefault(const std::string &s, U &output) void TextReader::readDefault(const std::string &s, U &output)
{ {
@ -106,8 +106,6 @@ namespace Grid
fromString(output, buf); fromString(output, buf);
} }
template <>
void TextReader::readDefault(const std::string &s, std::string &output);
template <typename U> template <typename U>
void TextReader::readDefault(const std::string &s, std::vector<U> &output) void TextReader::readDefault(const std::string &s, std::vector<U> &output)

View File

@ -28,11 +28,13 @@ Author: paboyle <paboyle@ph.ed.ac.uk>
/* END LEGAL */ /* END LEGAL */
#include <Grid/GridCore.h> #include <Grid/GridCore.h>
using namespace Grid; //using namespace Grid;
using namespace std; //using namespace std;
NAMESPACE_BEGIN(Grid);
// 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 +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()); node_ = node_.append_child(s.c_str());
} }
@ -65,14 +67,14 @@ 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(); std::abort();
} }
if ( toplev == std::string("") ) { if ( toplev == std::string("") ) {
node_ = doc_; node_ = doc_;
@ -82,14 +84,14 @@ 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(); std::abort();
} }
if ( toplev == std::string("") ) { if ( toplev == std::string("") ) {
node_ = doc_; 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())) if (node_.child(s.c_str()))
{ {
@ -133,7 +135,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()))
{ {
@ -147,3 +149,4 @@ void XmlReader::readDefault(const string &s, string &output)
output = ""; output = "";
} }
} }
NAMESPACE_END(Grid);

View File

@ -73,8 +73,7 @@ namespace Grid
bool nextElement(const std::string &s); bool nextElement(const std::string &s);
template <typename U> template <typename U>
void readDefault(const std::string &s, U &output); void readDefault(const std::string &s, U &output);
template <typename U> template <typename U> void readDefault(const std::string &s, std::vector<U> &output);
void readDefault(const std::string &s, std::vector<U> &output);
private: private:
pugi::xml_document doc_; pugi::xml_document doc_;
pugi::xml_node node_; pugi::xml_node node_;
@ -114,6 +113,7 @@ namespace Grid
} }
// Reader template implementation //////////////////////////////////////////// // Reader template implementation ////////////////////////////////////////////
template <> void XmlReader::readDefault(const std::string &s, std::string &output);
template <typename U> template <typename U>
void XmlReader::readDefault(const std::string &s, U &output) void XmlReader::readDefault(const std::string &s, U &output)
{ {
@ -123,9 +123,6 @@ namespace Grid
fromString(output, buf); fromString(output, buf);
} }
template <>
void XmlReader::readDefault(const std::string &s, std::string &output);
template <typename U> template <typename U>
void XmlReader::readDefault(const std::string &s, std::vector<U> &output) void XmlReader::readDefault(const std::string &s, std::vector<U> &output)
{ {