summaryrefslogtreecommitdiff
path: root/src/components/smart_objects
diff options
context:
space:
mode:
authorVeronica Veremjova <VVeremjova@luxoft.com>2016-01-12 17:14:26 +0200
committervveremeva <vveremjova@luxoft.com>2016-01-15 09:21:22 +0200
commit3e86daa9ac21ca6e6ebc7abffc694c611f87d33a (patch)
treee9b7a01112dd6496e95aab266317445ca96ac9d0 /src/components/smart_objects
parent3bb616b43412fea81b6c15da3270b66175e1a63f (diff)
downloadsdl_core-3e86daa9ac21ca6e6ebc7abffc694c611f87d33a.tar.gz
Add cast from int64 to int32 in number schema
Added DCHECK in convertion int64 to long long
Diffstat (limited to 'src/components/smart_objects')
-rw-r--r--src/components/smart_objects/include/smart_objects/number_schema_item.h25
1 files changed, 11 insertions, 14 deletions
diff --git a/src/components/smart_objects/include/smart_objects/number_schema_item.h b/src/components/smart_objects/include/smart_objects/number_schema_item.h
index 78fd145a4d..ac84cab476 100644
--- a/src/components/smart_objects/include/smart_objects/number_schema_item.h
+++ b/src/components/smart_objects/include/smart_objects/number_schema_item.h
@@ -124,6 +124,15 @@ bool TNumberSchemaItem<NumberType>::isValidNumberType(SmartType type) {
}
}
+template <typename InputType, typename OutputType>
+OutputType IntStaticCast(const InputType& value) {
+ DCHECK_OR_RETURN(value >= std::numeric_limits<OutputType>::min(),
+ std::numeric_limits<OutputType>::min());
+ DCHECK_OR_RETURN(value <= std::numeric_limits<OutputType>::max(),
+ std::numeric_limits<OutputType>::max());
+ return static_cast<OutputType>(value);
+}
+
template <typename NumberType>
Errors::eType TNumberSchemaItem<NumberType>::validate(
const SmartObject& Object) {
@@ -132,21 +141,9 @@ Errors::eType TNumberSchemaItem<NumberType>::validate(
}
NumberType value(0);
if (typeid(int32_t) == typeid(value)) {
- DCHECK_OR_RETURN(
- Object.asInt() >= std::numeric_limits<int32_t>::min(),
- Errors::OUT_OF_RANGE);
- DCHECK_OR_RETURN(
- Object.asInt() <= std::numeric_limits<int32_t>::max(),
- Errors::OUT_OF_RANGE);
- value = static_cast<int32_t>(Object.asInt());
+ value = IntStaticCast<int64_t,int32_t>(Object.asInt());
} else if (typeid(uint32_t) == typeid(value)) {
- DCHECK_OR_RETURN(
- Object.asUInt() >= std::numeric_limits<uint32_t>::min(),
- Errors::OUT_OF_RANGE);
- DCHECK_OR_RETURN(
- Object.asUInt() <= std::numeric_limits<uint32_t>::max(),
- Errors::OUT_OF_RANGE);
- value = static_cast<uint32_t>(Object.asUInt());
+ value = IntStaticCast<uint64_t,uint32_t>(Object.asUInt());
} else if (typeid(double) == typeid(value)) {
value = Object.asDouble();
} else if (typeid(int64_t) == typeid(value)) {