mirror of
https://github.com/paboyle/Grid.git
synced 2024-11-10 07:55:35 +00:00
Format, NAMESPACE
This commit is contained in:
parent
4be31ad1f6
commit
69496482fc
@ -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,83 +37,84 @@ Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
|
||||
namespace Grid {
|
||||
NAMESPACE_BEGIN(Grid);
|
||||
|
||||
class BinaryWriter: public Writer<BinaryWriter>
|
||||
{
|
||||
public:
|
||||
BinaryWriter(const std::string &fileName);
|
||||
virtual ~BinaryWriter(void) = default;
|
||||
void push(const std::string &s) {};
|
||||
void pop(void) {};
|
||||
template <typename U>
|
||||
void writeDefault(const std::string &s, const U &x);
|
||||
template <typename U>
|
||||
void writeDefault(const std::string &s, const std::vector<U> &x);
|
||||
void writeDefault(const std::string &s, const char *x);
|
||||
private:
|
||||
std::ofstream file_;
|
||||
};
|
||||
|
||||
class BinaryReader: public Reader<BinaryReader>
|
||||
{
|
||||
public:
|
||||
BinaryReader(const std::string &fileName);
|
||||
virtual ~BinaryReader(void) = default;
|
||||
bool push(const std::string &s) {return true;}
|
||||
void pop(void) {};
|
||||
template <typename U>
|
||||
void readDefault(const std::string &s, U &output);
|
||||
template <typename U>
|
||||
void readDefault(const std::string &s, std::vector<U> &output);
|
||||
private:
|
||||
std::ifstream file_;
|
||||
};
|
||||
|
||||
// Writer template implementation ////////////////////////////////////////////
|
||||
class BinaryWriter: public Writer<BinaryWriter>
|
||||
{
|
||||
public:
|
||||
BinaryWriter(const std::string &fileName);
|
||||
virtual ~BinaryWriter(void) = default;
|
||||
void push(const std::string &s) {};
|
||||
void pop(void) {};
|
||||
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);
|
||||
|
||||
void writeDefault(const std::string &s, const U &x);
|
||||
template <typename U>
|
||||
void BinaryWriter::writeDefault(const std::string &s, const std::vector<U> &x)
|
||||
{
|
||||
uint64_t sz = x.size();
|
||||
void writeDefault(const std::string &s, const std::vector<U> &x);
|
||||
void writeDefault(const std::string &s, const char *x);
|
||||
private:
|
||||
std::ofstream file_;
|
||||
};
|
||||
|
||||
class BinaryReader: public Reader<BinaryReader>
|
||||
{
|
||||
public:
|
||||
BinaryReader(const std::string &fileName);
|
||||
virtual ~BinaryReader(void) = default;
|
||||
bool push(const std::string &s) {return true;}
|
||||
void pop(void) {};
|
||||
template <typename U>
|
||||
void readDefault(const std::string &s, U &output);
|
||||
template <typename U>
|
||||
void readDefault(const std::string &s, std::vector<U> &output);
|
||||
private:
|
||||
std::ifstream file_;
|
||||
};
|
||||
|
||||
// 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 <typename U>
|
||||
void BinaryWriter::writeDefault(const std::string &s, const std::vector<U> &x)
|
||||
{
|
||||
uint64_t sz = x.size();
|
||||
|
||||
write("", sz);
|
||||
for (uint64_t i = 0; i < sz; ++i)
|
||||
write("", sz);
|
||||
for (uint64_t i = 0; i < sz; ++i)
|
||||
{
|
||||
write("", x[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Reader template implementation ////////////////////////////////////////////
|
||||
template <typename U>
|
||||
void BinaryReader::readDefault(const std::string &s, U &output)
|
||||
{
|
||||
file_.read((char *)&output, sizeof(U));
|
||||
}
|
||||
// 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)
|
||||
{
|
||||
uint64_t sz;
|
||||
template <typename U>
|
||||
void BinaryReader::readDefault(const std::string &s, std::vector<U> &output)
|
||||
{
|
||||
uint64_t sz;
|
||||
|
||||
read("", sz);
|
||||
output.resize(sz);
|
||||
for (uint64_t i = 0; i < sz; ++i)
|
||||
read("", sz);
|
||||
output.resize(sz);
|
||||
for (uint64_t i = 0; i < sz; ++i)
|
||||
{
|
||||
read("", output[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NAMESPACE_END(Grid);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user