summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/common/Variant.hpp43
-rw-r--r--src/core/common/VariantConverter.cpp37
2 files changed, 45 insertions, 35 deletions
diff --git a/src/core/common/Variant.hpp b/src/core/common/Variant.hpp
index 9a201c7..7cdec24 100644
--- a/src/core/common/Variant.hpp
+++ b/src/core/common/Variant.hpp
@@ -80,29 +80,28 @@ struct VariantMetadata {
* Structure holding the actual metadata.
*/
struct Meta {
+ /**
+ * Field used to store the type of a Variant (4 Bit, space for 16
+ * objects).
+ */
+ uint8_t variantType : 4;
+
+ /**
+ * Field used to store the location at which the Variant was found
+ * (30 Bit).
+ */
+ uint32_t locationOffset : 30; // Enough for 1GB
- /**
- * Field used to store the type of a Variant (4 Bit, space for 16
- * objects).
- */
- uint8_t variantType : 4;
-
- /**
- * Field used to store the location at which the Variant was found
- * (30 Bit).
- */
- uint32_t locationOffset : 30; // Enough for 1GB
-
- /**
- * Field used to store the length of the value from which the
- * variant was parsed (14 Bit).
- */
- uint16_t locationLength : 14; // 16.000 Bytes of context
-
- /**
- * Unique id of the file from which the variant was parsed.
- */
- uint16_t locationSourceId : 16; // 65.000 Source files
+ /**
+ * Field used to store the length of the value from which the
+ * variant was parsed (14 Bit).
+ */
+ uint16_t locationLength : 14; // 16.000 Bytes of context
+
+ /**
+ * Unique id of the file from which the variant was parsed.
+ */
+ uint16_t locationSourceId : 16; // 65.000 Source files
};
union {
diff --git a/src/core/common/VariantConverter.cpp b/src/core/common/VariantConverter.cpp
index b43d04e..699576b 100644
--- a/src/core/common/VariantConverter.cpp
+++ b/src/core/common/VariantConverter.cpp
@@ -225,22 +225,26 @@ bool VariantConverter::toString(Variant &var, Logger &logger, Mode mode)
const VariantType type = var.getType();
switch (type) {
case VariantType::NULLPTR:
- logger.warning(msgImplicitConversion(type, VariantType::STRING), var);
+ logger.warning(msgImplicitConversion(type, VariantType::STRING),
+ var);
var = "null";
return true;
case VariantType::BOOL:
- logger.warning(msgImplicitConversion(type, VariantType::STRING), var);
+ logger.warning(msgImplicitConversion(type, VariantType::STRING),
+ var);
var = var.asBool() ? "true" : "false";
return true;
case VariantType::INT: {
- logger.warning(msgImplicitConversion(type, VariantType::STRING), var);
+ logger.warning(msgImplicitConversion(type, VariantType::STRING),
+ var);
std::stringstream ss;
ss << var.asInt();
var = ss.str().c_str();
return true;
}
case VariantType::DOUBLE: {
- logger.warning(msgImplicitConversion(type, VariantType::STRING), var);
+ logger.warning(msgImplicitConversion(type, VariantType::STRING),
+ var);
std::stringstream ss;
ss << var.asDouble();
var = ss.str().c_str();
@@ -401,7 +405,8 @@ bool VariantConverter::toCardinality(Variant &var, Logger &logger, Mode mode)
Variant::cardinalityType &card = var.asCardinality();
if (value < 0) {
logger.error(
- "A value smaller 0 can not be converted to a cardinality!", var);
+ "A value smaller 0 can not be converted to a cardinality!",
+ var);
return false;
}
card.merge({(unsigned int)value});
@@ -432,7 +437,8 @@ bool VariantConverter::toCardinality(Variant &var, Logger &logger, Mode mode)
if (value < 0) {
logger.error(
"A value smaller 0 can not be converted to a "
- "cardinality!", var);
+ "cardinality!",
+ var);
return false;
}
card.merge({(unsigned int)value});
@@ -448,14 +454,16 @@ bool VariantConverter::toCardinality(Variant &var, Logger &logger, Mode mode)
if (!startVar.isInt()) {
logger.error(
"A non-integer can not be interpreted as the start "
- "of a range", startVar);
+ "of a range",
+ startVar);
return false;
}
int start = startVar.asInt();
if (start < 0) {
logger.error(
"A value smaller 0 can not be converted to a "
- "cardinality!", startVar);
+ "cardinality!",
+ startVar);
return false;
}
it++;
@@ -466,16 +474,18 @@ bool VariantConverter::toCardinality(Variant &var, Logger &logger, Mode mode)
if (!endVar.isInt()) {
logger.error(
"A non-integer can not be interpreted as the end "
- "of a range", endVar);
+ "of a range",
+ endVar);
return false;
}
int end = endVar.asInt();
if (end < start) {
logger.error(
std::string("The supposed start value ") +
- std::to_string(start) +
- " was bigger than the supposed end value " +
- std::to_string(end) + " of the Range.", endVar);
+ std::to_string(start) +
+ " was bigger than the supposed end value " +
+ std::to_string(end) + " of the Range.",
+ endVar);
return false;
}
card.merge({(unsigned int)start, (unsigned int)end});
@@ -561,7 +571,8 @@ bool VariantConverter::convert(Variant &var, const Rtti *type,
// Make sure the object type is correct
if (!var.getRtti()->isa(type)) {
logger.error(std::string("Expected object of type ") + type->name +
- " but got object of type " + var.getRtti()->name, var);
+ " but got object of type " + var.getRtti()->name,
+ var);
var.setObject(nullptr);
return false;
}