mirror of
https://github.com/paboyle/Grid.git
synced 2025-04-09 05:30:46 +01:00
more general implementation of the precision interface for serialisers
This commit is contained in:
parent
25828746f3
commit
54d789204f
@ -60,8 +60,14 @@ namespace Grid {
|
|||||||
void write(const std::string &s, const iVector<U, N> &output);
|
void write(const std::string &s, const iVector<U, N> &output);
|
||||||
template <typename U, int N>
|
template <typename U, int N>
|
||||||
void write(const std::string &s, const iMatrix<U, N> &output);
|
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:
|
private:
|
||||||
T *upcast;
|
T *upcast;
|
||||||
|
bool scientific_{false};
|
||||||
|
unsigned int prec_{0};
|
||||||
};
|
};
|
||||||
|
|
||||||
// Static abstract reader
|
// Static abstract reader
|
||||||
@ -155,6 +161,30 @@ namespace Grid {
|
|||||||
{
|
{
|
||||||
upcast->writeDefault(s, tensorToVec(output));
|
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
|
// Reader template implementation
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
@ -103,8 +103,15 @@ namespace Grid
|
|||||||
{
|
{
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
|
|
||||||
os.precision(16);
|
if (getPrecision())
|
||||||
os << std::scientific << std::boolalpha << x;
|
{
|
||||||
|
os.precision(getPrecision());
|
||||||
|
}
|
||||||
|
if (isScientific())
|
||||||
|
{
|
||||||
|
os << std::scientific;
|
||||||
|
}
|
||||||
|
os << std::boolalpha << x;
|
||||||
pugi::xml_node leaf = node_.append_child(s.c_str());
|
pugi::xml_node leaf = node_.append_child(s.c_str());
|
||||||
leaf.append_child(pugi::node_pcdata).set_value(os.str().c_str());
|
leaf.append_child(pugi::node_pcdata).set_value(os.str().c_str());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user