[Base-utils][Measure] Complete module added. 91/69091/18
authorRafał Szczekutek <r.szczekutek@samsung.com>
Mon, 27 Jun 2016 13:28:21 +0000 (15:28 +0200)
committerRafał Szczekutek <r.szczekutek@samsung.com>
Mon, 27 Jun 2016 13:28:21 +0000 (15:28 +0200)
Change-Id: I370b4535a229588dc25c34dbb9fa4da208742777
Signed-off-by: Beata Stefaniuk <b.stefaniuk@samsung.com>
src/CMakeLists.txt
src/include/mobile/utils_i18n.h
src/include/mobile/utils_i18n_measure.h [new file with mode: 0644]
src/include/wearable/utils_i18n.h
src/include/wearable/utils_i18n_measure.h [new file with mode: 0644]
src/utils_i18n_measure.cpp [new file with mode: 0644]

index 4b1062164d28dd90be07e4b9e6e93f8c7ca9e949..0e58af727dbfb02f13c1a377e899fe4353e16bb1 100755 (executable)
@@ -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
index ae86d15ed1e1c1faa27cba66235abfba5c33a67b..507c92ed9e7db381807d10f77580f98c5e22951e 100644 (file)
@@ -35,6 +35,7 @@
 #include <utils_i18n_alpha_idx.h>
 #include <utils_i18n_formattable.h>
 #include <utils_i18n_measure_unit.h>
+#include <utils_i18n_measure.h>
 
 /**
  * @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.
  * <table>
@@ -137,6 +138,10 @@ extern "C" {
  *       <td>@ref CAPI_BASE_UTILS_I18N_MEASURE_UNIT_MODULE</td>
  *       <td>The MeasureUnit module contains units such as length, mass, volume, currency, etc...</td>
  * </tr>
+ * <tr>
+ *       <td>@ref CAPI_BASE_UTILS_I18N_MEASURE_MODULE</td>
+ *       <td>The Measure module represents an amount of a specified unit, consisting of a number and a unit.</td>
+ * </tr>
  * </table>
  *
  * @section CAPI_BASE_UTILS_I18N_MODULE_MAPPING_TABLE Mapping Table
@@ -2763,6 +2768,31 @@ extern "C" {
  *       <td>#i18n_measure_unit_create_teaspoon</td>
  *       <td>createTeaspoon</td>
  * </tr>
+ * <tr>
+ *       <td>@ref CAPI_BASE_UTILS_I18N_MEASURE_MODULE</td>
+ *       <td>#i18n_measure_create</td>
+ *       <td>Measure</td>
+ * </tr>
+ * <tr>
+ *       <td>@ref CAPI_BASE_UTILS_I18N_MEASURE_MODULE</td>
+ *       <td>#i18n_measure_clone</td>
+ *       <td>clone</td>
+ * </tr>
+ * <tr>
+ *       <td>@ref CAPI_BASE_UTILS_I18N_MEASURE_MODULE</td>
+ *       <td>#i18n_measure_destroy</td>
+ *       <td>~Measure</td>
+ * </tr>
+ * <tr>
+ *       <td>@ref CAPI_BASE_UTILS_I18N_MEASURE_MODULE</td>
+ *       <td>#i18n_measure_get_number</td>
+ *       <td>getNumber</td>
+ * </tr>
+ * <tr>
+ *       <td>@ref CAPI_BASE_UTILS_I18N_MEASURE_MODULE</td>
+ *       <td>#i18n_measure_get_unit</td>
+ *       <td>getUnit</td>
+ * </tr>
  * </table>
  */
 
diff --git a/src/include/mobile/utils_i18n_measure.h b/src/include/mobile/utils_i18n_measure.h
new file mode 100644 (file)
index 0000000..6e2c276
--- /dev/null
@@ -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 <utils_i18n_types.h>
+
+/**
+ * @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 <utils_i18n.h>
+ *
+ * @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__*/
index fc0495f18e957b82bcf398159a0891f9bcdb3afb..5c288d1987f93b82120924b3fd1328a0d411a3ee 100644 (file)
@@ -35,6 +35,7 @@
 #include <utils_i18n_alpha_idx.h>
 #include <utils_i18n_formattable.h>
 #include <utils_i18n_measure_unit.h>
+#include <utils_i18n_measure.h>
 
 /**
  * @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.
  * <table>
@@ -135,7 +136,11 @@ extern "C" {
  * </tr>
  * <tr>
  *       <td>@ref CAPI_BASE_UTILS_I18N_MEASURE_UNIT_MODULE</td>
- *       <td>The MeasureUnit module contains unit such as length, mass, volume, currency, etc..</td>
+ *       <td>The MeasureUnit module contains units such as length, mass, volume, currency, etc...</td>
+ * </tr>
+ * <tr>
+ *       <td>@ref CAPI_BASE_UTILS_I18N_MEASURE_MODULE</td>
+ *       <td>The Measure module represents an amount of a specified unit, consisting of a number and a unit.</td>
  * </tr>
  * </table>
  *
@@ -2763,6 +2768,31 @@ extern "C" {
  *       <td>#i18n_measure_unit_create_teaspoon</td>
  *       <td>createTeaspoon</td>
  * </tr>
+ * <tr>
+ *       <td>@ref CAPI_BASE_UTILS_I18N_MEASURE_MODULE</td>
+ *       <td>#i18n_measure_create</td>
+ *       <td>Measure</td>
+ * </tr>
+ * <tr>
+ *       <td>@ref CAPI_BASE_UTILS_I18N_MEASURE_MODULE</td>
+ *       <td>#i18n_measure_clone</td>
+ *       <td>clone</td>
+ * </tr>
+ * <tr>
+ *       <td>@ref CAPI_BASE_UTILS_I18N_MEASURE_MODULE</td>
+ *       <td>#i18n_measure_destroy</td>
+ *       <td>~Measure</td>
+ * </tr>
+ * <tr>
+ *       <td>@ref CAPI_BASE_UTILS_I18N_MEASURE_MODULE</td>
+ *       <td>#i18n_measure_get_number</td>
+ *       <td>getNumber</td>
+ * </tr>
+ * <tr>
+ *       <td>@ref CAPI_BASE_UTILS_I18N_MEASURE_MODULE</td>
+ *       <td>#i18n_measure_get_unit</td>
+ *       <td>getUnit</td>
+ * </tr>
  * </table>
  */
 
diff --git a/src/include/wearable/utils_i18n_measure.h b/src/include/wearable/utils_i18n_measure.h
new file mode 100644 (file)
index 0000000..6e2c276
--- /dev/null
@@ -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 <utils_i18n_types.h>
+
+/**
+ * @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 <utils_i18n.h>
+ *
+ * @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 (file)
index 0000000..037b864
--- /dev/null
@@ -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 <utils_i18n_measure.h>
+#include <utils_i18n_private.h>
+
+#include <unicode/measure.h>
+#include <unicode/measunit.h>
+
+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;
+}