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

Format, NAMESPACE

This commit is contained in:
paboyle 2018-01-12 23:42:22 +00:00
parent 4be31ad1f6
commit 69496482fc

View File

@ -1,4 +1,4 @@
/************************************************************************************* /*************************************************************************************
Grid physics library, www.github.com/paboyle/Grid Grid physics library, www.github.com/paboyle/Grid
@ -24,8 +24,8 @@ Author: Peter Boyle <paboyle@ph.ed.ac.uk>
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
See the full license in the file "LICENSE" in the top level distribution directory See the full license in the file "LICENSE" in the top level distribution directory
*************************************************************************************/ *************************************************************************************/
/* END LEGAL */ /* END LEGAL */
#ifndef GRID_SERIALISATION_BINARY_READER_H #ifndef GRID_SERIALISATION_BINARY_READER_H
#define GRID_SERIALISATION_BINARY_READER_H #define GRID_SERIALISATION_BINARY_READER_H
@ -37,11 +37,11 @@ Author: Peter Boyle <paboyle@ph.ed.ac.uk>
#include <vector> #include <vector>
#include <cassert> #include <cassert>
namespace Grid { NAMESPACE_BEGIN(Grid);
class BinaryWriter: public Writer<BinaryWriter> class BinaryWriter: public Writer<BinaryWriter>
{ {
public: public:
BinaryWriter(const std::string &fileName); BinaryWriter(const std::string &fileName);
virtual ~BinaryWriter(void) = default; virtual ~BinaryWriter(void) = default;
void push(const std::string &s) {}; void push(const std::string &s) {};
@ -51,13 +51,13 @@ namespace Grid {
template <typename U> template <typename U>
void writeDefault(const std::string &s, const std::vector<U> &x); void writeDefault(const std::string &s, const std::vector<U> &x);
void writeDefault(const std::string &s, const char *x); void writeDefault(const std::string &s, const char *x);
private: private:
std::ofstream file_; std::ofstream file_;
}; };
class BinaryReader: public Reader<BinaryReader> class BinaryReader: public Reader<BinaryReader>
{ {
public: public:
BinaryReader(const std::string &fileName); BinaryReader(const std::string &fileName);
virtual ~BinaryReader(void) = default; virtual ~BinaryReader(void) = default;
bool push(const std::string &s) {return true;} bool push(const std::string &s) {return true;}
@ -66,23 +66,23 @@ namespace Grid {
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:
std::ifstream file_; std::ifstream file_;
}; };
// Writer template implementation //////////////////////////////////////////// // Writer template implementation ////////////////////////////////////////////
template <typename U> template <typename U>
void BinaryWriter::writeDefault(const std::string &s, const U &x) void BinaryWriter::writeDefault(const std::string &s, const U &x)
{ {
file_.write((char *)&x, sizeof(U)); file_.write((char *)&x, sizeof(U));
} }
template <> template <>
void BinaryWriter::writeDefault(const std::string &s, const std::string &x); void BinaryWriter::writeDefault(const std::string &s, const std::string &x);
template <typename U> template <typename U>
void BinaryWriter::writeDefault(const std::string &s, const std::vector<U> &x) void BinaryWriter::writeDefault(const std::string &s, const std::vector<U> &x)
{ {
uint64_t sz = x.size(); uint64_t sz = x.size();
write("", sz); write("", sz);
@ -90,21 +90,21 @@ namespace Grid {
{ {
write("", x[i]); write("", x[i]);
} }
} }
// Reader template implementation //////////////////////////////////////////// // Reader template implementation ////////////////////////////////////////////
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 <> template <>
void BinaryReader::readDefault(const std::string &s, std::string &output); 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)
{ {
uint64_t sz; uint64_t sz;
read("", sz); read("", sz);
@ -113,7 +113,8 @@ namespace Grid {
{ {
read("", output[i]); read("", output[i]);
} }
}
} }
NAMESPACE_END(Grid);
#endif #endif