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

more general implementation of the precision interface for serialisers

This commit is contained in:
Antonin Portelli 2018-05-07 21:17:46 +01:00
parent 25828746f3
commit 54d789204f
2 changed files with 40 additions and 3 deletions

View File

@ -60,8 +60,14 @@ namespace Grid {
void write(const std::string &s, const iVector<U, N> &output);
template <typename U, int N>
void write(const std::string &s, const iMatrix<U, N> &output);
void scientificFormat(const bool set);
bool isScientific(void);
void setPrecision(const unsigned int prec);
unsigned int getPrecision(void);
private:
T *upcast;
T *upcast;
bool scientific_{false};
unsigned int prec_{0};
};
// Static abstract reader
@ -155,6 +161,30 @@ namespace Grid {
{
upcast->writeDefault(s, tensorToVec(output));
}
template <typename T>
void Writer<T>::scientificFormat(const bool set)
{
scientific_ = set;
}
template <typename T>
bool Writer<T>::isScientific(void)
{
return scientific_;
}
template <typename T>
void Writer<T>::setPrecision(const unsigned int prec)
{
prec_ = prec;
}
template <typename T>
unsigned int Writer<T>::getPrecision(void)
{
return prec_;
}
// Reader template implementation
template <typename T>

View File

@ -103,8 +103,15 @@ namespace Grid
{
std::ostringstream os;
os.precision(16);
os << std::scientific << std::boolalpha << x;
if (getPrecision())
{
os.precision(getPrecision());
}
if (isScientific())
{
os << std::scientific;
}
os << std::boolalpha << x;
pugi::xml_node leaf = node_.append_child(s.c_str());
leaf.append_child(pugi::node_pcdata).set_value(os.str().c_str());
}