Commit c9c2d06b authored by Philipp A. Hartmann's avatar Philipp A. Hartmann

Writer: add Double(d,precision) for one-shot double output

As proposed in other patches, it is convenient to pass a user-defined
precision for the (programmatic) output of a single double value
to an OutputStream.

This patch adds an additional overload with an explicit precision
argument to the (Pretty)Writer class templates.
parent 0ccc51fb
......@@ -51,6 +51,11 @@ public:
PrettyWriter& Int64(int64_t i64) { PrettyPrefix(kNumberType); Base::WriteInt64(i64); return *this; }
PrettyWriter& Uint64(uint64_t u64) { PrettyPrefix(kNumberType); Base::WriteUint64(u64); return *this; }
PrettyWriter& Double(double d) { PrettyPrefix(kNumberType); Base::WriteDouble(d); return *this; }
//! Overridden for fluent API, see \ref Writer::Double()
PrettyWriter& Double(double d, int precision) {
int oldPrecision = Base::GetDoublePrecision();
return SetDoublePrecision(precision).Double(d).SetDoublePrecision(oldPrecision);
}
PrettyWriter& String(const Ch* str, SizeType length, bool copy = false) {
(void)copy;
......
......@@ -75,6 +75,20 @@ public:
*/
Writer& Double(double d) { Prefix(kNumberType); WriteDouble(d); return *this; }
//! Writes the given \c double value to the stream (explicit precision)
/*!
The currently set double precision is ignored in favor of the explicitly
given precision for this value.
\see Double(), SetDoublePrecision(), GetDoublePrecision()
\param d The value to be written
\param precision The number of significant digits for this value
\return The Writer itself for fluent API.
*/
Writer& Double(double d, int precision) {
int oldPrecision = GetDoublePrecision();
return SetDoublePrecision(precision).Double(d).SetDoublePrecision(oldPrecision);
}
Writer& String(const Ch* str, SizeType length, bool copy = false) {
(void)copy;
Prefix(kStringType);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment