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.
This commit is contained in:
parent
0ccc51fbae
commit
c9c2d06b9b
@ -51,6 +51,11 @@ public:
|
|||||||
PrettyWriter& Int64(int64_t i64) { PrettyPrefix(kNumberType); Base::WriteInt64(i64); return *this; }
|
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& Uint64(uint64_t u64) { PrettyPrefix(kNumberType); Base::WriteUint64(u64); return *this; }
|
||||||
PrettyWriter& Double(double d) { PrettyPrefix(kNumberType); Base::WriteDouble(d); 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) {
|
PrettyWriter& String(const Ch* str, SizeType length, bool copy = false) {
|
||||||
(void)copy;
|
(void)copy;
|
||||||
|
@ -75,6 +75,20 @@ public:
|
|||||||
*/
|
*/
|
||||||
Writer& Double(double d) { Prefix(kNumberType); WriteDouble(d); return *this; }
|
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) {
|
Writer& String(const Ch* str, SizeType length, bool copy = false) {
|
||||||
(void)copy;
|
(void)copy;
|
||||||
Prefix(kStringType);
|
Prefix(kStringType);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user