summaryrefslogtreecommitdiff
path: root/src/components
diff options
context:
space:
mode:
authorVeronica Veremjova <VVeremjova@luxoft.com>2015-12-28 14:47:31 +0200
committervveremeva <vveremjova@luxoft.com>2016-01-15 09:21:22 +0200
commit69f632fc2c57d9abbab5e4550db58eb67f8f5574 (patch)
treed6870729f99c96f1d94c0d4ea1728a9714c7d491 /src/components
parent5859c8f69ee80c3322b3fa980aff432fee8d80b5 (diff)
downloadsdl_core-69f632fc2c57d9abbab5e4550db58eb67f8f5574.tar.gz
Fix converting upperbound values
Convert recieved integer values into 64bit instead of 32bit Replaced returning integer values from Smart Object by 64bit numbers Added functions for converting int64 to long long int and back Closes-Bug: APPLINK-12369
Diffstat (limited to 'src/components')
-rw-r--r--src/components/application_manager/src/commands/mobile/put_file_request.cc2
-rw-r--r--src/components/application_manager/src/message_helper.cc2
-rw-r--r--src/components/application_manager/src/resumption/resumption_data_db.cc10
-rw-r--r--src/components/formatters/CMakeLists.txt1
-rw-r--r--src/components/formatters/src/CFormatterJsonBase.cc10
-rw-r--r--src/components/formatters/src/CFormatterJsonSDLRPCv1.cc66
-rw-r--r--src/components/formatters/src/formatter_json_rpc.cc7
-rw-r--r--src/components/smart_objects/include/smart_objects/number_schema_item.h2
-rw-r--r--src/components/smart_objects/include/smart_objects/smart_object.h26
-rw-r--r--src/components/smart_objects/src/smart_object.cc31
-rw-r--r--src/components/time_tester/src/application_manager_metric.cc9
-rw-r--r--src/components/utils/CMakeLists.txt1
-rw-r--r--src/components/utils/include/utils/convert_utils.h50
-rw-r--r--src/components/utils/src/convert_utils.cc65
14 files changed, 211 insertions, 71 deletions
diff --git a/src/components/application_manager/src/commands/mobile/put_file_request.cc b/src/components/application_manager/src/commands/mobile/put_file_request.cc
index 0dfc784c84..624587d0ce 100644
--- a/src/components/application_manager/src/commands/mobile/put_file_request.cc
+++ b/src/components/application_manager/src/commands/mobile/put_file_request.cc
@@ -127,7 +127,7 @@ void PutFileRequest::Run() {
(*message_)[strings::msg_params].keyExists(strings::offset);
if (offset_exist) {
- offset_ = (*message_)[strings::msg_params][strings::offset].asInt64();
+ offset_ = (*message_)[strings::msg_params][strings::offset].asInt();
}
if ((*message_)[strings::msg_params].
diff --git a/src/components/application_manager/src/message_helper.cc b/src/components/application_manager/src/message_helper.cc
index c5d47ae583..eb7006c6ae 100644
--- a/src/components/application_manager/src/message_helper.cc
+++ b/src/components/application_manager/src/message_helper.cc
@@ -2555,7 +2555,7 @@ bool MessageHelper::PrintSmartObject(const smart_objects::SmartObject& object) {
break;
}
case NsSmartDeviceLink::NsSmartObjects::SmartType_Integer:
- printf("%" PRId64 "\n", object.asInt64());
+ printf("%" PRId64 "\n", object.asInt());
break;
case NsSmartDeviceLink::NsSmartObjects::SmartType_String:
printf("%s", object.asString().c_str());
diff --git a/src/components/application_manager/src/resumption/resumption_data_db.cc b/src/components/application_manager/src/resumption/resumption_data_db.cc
index d087b2061f..657b7913c6 100644
--- a/src/components/application_manager/src/resumption/resumption_data_db.cc
+++ b/src/components/application_manager/src/resumption/resumption_data_db.cc
@@ -2615,11 +2615,11 @@ ApplicationParams::ApplicationParams(
}
m_is_valid = true;
m_hash = application[hash_id].asString();
- m_grammar_id = application[grammar_id].asInt64();
- m_connection_key = application[connection_key].asInt64();
- m_hmi_app_id = application[hmi_app_id].asInt64();
- m_hmi_level = static_cast<mobile_apis::HMILevel::eType>(
- application[hmi_level].asInt());
+ m_grammar_id = application[grammar_id].asInt();
+ m_connection_key = application[connection_key].asInt();
+ m_hmi_app_id = application[hmi_app_id].asInt();
+ m_hmi_level =
+ static_cast<mobile_apis::HMILevel::eType>(application[hmi_level].asInt());
m_is_media_application = application[is_media_application].asBool();
}
diff --git a/src/components/formatters/CMakeLists.txt b/src/components/formatters/CMakeLists.txt
index ea089955dc..1858342ff3 100644
--- a/src/components/formatters/CMakeLists.txt
+++ b/src/components/formatters/CMakeLists.txt
@@ -38,6 +38,7 @@ include_directories (
${JSONCPP_INCLUDE_DIRECTORY}
${MESSAGE_BROKER_INCLUDE_DIRECTORY}
${COMPONENTS_DIR}/smart_objects/include
+ ${COMPONENTS_DIR}/utils/include
)
set (SOURCES
diff --git a/src/components/formatters/src/CFormatterJsonBase.cc b/src/components/formatters/src/CFormatterJsonBase.cc
index 08773bc1dd..8c2a70f1d4 100644
--- a/src/components/formatters/src/CFormatterJsonBase.cc
+++ b/src/components/formatters/src/CFormatterJsonBase.cc
@@ -32,8 +32,8 @@
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#include "json/json.h"
-
#include "formatters/CFormatterJsonBase.h"
+#include "utils/convert_utils.h"
void NsSmartDeviceLink::NsJSONHandler::Formatters::CFormatterJsonBase::jsonValueToObj(
const Json::Value& value,
@@ -56,9 +56,9 @@ void NsSmartDeviceLink::NsJSONHandler::Formatters::CFormatterJsonBase::jsonValue
jsonValueToObj(value[i], obj[i]);
}
} else if (value.type() == Json::intValue) {
- obj = value.asInt();
+ obj = utils::ConvertLongLongIntToInt64(value.asInt64());
} else if (value.type() == Json::uintValue) {
- obj = value.asUInt();
+ obj = utils::ConvertLongLongUIntToUInt64(value.asUInt64());
} else if (value.type() == Json::realValue) {
obj = value.asDouble();
} else if (value.type() == Json::booleanValue) {
@@ -104,10 +104,10 @@ void NsSmartDeviceLink::NsJSONHandler::Formatters::CFormatterJsonBase::objToJson
item = obj.asBool();
} else if (NsSmartDeviceLink::NsSmartObjects::SmartType_Integer
== obj.getType()) {
- item = obj.asInt();
+ item = utils::ConvertInt64ToLongLongInt(obj.asInt());
} else if (NsSmartDeviceLink::NsSmartObjects::SmartType_UInteger
== obj.getType()) {
- item = obj.asUInt();
+ item = utils::ConvertUInt64ToLongLongUInt(obj.asUInt());
} else if (NsSmartDeviceLink::NsSmartObjects::SmartType_Double
== obj.getType()) {
item = obj.asDouble();
diff --git a/src/components/formatters/src/CFormatterJsonSDLRPCv1.cc b/src/components/formatters/src/CFormatterJsonSDLRPCv1.cc
index 1f29a20d7e..f490b85ea6 100644
--- a/src/components/formatters/src/CFormatterJsonSDLRPCv1.cc
+++ b/src/components/formatters/src/CFormatterJsonSDLRPCv1.cc
@@ -1,34 +1,38 @@
-// Copyright (c) 2013, Ford Motor Company
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following
-// disclaimer in the documentation and/or other materials provided with the
-// distribution.
-//
-// Neither the name of the Ford Motor Company nor the names of its contributors
-// may be used to endorse or promote products derived from this software
-// without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 'A PARTICULAR PURPOSE
-// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
-// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-// POSSIBILITY OF SUCH DAMAGE.
+/*
+ * Copyright (c) 2015, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
#include "formatters/CFormatterJsonSDLRPCv1.h"
#include "formatters/meta_formatter.h"
+#include "utils/convert_utils.h"
namespace strings = NsSmartDeviceLink::NsJSONHandler::strings;
namespace smart_objects_ns = NsSmartDeviceLink::NsSmartObjects;
@@ -96,8 +100,8 @@ bool CFormatterJsonSDLRPCv1::toString(const smart_objects_ns::SmartObject& obj,
root[type][S_PARAMETERS] = params;
if (formattedObj[strings::S_PARAMS].keyExists(strings::S_CORRELATION_ID)) {
- root[type][S_CORRELATION_ID] =
- formattedObj[strings::S_PARAMS][strings::S_CORRELATION_ID].asInt();
+ root[type][S_CORRELATION_ID] = utils::ConvertInt64ToLongLongInt(
+ formattedObj[strings::S_PARAMS][strings::S_CORRELATION_ID].asInt());
}
root[type][S_NAME] = formattedObj[strings::S_PARAMS][strings::S_FUNCTION_ID]
diff --git a/src/components/formatters/src/formatter_json_rpc.cc b/src/components/formatters/src/formatter_json_rpc.cc
index 012962bbb2..6c6e47069f 100644
--- a/src/components/formatters/src/formatter_json_rpc.cc
+++ b/src/components/formatters/src/formatter_json_rpc.cc
@@ -33,6 +33,7 @@
// POSSIBILITY OF SUCH DAMAGE.
#include "formatters/formatter_json_rpc.h"
+#include "utils/convert_utils.h"
namespace NsSmartDeviceLink {
namespace NsJSONHandler {
@@ -118,7 +119,7 @@ bool FormatterJsonRpc::ToString(const NsSmartObjects::SmartObject &obj,
if (NsSmartObjects::SmartType_Integer != code.getType()) {
result = false;
} else {
- root[kResult][kCode] = code.asInt();
+ root[kResult][kCode] = utils::ConvertInt64ToLongLongInt(code.asInt());
}
}
} else if (kNotification == message_type) {
@@ -134,7 +135,7 @@ bool FormatterJsonRpc::ToString(const NsSmartObjects::SmartObject &obj,
if (NsSmartObjects::SmartType_Integer != code.getType()) {
result = false;
} else {
- root[kError][kCode] = code.asInt();
+ root[kError][kCode] = utils::ConvertInt64ToLongLongInt(code.asInt());
}
}
}
@@ -174,7 +175,7 @@ bool FormatterJsonRpc::SetId(const NsSmartObjects::SmartObject &params,
strings::S_CORRELATION_ID);
if (NsSmartObjects::SmartType_Integer == id.getType()) {
- id_container[kId] = id.asUInt();
+ id_container[kId] = utils::ConvertUInt64ToLongLongUInt(id.asUInt());
result = true;
}
}
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 6a3d3eb284..8dfcff369e 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
@@ -137,7 +137,7 @@ Errors::eType TNumberSchemaItem<NumberType>::validate(const SmartObject& Object)
} else if (typeid(double) == typeid(value)) {
value = Object.asDouble();
} else if (typeid(int64_t) == typeid(value)) {
- value = Object.asInt64();
+ value = Object.asInt();
} else {
NOTREACHED();
}
diff --git a/src/components/smart_objects/include/smart_objects/smart_object.h b/src/components/smart_objects/include/smart_objects/smart_object.h
index eca1199cec..ae61b1de5b 100644
--- a/src/components/smart_objects/include/smart_objects/smart_object.h
+++ b/src/components/smart_objects/include/smart_objects/smart_object.h
@@ -132,6 +132,7 @@ typedef std::vector<SmartObjectSPtr> SmartObjectList;
* This class act as Variant type from other languages and can be used as primitive type
* like bool, int32_t, char, double, string and as complex type like array and map.
**/
+
class SmartObject FINAL {
public:
/**
@@ -200,11 +201,11 @@ class SmartObject FINAL {
explicit SmartObject(int32_t InitialValue);
/**
- * @brief Returns current object converted to int32_t
+ * @brief Returns current object converted to int64_t
*
- * @return int32_t
+ * @return int64_t
**/
- int32_t asInt() const;
+ int64_t asInt() const;
/**
* @brief Assignment operator for type: int32_t
@@ -231,11 +232,11 @@ class SmartObject FINAL {
explicit SmartObject(uint32_t InitialValue);
/**
- * @brief Returns current object converted to uint32_t int32_t
+ * @brief Returns current object converted to uint64_t
*
- * @return double
+ * @return uint64_t
**/
- uint32_t asUInt() const;
+ uint64_t asUInt() const;
/**
* @brief Assignment operator for type: int32_t
@@ -287,6 +288,19 @@ class SmartObject FINAL {
**/
bool operator==(int64_t Value) const;
+ /**
+ * @name Support of type: uint64_t
+ * @{
+ **/
+
+ /**
+ * @brief Assignment operator for type: uint64_t
+ *
+ * @param NewValue New object value
+ * @return SmartObject&
+ **/
+ SmartObject& operator=(const uint64_t NewValue);
+
/** @} */
/**
diff --git a/src/components/smart_objects/src/smart_object.cc b/src/components/smart_objects/src/smart_object.cc
index 599141f087..e58179f0bb 100644
--- a/src/components/smart_objects/src/smart_object.cc
+++ b/src/components/smart_objects/src/smart_object.cc
@@ -180,14 +180,12 @@ SmartObject::SmartObject(int32_t InitialValue)
set_value_integer(InitialValue);
}
-int32_t SmartObject::asInt() const {
+int64_t SmartObject::asInt() const {
const int64_t convert = convert_int();
if (invalid_int64_value == convert) {
return invalid_int_value;
}
- DCHECK(convert >= std::numeric_limits<int32_t>::min());
- DCHECK(convert <= std::numeric_limits<int32_t>::max());
- return static_cast<int32_t>(convert);
+ return convert;
}
SmartObject& SmartObject::operator=(const int32_t NewValue) {
@@ -243,14 +241,12 @@ SmartObject::SmartObject(uint32_t InitialValue)
set_value_integer(InitialValue);
}
-uint32_t SmartObject::asUInt() const {
+uint64_t SmartObject::asUInt() const {
const int64_t convert = convert_int();
- if (invalid_int64_value == convert) {
- return invalid_unsigned_int_value;
+ if (convert <= invalid_int_value) {
+ return invalid_unsigned_int_value;
}
- DCHECK(convert >= std::numeric_limits<uint32_t>::min());
- DCHECK(convert <= std::numeric_limits<uint32_t>::max());
- return static_cast<uint32_t>(convert);
+ return static_cast<uint64_t>(convert);
}
SmartObject& SmartObject::operator=(const uint32_t NewValue) {
@@ -278,10 +274,6 @@ SmartObject::SmartObject(int64_t InitialValue)
set_value_integer(InitialValue);
}
-int64_t SmartObject::asInt64() const {
- return convert_int();
-}
-
SmartObject& SmartObject::operator=(const int64_t NewValue) {
if (m_type != SmartType_Invalid) {
set_value_integer(NewValue);
@@ -298,6 +290,17 @@ bool SmartObject::operator==(const int64_t Value) const {
}
// =============================================================
+// uint64_t TYPE SUPPORT
+// =============================================================
+SmartObject& SmartObject::operator=(const uint64_t NewValue) {
+ if (m_type != SmartType_Invalid) {
+ set_value_integer(NewValue);
+ }
+ return *this;
+}
+
+
+// =============================================================
// DOUBLE TYPE SUPPORT
// =============================================================
SmartObject::SmartObject(double InitialValue)
diff --git a/src/components/time_tester/src/application_manager_metric.cc b/src/components/time_tester/src/application_manager_metric.cc
index debfa9b9e9..3b6dc7f0e4 100644
--- a/src/components/time_tester/src/application_manager_metric.cc
+++ b/src/components/time_tester/src/application_manager_metric.cc
@@ -33,6 +33,7 @@
#include "time_tester/application_manager_metric.h"
#include "time_tester/json_keys.h"
#include "application_manager/smart_object_keys.h"
+#include "utils/convert_utils.h"
namespace time_tester {
@@ -45,10 +46,10 @@ Json::Value ApplicationManagerMetricWrapper::GetJsonMetric() {
Json::Int64(date_time::DateTime::getuSecs(message_metric->end));
const NsSmartDeviceLink::NsSmartObjects::SmartObject& params =
message_metric->message->getElement(application_manager::strings::params);
- result[strings::correlation_id] =
- params[application_manager::strings::correlation_id].asInt();
- result[strings::connection_key] =
- params[application_manager::strings::connection_key].asInt();
+ result[strings::correlation_id] = utils::ConvertInt64ToLongLongInt(
+ params[application_manager::strings::correlation_id].asInt());
+ result[strings::connection_key] = utils::ConvertInt64ToLongLongInt(
+ params[application_manager::strings::connection_key].asInt());
return result;
}
} // namespace time_tester
diff --git a/src/components/utils/CMakeLists.txt b/src/components/utils/CMakeLists.txt
index 2770d30114..cc301c5f4f 100644
--- a/src/components/utils/CMakeLists.txt
+++ b/src/components/utils/CMakeLists.txt
@@ -56,6 +56,7 @@ set (SOURCES
${UTILS_SRC_DIR}/resource_usage.cc
${UTILS_SRC_DIR}/appenders_loader.cc
${UTILS_SRC_DIR}/gen_hash.cc
+ ${UTILS_SRC_DIR}/convert_utils.cc
)
if(ENABLE_LOG)
diff --git a/src/components/utils/include/utils/convert_utils.h b/src/components/utils/include/utils/convert_utils.h
new file mode 100644
index 0000000000..d3b2b208b0
--- /dev/null
+++ b/src/components/utils/include/utils/convert_utils.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2015, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef SRC_COMPONENTS_UTILS_INCLUDE_UTILS_CONVERT_UTILS_H_
+#define SRC_COMPONENTS_UTILS_INCLUDE_UTILS_CONVERT_UTILS_H_
+
+#include <stdint.h>
+
+namespace utils {
+
+long long int ConvertInt64ToLongLongInt(const int64_t value);
+
+int64_t ConvertLongLongIntToInt64(long long int value);
+
+unsigned long long int ConvertUInt64ToLongLongUInt(uint64_t value);
+
+uint64_t ConvertLongLongUIntToUInt64(unsigned long long int value);
+
+} // namespace utils
+
+#endif // SRC_COMPONENTS_UTILS_INCLUDE_UTILS_CONVERT_UTILS_H_
diff --git a/src/components/utils/src/convert_utils.cc b/src/components/utils/src/convert_utils.cc
new file mode 100644
index 0000000000..cf24221f16
--- /dev/null
+++ b/src/components/utils/src/convert_utils.cc
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2015, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "utils/convert_utils.h"
+#include <stdint.h>
+#include <limits>
+#include <algorithm>
+#include "utils/macro.h"
+
+long long int utils::ConvertInt64ToLongLongInt(const int64_t value) {
+ return static_cast<long long int>(value);
+}
+
+int64_t utils::ConvertLongLongIntToInt64(long long int value) {
+ if (value <= std::numeric_limits<int64_t>::min()) {
+ return std::min<int64_t>(value, std::numeric_limits<int64_t>::min());
+ }
+ if (value >= std::numeric_limits<int64_t>::max()) {
+ return std::max<int64_t>(value, std::numeric_limits<int64_t>::max());
+ }
+ return static_cast<int64_t>(value);
+}
+
+unsigned long long int utils::ConvertUInt64ToLongLongUInt(uint64_t value) {
+ return static_cast<unsigned long long int>(value);
+}
+
+uint64_t utils::ConvertLongLongUIntToUInt64(unsigned long long int value) {
+ if (value <= std::numeric_limits<uint64_t>::min()) {
+ return std::min<uint64_t>(value, std::numeric_limits<uint64_t>::min());
+ }
+ if (value >= std::numeric_limits<uint64_t>::max()) {
+ return std::max<uint64_t>(value, std::numeric_limits<uint64_t>::max());
+ }
+ return static_cast<uint64_t>(value);
+}