Now use uint8_t to store decimal count

This commit is contained in:
Benoit Blanchon
2014-11-03 18:28:24 +01:00
parent 2f8fde6772
commit 04cde11a04
6 changed files with 7 additions and 6 deletions

View File

@ -28,7 +28,7 @@ class JsonWriter {
void writeString(const char *value);
void writeInteger(long value);
void writeBoolean(bool value);
void writeDouble(double value, int decimals);
void writeDouble(double value, uint8_t decimals);
void writeColon() { _length += _sink->write(':'); }
void writeComma() { _length += _sink->write(','); }

View File

@ -41,7 +41,7 @@ class JsonArray : public JsonPrintable<JsonArray>,
}
value_type &add();
void add(double value, int decimals) { add().set(value, decimals); }
void add(double value, uint8_t decimals) { add().set(value, decimals); }
void add(JsonArray &nestedArray) { add().set(nestedArray); }
void add(JsonObject &nestedObject) { add().set(nestedObject); }

View File

@ -7,6 +7,7 @@
#pragma once
#include <stddef.h>
#include <stdint.h> // for uint8_t
#include "Internals/JsonValueContent.hpp"
#include "Internals/JsonValueType.hpp"
@ -25,7 +26,7 @@ class JsonValue {
JsonValue() : _type(Internals::JSON_UNDEFINED) {}
void set(bool value);
void set(double value, int decimals = 2);
void set(double value, uint8_t decimals = 2);
void set(signed char value) { set(static_cast<long>(value)); }
void set(signed int value) { set(static_cast<long>(value)); }
void set(signed long value);

View File

@ -118,7 +118,7 @@ void JsonParser::parseNumberTo(JsonValue &destination) {
if (*endOfLong == '.') {
// stopped on a decimal separator
double doubleValue = strtod(_ptr, &_ptr);
int decimals = _ptr - endOfLong - 1;
uint8_t decimals = _ptr - endOfLong - 1;
destination.set(doubleValue, decimals);
} else {
_ptr = endOfLong;

View File

@ -19,6 +19,6 @@ void JsonWriter::writeBoolean(bool value) {
_length += _sink->print(value ? "true" : "false");
}
void JsonWriter::writeDouble(double value, int decimals) {
void JsonWriter::writeDouble(double value, uint8_t decimals) {
_length += _sink->print(value, decimals);
}

View File

@ -50,7 +50,7 @@ void JsonValue::set(const char *value) {
_content.asString = value;
}
void JsonValue::set(double value, int decimals) {
void JsonValue::set(double value, uint8_t decimals) {
if (_type == JSON_INVALID) return;
_type = static_cast<JsonValueType>(JSON_DOUBLE_0_DECIMALS + decimals);
_content.asDouble = value;