1
0
mirror of https://github.com/paboyle/Grid.git synced 2025-06-16 14:57:05 +01:00

Merge remote-tracking branch 'origin/develop' into temporary-smearing

This commit is contained in:
Guido Cossu
2016-07-04 17:28:40 +01:00
107 changed files with 7839 additions and 4572 deletions

View File

@ -32,6 +32,40 @@ Author: Peter Boyle <paboyle@ph.ed.ac.uk>
#include <type_traits>
namespace Grid {
// helper function to read space-separated values
template <typename T>
std::vector<T> strToVec(const std::string s)
{
std::istringstream sstr(s);
T buf;
std::vector<T> v;
while(!sstr.eof())
{
sstr >> buf;
v.push_back(buf);
}
return v;
}
// output to streams for vectors
template < class T >
inline std::ostream & operator<<(std::ostream &os, const std::vector<T> &v)
{
os << "[";
for (auto &x: v)
{
os << x << " ";
}
if (v.size() > 0)
{
os << "\b";
}
os << "]";
return os;
}
class Serializable {};
@ -138,23 +172,6 @@ namespace Grid {
r.read(s, output);
}
template < class T >
inline std::ostream& operator << (std::ostream& os, const std::vector<T>& v)
{
os << "[";
for (auto &x: v)
{
os << x << " ";
}
if (v.size() > 0)
{
os << "\b";
}
os << "]";
return os;
}
// Writer template implementation ////////////////////////////////////////////
template <typename T>
Writer<T>::Writer(void)

View File

@ -120,7 +120,7 @@ THE SOFTWARE.
\
\
template <typename T>\
static void write(Writer<T> &WR,const std::string &s, const cname &obj){ \
static inline void write(Writer<T> &WR,const std::string &s, const cname &obj){ \
push(WR,s);\
GRID_MACRO_EVAL(GRID_MACRO_MAP(GRID_MACRO_WRITE_MEMBER,__VA_ARGS__)) \
pop(WR);\
@ -128,14 +128,14 @@ THE SOFTWARE.
\
\
template <typename T>\
static void read(Reader<T> &RD,const std::string &s, cname &obj){ \
static inline void read(Reader<T> &RD,const std::string &s, cname &obj){ \
push(RD,s);\
GRID_MACRO_EVAL(GRID_MACRO_MAP(GRID_MACRO_READ_MEMBER,__VA_ARGS__)) \
pop(RD);\
} \
\
\
friend std::ostream & operator << (std::ostream &os, const cname &obj ) { \
friend inline std::ostream & operator << (std::ostream &os, const cname &obj ) { \
os<<"class "<<#cname<<" {"<<std::endl;\
GRID_MACRO_EVAL(GRID_MACRO_MAP(GRID_MACRO_OS_WRITE_MEMBER,__VA_ARGS__)) \
os<<"}"; \
@ -165,7 +165,7 @@ namespace Grid {
class EnumIO<name> {\
public:\
template <typename T>\
static void write(Writer<T> &WR,const std::string &s, const name &obj){ \
static inline void write(Writer<T> &WR,const std::string &s, const name &obj){ \
switch (obj) {\
GRID_MACRO_EVAL(GRID_MACRO_MAP(GRID_MACRO_ENUMCASE,__VA_ARGS__))\
default: Grid::write(WR,s,#undefname); break;\
@ -173,7 +173,7 @@ namespace Grid {
}\
\
template <typename T>\
static void read(Reader<T> &RD,const std::string &s, name &obj){ \
static inline void read(Reader<T> &RD,const std::string &s, name &obj){ \
std::string buf;\
Grid::read(RD, s, buf);\
if (buf == #undefname) {obj = name::undefname;}\
@ -182,7 +182,7 @@ namespace Grid {
}\
};\
\
std::ostream & operator << (std::ostream &os, const name &obj ) { \
inline std::ostream & operator << (std::ostream &os, const name &obj ) { \
switch (obj) {\
GRID_MACRO_EVAL(GRID_MACRO_MAP(GRID_MACRO_ENUMCASEIO,__VA_ARGS__))\
default: os << #undefname; break;\

View File

@ -80,6 +80,20 @@ void XmlReader::pop(void)
node_ = node_.parent();
}
bool XmlReader::nextElement(const std::string &s)
{
if (node_.next_sibling(s.c_str()))
{
node_ = node_.next_sibling(s.c_str());
return true;
}
else
{
return false;
}
}
template <>
void XmlReader::readDefault(const string &s, string &output)
{

View File

@ -68,6 +68,7 @@ namespace Grid
virtual ~XmlReader(void) = default;
void push(const std::string &s);
void pop(void);
bool nextElement(const std::string &s);
template <typename U>
void readDefault(const std::string &s, U &output);
template <typename U>