mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-31 03:07:35 +02:00
Rename flags_
to type_
This commit is contained in:
@ -19,14 +19,14 @@ T parseNumber(const char* s);
|
|||||||
|
|
||||||
class VariantData {
|
class VariantData {
|
||||||
VariantContent content_; // must be first to allow cast from array to variant
|
VariantContent content_; // must be first to allow cast from array to variant
|
||||||
uint8_t flags_;
|
uint8_t type_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
VariantData() : flags_(VALUE_IS_NULL) {}
|
VariantData() : type_(VALUE_IS_NULL) {}
|
||||||
|
|
||||||
template <typename TVisitor>
|
template <typename TVisitor>
|
||||||
typename TVisitor::result_type accept(TVisitor& visit) const {
|
typename TVisitor::result_type accept(TVisitor& visit) const {
|
||||||
switch (type()) {
|
switch (type_) {
|
||||||
case VALUE_IS_FLOAT:
|
case VALUE_IS_FLOAT:
|
||||||
return visit.visit(content_.asFloat);
|
return visit.visit(content_.asFloat);
|
||||||
|
|
||||||
@ -98,7 +98,7 @@ class VariantData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool asBoolean() const {
|
bool asBoolean() const {
|
||||||
switch (type()) {
|
switch (type_) {
|
||||||
case VALUE_IS_BOOLEAN:
|
case VALUE_IS_BOOLEAN:
|
||||||
return content_.asBoolean;
|
return content_.asBoolean;
|
||||||
case VALUE_IS_SIGNED_INTEGER:
|
case VALUE_IS_SIGNED_INTEGER:
|
||||||
@ -132,7 +132,7 @@ class VariantData {
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
T asFloat() const {
|
T asFloat() const {
|
||||||
static_assert(is_floating_point<T>::value, "T must be a floating point");
|
static_assert(is_floating_point<T>::value, "T must be a floating point");
|
||||||
switch (type()) {
|
switch (type_) {
|
||||||
case VALUE_IS_BOOLEAN:
|
case VALUE_IS_BOOLEAN:
|
||||||
return static_cast<T>(content_.asBoolean);
|
return static_cast<T>(content_.asBoolean);
|
||||||
case VALUE_IS_UNSIGNED_INTEGER:
|
case VALUE_IS_UNSIGNED_INTEGER:
|
||||||
@ -152,7 +152,7 @@ class VariantData {
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
T asIntegral() const {
|
T asIntegral() const {
|
||||||
static_assert(is_integral<T>::value, "T must be an integral type");
|
static_assert(is_integral<T>::value, "T must be an integral type");
|
||||||
switch (type()) {
|
switch (type_) {
|
||||||
case VALUE_IS_BOOLEAN:
|
case VALUE_IS_BOOLEAN:
|
||||||
return content_.asBoolean;
|
return content_.asBoolean;
|
||||||
case VALUE_IS_UNSIGNED_INTEGER:
|
case VALUE_IS_UNSIGNED_INTEGER:
|
||||||
@ -179,7 +179,7 @@ class VariantData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
JsonString asRawString() const {
|
JsonString asRawString() const {
|
||||||
switch (type()) {
|
switch (type_) {
|
||||||
case VALUE_IS_RAW_STRING:
|
case VALUE_IS_RAW_STRING:
|
||||||
return JsonString(content_.asOwnedString->data,
|
return JsonString(content_.asOwnedString->data,
|
||||||
content_.asOwnedString->length, JsonString::Copied);
|
content_.asOwnedString->length, JsonString::Copied);
|
||||||
@ -189,7 +189,7 @@ class VariantData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
JsonString asString() const {
|
JsonString asString() const {
|
||||||
switch (type()) {
|
switch (type_) {
|
||||||
case VALUE_IS_LINKED_STRING:
|
case VALUE_IS_LINKED_STRING:
|
||||||
return JsonString(content_.asLinkedString, JsonString::Linked);
|
return JsonString(content_.asLinkedString, JsonString::Linked);
|
||||||
case VALUE_IS_OWNED_STRING:
|
case VALUE_IS_OWNED_STRING:
|
||||||
@ -242,24 +242,24 @@ class VariantData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool isArray() const {
|
bool isArray() const {
|
||||||
return (flags_ & VALUE_IS_ARRAY) != 0;
|
return type_ == VALUE_IS_ARRAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isBoolean() const {
|
bool isBoolean() const {
|
||||||
return type() == VALUE_IS_BOOLEAN;
|
return type_ == VALUE_IS_BOOLEAN;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isCollection() const {
|
bool isCollection() const {
|
||||||
return (flags_ & COLLECTION_MASK) != 0;
|
return (type_ & COLLECTION_MASK) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isFloat() const {
|
bool isFloat() const {
|
||||||
return (flags_ & NUMBER_BIT) != 0;
|
return (type_ & NUMBER_BIT) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool isInteger() const {
|
bool isInteger() const {
|
||||||
switch (type()) {
|
switch (type_) {
|
||||||
case VALUE_IS_UNSIGNED_INTEGER:
|
case VALUE_IS_UNSIGNED_INTEGER:
|
||||||
return canConvertNumber<T>(content_.asUnsignedInteger);
|
return canConvertNumber<T>(content_.asUnsignedInteger);
|
||||||
|
|
||||||
@ -272,7 +272,7 @@ class VariantData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool isNull() const {
|
bool isNull() const {
|
||||||
return type() == VALUE_IS_NULL;
|
return type_ == VALUE_IS_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isNull(const VariantData* var) {
|
static bool isNull(const VariantData* var) {
|
||||||
@ -282,11 +282,11 @@ class VariantData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool isObject() const {
|
bool isObject() const {
|
||||||
return (flags_ & VALUE_IS_OBJECT) != 0;
|
return type_ == VALUE_IS_OBJECT;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isString() const {
|
bool isString() const {
|
||||||
return type() == VALUE_IS_LINKED_STRING || type() == VALUE_IS_OWNED_STRING;
|
return type_ == VALUE_IS_LINKED_STRING || type_ == VALUE_IS_OWNED_STRING;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t nesting(const ResourceManager* resources) const {
|
size_t nesting(const ResourceManager* resources) const {
|
||||||
@ -329,11 +329,11 @@ class VariantData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void reset() {
|
void reset() {
|
||||||
flags_ = VALUE_IS_NULL;
|
type_ = VALUE_IS_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setBoolean(bool value) {
|
void setBoolean(bool value) {
|
||||||
setType(VALUE_IS_BOOLEAN);
|
type_ = VALUE_IS_BOOLEAN;
|
||||||
content_.asBoolean = value;
|
content_.asBoolean = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -343,7 +343,7 @@ class VariantData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setFloat(JsonFloat value) {
|
void setFloat(JsonFloat value) {
|
||||||
setType(VALUE_IS_FLOAT);
|
type_ = VALUE_IS_FLOAT;
|
||||||
content_.asFloat = value;
|
content_.asFloat = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -354,13 +354,13 @@ class VariantData {
|
|||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
enable_if_t<is_signed<T>::value> setInteger(T value) {
|
enable_if_t<is_signed<T>::value> setInteger(T value) {
|
||||||
setType(VALUE_IS_SIGNED_INTEGER);
|
type_ = VALUE_IS_SIGNED_INTEGER;
|
||||||
content_.asSignedInteger = value;
|
content_.asSignedInteger = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
enable_if_t<is_unsigned<T>::value> setInteger(T value) {
|
enable_if_t<is_unsigned<T>::value> setInteger(T value) {
|
||||||
setType(VALUE_IS_UNSIGNED_INTEGER);
|
type_ = VALUE_IS_UNSIGNED_INTEGER;
|
||||||
content_.asUnsignedInteger = static_cast<JsonUInt>(value);
|
content_.asUnsignedInteger = static_cast<JsonUInt>(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -371,7 +371,7 @@ class VariantData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setNull() {
|
void setNull() {
|
||||||
setType(VALUE_IS_NULL);
|
type_ = VALUE_IS_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setNull(ResourceManager* resources) {
|
void setNull(ResourceManager* resources) {
|
||||||
@ -387,7 +387,7 @@ class VariantData {
|
|||||||
|
|
||||||
void setRawString(StringNode* s) {
|
void setRawString(StringNode* s) {
|
||||||
ARDUINOJSON_ASSERT(s);
|
ARDUINOJSON_ASSERT(s);
|
||||||
setType(VALUE_IS_RAW_STRING);
|
type_ = VALUE_IS_RAW_STRING;
|
||||||
content_.asOwnedString = s;
|
content_.asOwnedString = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -445,13 +445,13 @@ class VariantData {
|
|||||||
|
|
||||||
void setLinkedString(const char* s) {
|
void setLinkedString(const char* s) {
|
||||||
ARDUINOJSON_ASSERT(s);
|
ARDUINOJSON_ASSERT(s);
|
||||||
setType(VALUE_IS_LINKED_STRING);
|
type_ = VALUE_IS_LINKED_STRING;
|
||||||
content_.asLinkedString = s;
|
content_.asLinkedString = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setOwnedString(StringNode* s) {
|
void setOwnedString(StringNode* s) {
|
||||||
ARDUINOJSON_ASSERT(s);
|
ARDUINOJSON_ASSERT(s);
|
||||||
setType(VALUE_IS_OWNED_STRING);
|
type_ = VALUE_IS_OWNED_STRING;
|
||||||
content_.asOwnedString = s;
|
content_.asOwnedString = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -470,7 +470,7 @@ class VariantData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ArrayData& toArray() {
|
ArrayData& toArray() {
|
||||||
setType(VALUE_IS_ARRAY);
|
type_ = VALUE_IS_ARRAY;
|
||||||
new (&content_.asArray) ArrayData();
|
new (&content_.asArray) ArrayData();
|
||||||
return content_.asArray;
|
return content_.asArray;
|
||||||
}
|
}
|
||||||
@ -487,7 +487,7 @@ class VariantData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ObjectData& toObject() {
|
ObjectData& toObject() {
|
||||||
setType(VALUE_IS_OBJECT);
|
type_ = VALUE_IS_OBJECT;
|
||||||
new (&content_.asObject) ObjectData();
|
new (&content_.asObject) ObjectData();
|
||||||
return content_.asObject;
|
return content_.asObject;
|
||||||
}
|
}
|
||||||
@ -504,22 +504,18 @@ class VariantData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint8_t type() const {
|
uint8_t type() const {
|
||||||
return flags_;
|
return type_;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void release(ResourceManager* resources) {
|
void release(ResourceManager* resources) {
|
||||||
if (flags_ & OWNED_VALUE_BIT)
|
if (type_ & OWNED_VALUE_BIT)
|
||||||
resources->dereferenceString(content_.asOwnedString->data);
|
resources->dereferenceString(content_.asOwnedString->data);
|
||||||
|
|
||||||
auto collection = asCollection();
|
auto collection = asCollection();
|
||||||
if (collection)
|
if (collection)
|
||||||
collection->clear(resources);
|
collection->clear(resources);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setType(uint8_t t) {
|
|
||||||
flags_ = t;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ARDUINOJSON_END_PRIVATE_NAMESPACE
|
ARDUINOJSON_END_PRIVATE_NAMESPACE
|
||||||
|
@ -18,7 +18,7 @@ class VariantSlot {
|
|||||||
// we cannot use composition because it adds padding
|
// we cannot use composition because it adds padding
|
||||||
// (+20% on ESP8266 for example)
|
// (+20% on ESP8266 for example)
|
||||||
VariantContent content_;
|
VariantContent content_;
|
||||||
uint8_t flags_;
|
uint8_t type_;
|
||||||
SlotId next_;
|
SlotId next_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -29,8 +29,8 @@ class VariantSlot {
|
|||||||
|
|
||||||
static void operator delete(void*, void*) noexcept {}
|
static void operator delete(void*, void*) noexcept {}
|
||||||
|
|
||||||
VariantSlot() : flags_(0), next_(NULL_SLOT) {
|
VariantSlot() : type_(0), next_(NULL_SLOT) {
|
||||||
(void)flags_; // HACK: suppress Clang warning "private field is not used"
|
(void)type_; // HACK: suppress Clang warning "private field is not used"
|
||||||
}
|
}
|
||||||
|
|
||||||
VariantData* data() {
|
VariantData* data() {
|
||||||
|
Reference in New Issue
Block a user