From f3c61e2c35a19cb5d0b749f394c26f70792bda2d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20Szczekutek?= Date: Mon, 27 Jun 2016 15:28:21 +0200 Subject: [PATCH] [Base-utils][Measure] Complete module added. Change-Id: I370b4535a229588dc25c34dbb9fa4da208742777 Signed-off-by: Beata Stefaniuk --- src/CMakeLists.txt | 2 + src/include/mobile/utils_i18n.h | 32 ++++- src/include/mobile/utils_i18n_measure.h | 135 ++++++++++++++++++++++ src/include/wearable/utils_i18n.h | 34 +++++- src/include/wearable/utils_i18n_measure.h | 135 ++++++++++++++++++++++ src/utils_i18n_measure.cpp | 73 ++++++++++++ 6 files changed, 408 insertions(+), 3 deletions(-) create mode 100644 src/include/mobile/utils_i18n_measure.h create mode 100644 src/include/wearable/utils_i18n_measure.h create mode 100644 src/utils_i18n_measure.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4b10621..0e58af7 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -36,6 +36,7 @@ SET(BASEUTILS_SRCS utils_i18n_alpha_idx.cpp utils_i18n_formattable.cpp utils_i18n_measure_unit.cpp + utils_i18n_measure.cpp ) ADD_LIBRARY(${target_name} SHARED ${BASEUTILS_SRCS} @@ -73,5 +74,6 @@ INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${INC_DIR}/utils_i18n_ubrk.h DESTINATI INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${INC_DIR}/utils_i18n_alpha_idx.h DESTINATION ${INCLUDE_INSTALL_DIR}/base) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${INC_DIR}/utils_i18n_formattable.h DESTINATION ${INCLUDE_INSTALL_DIR}/base) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${INC_DIR}/utils_i18n_measure_unit.h DESTINATION ${INCLUDE_INSTALL_DIR}/base) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${INC_DIR}/utils_i18n_measure.h DESTINATION ${INCLUDE_INSTALL_DIR}/base) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${INC_DIR}/utils_i18n.h DESTINATION ${INCLUDE_INSTALL_DIR}/base) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${pc_name}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) \ No newline at end of file diff --git a/src/include/mobile/utils_i18n.h b/src/include/mobile/utils_i18n.h index ae86d15..507c92e 100644 --- a/src/include/mobile/utils_i18n.h +++ b/src/include/mobile/utils_i18n.h @@ -35,6 +35,7 @@ #include #include #include +#include /** * @file utils_i18n.h @@ -49,7 +50,7 @@ extern "C" { /** * @ingroup CAPI_BASE_UTILS_MODULE * @defgroup CAPI_BASE_UTILS_I18N_MODULE i18n - * @brief The i18n module contains uchar, ucollator, unormalization, usearch, ustring, ucalendar, udate, udatepg, ulocale, unumber, alpha_idx, formattable and measure unit. + * @brief The i18n module contains uchar, ucollator, unormalization, usearch, ustring, ucalendar, udate, udatepg, ulocale, unumber, alpha_idx, formattable, measure unit and measure. * This module provides flexible generation of number or date format patterns and helps you format and parse dates/number for any locale. * The i18n module provides various features based on data from ICU. The following table shows the version of ICU used in each Tizen platform. * @@ -137,6 +138,10 @@ extern "C" { * * * + * + * + * + * *
@ref CAPI_BASE_UTILS_I18N_MEASURE_UNIT_MODULEThe MeasureUnit module contains units such as length, mass, volume, currency, etc...
@ref CAPI_BASE_UTILS_I18N_MEASURE_MODULEThe Measure module represents an amount of a specified unit, consisting of a number and a unit.
* * @section CAPI_BASE_UTILS_I18N_MODULE_MAPPING_TABLE Mapping Table @@ -2763,6 +2768,31 @@ extern "C" { * #i18n_measure_unit_create_teaspoon * createTeaspoon * + * + * @ref CAPI_BASE_UTILS_I18N_MEASURE_MODULE + * #i18n_measure_create + * Measure + * + * + * @ref CAPI_BASE_UTILS_I18N_MEASURE_MODULE + * #i18n_measure_clone + * clone + * + * + * @ref CAPI_BASE_UTILS_I18N_MEASURE_MODULE + * #i18n_measure_destroy + * ~Measure + * + * + * @ref CAPI_BASE_UTILS_I18N_MEASURE_MODULE + * #i18n_measure_get_number + * getNumber + * + * + * @ref CAPI_BASE_UTILS_I18N_MEASURE_MODULE + * #i18n_measure_get_unit + * getUnit + * * */ diff --git a/src/include/mobile/utils_i18n_measure.h b/src/include/mobile/utils_i18n_measure.h new file mode 100644 index 0000000..6e2c276 --- /dev/null +++ b/src/include/mobile/utils_i18n_measure.h @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __UTILS_I18N_MEASURE_H__ +#define __UTILS_I18N_MEASURE_H__ + +#include + +/** + * @file utils_i18n_measure.h + * @version 0.1 + * @brief utils_i18n_measure + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @ingroup CAPI_BASE_UTILS_I18N_MODULE + * @defgroup CAPI_BASE_UTILS_I18N_MEASURE_MODULE MeasureUnit + * @brief Measure object contains an amount of a specified unit, consisting of a number and an unit. + * @section CAPI_BASE_UTILS_I18N_MEASURE_MODULE_HEADER Required Header + *» \#include + * + * @section CAPI_BASE_UTILS_I18N_MEASURE_MODULE_OVERVIEW Overview + * @details + */ + +/** + * @addtogroup CAPI_BASE_UTILS_I18N_MEASURE_MODULE + * @{ + */ + +/** + * @brief Creates an object with the given numeric amount and the given unit. + * @details After this call, the caller must not delete the given measure unit object. + * @remarks The created object should be released by the caller with the + * #i18n_measure_destroy() function. + * @since_tizen 3.0 + * + * @param[in] formattable A numeric object; The #i18n_formattable_is_numeric() + * function must return @c true for this object. + * @param[in] measure_unit The unit object, which must not be @c NULL + * @param[out] measure The created measure object + * + * @return @c 0 on success, otherwise a negative error value + * @retval #I18N_ERROR_NONE Successful + * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter + * @retval #I18N_ERROR_OUT_OF_MEMORY Out of memory + */ +int i18n_measure_create(const i18n_formattable_h formattable, i18n_measure_unit_h measure_unit, i18n_measure_h *measure); + +/** + * @brief Creates a polymorphic clone of the given @a clone object. + * @remarks The @c clone object should be released by the caller with the + * #i18n_measure_destroy() function. + * @since_tizen 3.0 + * + * @param[in] measure The measure object to be cloned + * @param[out] clone The created measure object + * + * @return @c 0 on success, otherwise a negative error value + * @retval #I18N_ERROR_NONE Successful + * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter + * @retval #I18N_ERROR_OUT_OF_MEMORY Out of memory + */ +int i18n_measure_clone(i18n_measure_h measure, i18n_measure_h *clone); + +/** + * @brief Destroys the measure object + * @since_tizen 3.0 + * + * @param[in] measure The measure object to destroy + * + * @return @c 0 on success, otherwise a negative error value + * @retval #I18N_ERROR_NONE Successful + * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter + */ +int i18n_measure_destroy(i18n_measure_h measure); + +/** + * @brief Gets a reference to the numeric value of the measure object. + * @remarks The obtained formattable object should be released by the caller + * with the #i18n_formattable_destroy() function. + * @since_tizen 3.0 + * + * @param[in] measure The measure object + * @param[out] formattable The numeric value of the measure object + * + * @return @c 0 on success, otherwise a negative error value + * @retval #I18N_ERROR_NONE Successful + * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter + * @retval #I18N_ERROR_OUT_OF_MEMORY Out of memory + */ +int i18n_measure_get_number(i18n_measure_h measure, i18n_formattable_h *formattable); + +/** + * @brief Gets a reference to the unit of the measure object. + * @remarks The obtained measure unit object should be released by the caller + * with the #i18n_measure_unit_destroy() function. + * @since_tizen 3.0 + * + * @param[in] measure The measure object + * @param[out] measure_unit The unit of the measure object + * + * @return @c 0 on success, otherwise a negative error value + * @retval #I18N_ERROR_NONE Successful + * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter + * @retval #I18N_ERROR_OUT_OF_MEMORY Out of memory + */ +int i18n_measure_get_unit(i18n_measure_h measure, i18n_measure_unit_h *measure_unit); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* __UTILS_I18N_MEASURE_H__*/ diff --git a/src/include/wearable/utils_i18n.h b/src/include/wearable/utils_i18n.h index fc0495f..5c288d1 100644 --- a/src/include/wearable/utils_i18n.h +++ b/src/include/wearable/utils_i18n.h @@ -35,6 +35,7 @@ #include #include #include +#include /** * @file utils_i18n.h @@ -49,7 +50,7 @@ extern "C" { /** * @ingroup CAPI_BASE_UTILS_MODULE * @defgroup CAPI_BASE_UTILS_I18N_MODULE i18n - * @brief The i18n module contains uchar, ucollator, unormalization, usearch, ustring, ucalendar, udate, udatepg, ulocale, unumber, alpha_idx and formattable. + * @brief The i18n module contains uchar, ucollator, unormalization, usearch, ustring, ucalendar, udate, udatepg, ulocale, unumber, alpha_idx, formattable and measure. * This module provides flexible generation of number or date format patterns and helps you format and parse dates/number for any locale. * The i18n module provides various features based on data from ICU. The following table shows the version of ICU used in each Tizen platform. * @@ -135,7 +136,11 @@ extern "C" { * * * - * + * + * + * + * + * * *
@ref CAPI_BASE_UTILS_I18N_MEASURE_UNIT_MODULEThe MeasureUnit module contains unit such as length, mass, volume, currency, etc..The MeasureUnit module contains units such as length, mass, volume, currency, etc...
@ref CAPI_BASE_UTILS_I18N_MEASURE_MODULEThe Measure module represents an amount of a specified unit, consisting of a number and a unit.
* @@ -2763,6 +2768,31 @@ extern "C" { * #i18n_measure_unit_create_teaspoon * createTeaspoon * + * + * @ref CAPI_BASE_UTILS_I18N_MEASURE_MODULE + * #i18n_measure_create + * Measure + * + * + * @ref CAPI_BASE_UTILS_I18N_MEASURE_MODULE + * #i18n_measure_clone + * clone + * + * + * @ref CAPI_BASE_UTILS_I18N_MEASURE_MODULE + * #i18n_measure_destroy + * ~Measure + * + * + * @ref CAPI_BASE_UTILS_I18N_MEASURE_MODULE + * #i18n_measure_get_number + * getNumber + * + * + * @ref CAPI_BASE_UTILS_I18N_MEASURE_MODULE + * #i18n_measure_get_unit + * getUnit + * * */ diff --git a/src/include/wearable/utils_i18n_measure.h b/src/include/wearable/utils_i18n_measure.h new file mode 100644 index 0000000..6e2c276 --- /dev/null +++ b/src/include/wearable/utils_i18n_measure.h @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __UTILS_I18N_MEASURE_H__ +#define __UTILS_I18N_MEASURE_H__ + +#include + +/** + * @file utils_i18n_measure.h + * @version 0.1 + * @brief utils_i18n_measure + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @ingroup CAPI_BASE_UTILS_I18N_MODULE + * @defgroup CAPI_BASE_UTILS_I18N_MEASURE_MODULE MeasureUnit + * @brief Measure object contains an amount of a specified unit, consisting of a number and an unit. + * @section CAPI_BASE_UTILS_I18N_MEASURE_MODULE_HEADER Required Header + *» \#include + * + * @section CAPI_BASE_UTILS_I18N_MEASURE_MODULE_OVERVIEW Overview + * @details + */ + +/** + * @addtogroup CAPI_BASE_UTILS_I18N_MEASURE_MODULE + * @{ + */ + +/** + * @brief Creates an object with the given numeric amount and the given unit. + * @details After this call, the caller must not delete the given measure unit object. + * @remarks The created object should be released by the caller with the + * #i18n_measure_destroy() function. + * @since_tizen 3.0 + * + * @param[in] formattable A numeric object; The #i18n_formattable_is_numeric() + * function must return @c true for this object. + * @param[in] measure_unit The unit object, which must not be @c NULL + * @param[out] measure The created measure object + * + * @return @c 0 on success, otherwise a negative error value + * @retval #I18N_ERROR_NONE Successful + * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter + * @retval #I18N_ERROR_OUT_OF_MEMORY Out of memory + */ +int i18n_measure_create(const i18n_formattable_h formattable, i18n_measure_unit_h measure_unit, i18n_measure_h *measure); + +/** + * @brief Creates a polymorphic clone of the given @a clone object. + * @remarks The @c clone object should be released by the caller with the + * #i18n_measure_destroy() function. + * @since_tizen 3.0 + * + * @param[in] measure The measure object to be cloned + * @param[out] clone The created measure object + * + * @return @c 0 on success, otherwise a negative error value + * @retval #I18N_ERROR_NONE Successful + * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter + * @retval #I18N_ERROR_OUT_OF_MEMORY Out of memory + */ +int i18n_measure_clone(i18n_measure_h measure, i18n_measure_h *clone); + +/** + * @brief Destroys the measure object + * @since_tizen 3.0 + * + * @param[in] measure The measure object to destroy + * + * @return @c 0 on success, otherwise a negative error value + * @retval #I18N_ERROR_NONE Successful + * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter + */ +int i18n_measure_destroy(i18n_measure_h measure); + +/** + * @brief Gets a reference to the numeric value of the measure object. + * @remarks The obtained formattable object should be released by the caller + * with the #i18n_formattable_destroy() function. + * @since_tizen 3.0 + * + * @param[in] measure The measure object + * @param[out] formattable The numeric value of the measure object + * + * @return @c 0 on success, otherwise a negative error value + * @retval #I18N_ERROR_NONE Successful + * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter + * @retval #I18N_ERROR_OUT_OF_MEMORY Out of memory + */ +int i18n_measure_get_number(i18n_measure_h measure, i18n_formattable_h *formattable); + +/** + * @brief Gets a reference to the unit of the measure object. + * @remarks The obtained measure unit object should be released by the caller + * with the #i18n_measure_unit_destroy() function. + * @since_tizen 3.0 + * + * @param[in] measure The measure object + * @param[out] measure_unit The unit of the measure object + * + * @return @c 0 on success, otherwise a negative error value + * @retval #I18N_ERROR_NONE Successful + * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter + * @retval #I18N_ERROR_OUT_OF_MEMORY Out of memory + */ +int i18n_measure_get_unit(i18n_measure_h measure, i18n_measure_unit_h *measure_unit); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* __UTILS_I18N_MEASURE_H__*/ diff --git a/src/utils_i18n_measure.cpp b/src/utils_i18n_measure.cpp new file mode 100644 index 0000000..037b864 --- /dev/null +++ b/src/utils_i18n_measure.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include +#include + +int i18n_measure_create(const i18n_formattable_h formattable, i18n_measure_unit_h measure_unit, i18n_measure_h *measure) +{ + retv_if(measure == NULL || formattable == NULL || measure_unit == NULL, I18N_ERROR_INVALID_PARAMETER); + UErrorCode status = U_ZERO_ERROR; + + *measure = new Measure(*((Formattable *) formattable), (MeasureUnit *) measure_unit, status); + retv_if(*measure == NULL, I18N_ERROR_OUT_OF_MEMORY); + + return _i18n_error_mapping(status); +} + +int i18n_measure_clone(i18n_measure_h measure, i18n_measure_h *clone) +{ + retv_if(measure == NULL || clone == NULL, I18N_ERROR_INVALID_PARAMETER); + + *clone = ((Measure *) measure)->clone(); + retv_if(*clone == NULL, I18N_ERROR_OUT_OF_MEMORY); + + return I18N_ERROR_NONE; +} + +int i18n_measure_destroy(i18n_measure_h measure) +{ + retv_if(measure == NULL, I18N_ERROR_INVALID_PARAMETER); + + delete((Measure *) measure); + + return I18N_ERROR_NONE; +} + +int i18n_measure_get_number(i18n_measure_h measure, i18n_formattable_h *formattable) +{ + retv_if(measure == NULL || formattable == NULL, I18N_ERROR_INVALID_PARAMETER); + + Formattable frmttbl = ((Measure *) measure)->getNumber(); + *formattable = frmttbl.clone(); + retv_if(*formattable == NULL, I18N_ERROR_OUT_OF_MEMORY); + + return I18N_ERROR_NONE; +} + +int i18n_measure_get_unit(i18n_measure_h measure, i18n_measure_unit_h *measure_unit) +{ + retv_if(measure == NULL || measure_unit == NULL, I18N_ERROR_INVALID_PARAMETER); + + MeasureUnit mu = ((Measure *) measure)->getUnit(); + *measure_unit = mu.clone(); + retv_if(*measure_unit == NULL, I18N_ERROR_OUT_OF_MEMORY); + + return I18N_ERROR_NONE; +} -- 2.34.1