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