Making DALi public API typesafe using guaranteed types; uint8_t, uint32_t
[platform/core/uifw/dali-core.git] / dali / public-api / object / any.h
index df7022f..e3fac2a 100644 (file)
@@ -2,7 +2,7 @@
 #define __DALI_ANY_TYPE_H__
 
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 // EXTERNAL INCLUDES
 #include <typeinfo>   // operator typeid
-
+#include <cstddef>    // NULL
 
 // INTERNAL INCLUDES
 #include <dali/public-api/common/dali-common.h>
 
 namespace Dali
 {
+/**
+ * @addtogroup dali_core_object
+ * @{
+ */
 
 /**
  * @brief Stores a value of any type.
@@ -37,34 +41,39 @@ namespace Dali
  * Any floatVariable( 4.5f );
  * Any strVariable( std::string( "Hello world" ) );
  * uintVariable = 1u;
- * unsigned int variable = AnyCast< unsigned int >( uintVariable );
+ * uint32_t variable = AnyCast< uint32_t >( uintVariable );
  * if ( typeid( int ) == uintVariable.GetType() )
  * \endcode
+ * @SINCE_1_0.0
  */
 class Any
 {
 public:
   /**
-   * Default constructor.
+   * @brief Default constructor.
+   * @SINCE_1_0.0
    */
-  DALI_IMPORT_API Any();
+  DALI_CORE_API Any();
 
   /**
-   * Destructor. Free resources.
+   * @brief Destructor. Free resources.
+   * @SINCE_1_0.0
    */
-  DALI_IMPORT_API ~Any();
+  DALI_CORE_API ~Any();
 
   /**
-   * @brief Pass Assert message
+   * @brief Passes Assert message.
    *
-   * @param assertMessage Assert message to report
+   * @SINCE_1_0.0
+   * @param[in] assertMessage Assert message to report
    */
-  DALI_IMPORT_API static void AssertAlways( const char* assertMessage );
+  DALI_CORE_API static void AssertAlways( const char* assertMessage );
 
   /**
    * @brief Constructs a Any type with the given value.
    *
-   * @param[in] value The given value.
+   * @SINCE_1_0.0
+   * @param[in] value The given value
    */
   template<typename Type>
   Any( const Type& value )
@@ -73,8 +82,9 @@ public:
   }
 
   /**
-   * Copy Constructor.
-   * @param [in] any Any to be copied.
+   * @brief Copy Constructor.
+   * @SINCE_1_0.0
+   * @param[in] any Any to be copied
    */
   Any( const Any& any )
   {
@@ -93,9 +103,11 @@ public:
   /**
    * @brief Assigns a given value to the Any type.
    *
+   * @SINCE_1_0.0
+   * @param[in] value The given value
+   * @return A reference to this
    * @note If the types are different, then the current container will be re-created.
    *
-   * @param[in] value The given value.
    */
   template<typename Type>
   Any& operator=( const Type& value )
@@ -126,16 +138,19 @@ public:
   /**
    * @brief Assignment operator.
    *
+   * @SINCE_1_0.0
+   * @param[in] any Any to be assigned which contains a value of identical type to current contents.
+   * @return A reference to this
    * @exception DaliException If parameter any is of a different type.
    *
-   * @param [in] any Any to be assigned which contains a value of identical type to current contents.
    */
-  DALI_IMPORT_API Any& operator=( const Any& any );
+  DALI_CORE_API Any& operator=( const Any& any );
 
   /**
-   * @brief Get a value of type Type from container
+   * @brief Gets a value of type Type from container.
    *
-   * @param type destination of type Type to write to
+   * @SINCE_1_0.0
+   * @param[in] type destination of type Type to write to
    */
   template<typename Type>
   void Get( Type& type ) const
@@ -146,27 +161,26 @@ public:
   /**
    * @brief Returns the type info of the stored value.
    *
+   * @SINCE_1_0.0
    * @return The std::type_info of the stored value or the type info of the void
-   * type if there is no value stored.
+   * type if there is no value stored
    */
-  DALI_IMPORT_API const std::type_info& GetType() const;
+  DALI_CORE_API const std::type_info& GetType() const;
 
   /**
    * @brief Retrieves the stored value in the Any type.
    *
-   * @return The stored value.
+   * @SINCE_1_0.0
+   * @return The stored value
    */
   template<typename Type>
   const Type& Get() const
   {
-
     if ( NULL == mContainer )
     {
       AssertAlways( "Any::Get(). mContainer is NULL" );
     }
-
-    // Check if the value has the same value than the Any type.
-    if( mContainer->GetType() != typeid( Type ) )
+    else if( mContainer->GetType() != typeid( Type ) ) // Check if the value has the same value than the Any type.
     {
       AssertAlways( "Any::Get(). Trying to retrieve a value of a different type than the template one." );
     }
@@ -174,9 +188,10 @@ public:
   }
 
   /**
-   * @brief Return pointer of Type to the value stored
+   * @brief Returns pointer of Type to the value stored.
    *
-   * @return pointer to the value or NULL if no value is contained
+   * @SINCE_1_0.0
+   * @return pointer to the value, or NULL if no value is contained
    */
   template<typename Type>
   Type* GetPointer()
@@ -194,9 +209,10 @@ public:
   }
 
   /**
-   * @brief Return pointer of Type to the value stored
+   * @brief Returns pointer of Type to the value stored.
    *
-   * @return pointer to the value or NULL if no value is contained
+   * @SINCE_1_0.0
+   * @return pointer to the value, or NULL if no value is contained
    */
   template<typename Type>
   const Type* GetPointer() const
@@ -214,9 +230,10 @@ public:
   }
 
   /**
-   * @brief Returns whether container holds a value
+   * @brief Returns whether container holds a value.
    *
-   * @return true if the container is empty, else false.
+   * @SINCE_1_0.0
+   * @return @c true if the container is empty, else @c false
    */
   bool Empty() const
   {
@@ -228,17 +245,19 @@ public:
   typedef void (*DeleteFunc)( const AnyContainerBase* base );
 
   /**
-   * Base container to hold type for match verification and instance cloning function
+   * @brief Base container to hold type for match verification and instance cloning function.
    *
+   * @SINCE_1_0.0
    */
   struct AnyContainerBase
   {
     /**
-     * @brief Constructor of base container
+     * @brief Constructor of base container.
      *
-     * @param type typeid of container
-     * @param cloneFunc Cloning function to replicate this container type
-     * @param deleteFunc Deleting function to destroy this container type
+     * @SINCE_1_0.0
+     * @param[in] type typeid of container
+     * @param[in] cloneFunc Cloning function to replicate this container type
+     * @param[in] deleteFunc Deleting function to destroy this container type
      */
     AnyContainerBase( const std::type_info& type, CloneFunc cloneFunc, DeleteFunc deleteFunc )
     : mType( type ),
@@ -247,9 +266,10 @@ public:
     {}
 
     /**
-     * @brief Get the typeid of this container
+     * @brief Gets the typeid of this container.
      *
-     * @return type
+     * @SINCE_1_0.0
+     * @return Type
      */
     const std::type_info& GetType() const
     {
@@ -263,9 +283,10 @@ public:
 
 
   /**
-   * @brief Templated Clone function from container base
+   * @brief Templated Clone function from container base.
    *
-   * @param base reference to container
+   * @SINCE_1_0.0
+   * @param[in] base The reference to container
    */
   template<typename Type>
   struct AnyContainerImplCloner
@@ -277,9 +298,10 @@ public:
   };
 
   /**
-   * @brief Templated Delete function from container base
+   * @brief Templated Delete function from container base.
    *
-   * @param base pointer to container
+   * @SINCE_1_0.0
+   * @param[in] base The pointer to container
    */
   template<typename Type>
   struct AnyContainerImplDelete
@@ -291,8 +313,9 @@ public:
   };
 
   /**
-   * @brief Templated class to hold value for type
+   * @brief Templated class to hold value for type.
    *
+   * @SINCE_1_0.0
    */
   template<typename Type>
   class AnyContainerImpl : public AnyContainerBase
@@ -300,9 +323,10 @@ public:
   public:
 
     /**
-     * @brief Constructor to create container holding value of type Type
+     * @brief Constructor to create container holding value of type Type.
      *
-     * @param value Value of Type
+     * @SINCE_1_0.0
+     * @param[in] value Value of Type
      */
     AnyContainerImpl( const Type& value )
     : AnyContainerBase( typeid( Type ),
@@ -312,9 +336,10 @@ public:
     {}
 
     /**
-     * @brief Constructor to create new container of type from and existing container (cloning)
+     * @brief Constructor to create new container of type from and existing container (cloning).
      *
-     * @param base reference to base container to copy from
+     * @SINCE_1_0.0
+     * @param[in] base The reference to base container to copy from
      */
     AnyContainerImpl( const AnyContainerBase& base )
     : AnyContainerBase( typeid( Type ),
@@ -325,9 +350,10 @@ public:
     }
 
     /**
-     * @brief Get the container's stored value
+     * @brief Gets the container's stored value.
      *
-     * @return value of type Type
+     * @SINCE_1_0.0
+     * @return Value of type Type
      */
     const Type& GetValue() const
     {
@@ -335,9 +361,10 @@ public:
     }
 
     /**
-     * @brief Set the container's stored value
+     * @brief Sets the container's stored value.
      *
-     * @param value of type Type
+     * @SINCE_1_0.0
+     * @param[in] value Value of type Type
      */
     void SetValue( const Type& value )
     {
@@ -345,9 +372,10 @@ public:
     }
 
     /**
-     * @brief Get a pointer to the value held
+     * @brief Gets a pointer to the value held.
      *
-     * @return pointer to the value of type Type
+     * @SINCE_1_0.0
+     * @return Pointer to the value of type Type
      */
     Type* GetPointerToValue()
     {
@@ -355,9 +383,10 @@ public:
     }
 
     /**
-     * @brief Get a pointer to the value held
+     * @brief Gets a pointer to the value held.
      *
-     * @return pointer to the value of type Type
+     * @SINCE_1_0.0
+     * @return Pointer to the value of type Type
      */
     const Type* GetPointerToValue() const
     {
@@ -373,81 +402,96 @@ public:
 };
 
 /**
- * AnyCast helper functions ( replicates boost functionality, but without exception generation )
+ * AnyCast helper functions
  */
 
 /**
- * @brief Extract a pointer to the held type of an Any object from a pointer to that Any object (NULL if empty )
+ * @brief Extracts a pointer to the held type of an Any object from a pointer to that Any object (NULL if empty).
  *
- * @param any Pointer to an Any object
+ * @SINCE_1_0.0
+ * @param[in] any Pointer to an Any object
  *
  * @return Pointer to the Type held
  */
-template<typename Type>inline Type* AnyCast( Any* any )
+template<typename Type>
+inline Type* AnyCast( Any* any )
 {
   return any->GetPointer<Type>();
 }
 
 /**
- * @brief Extract a const pointer to the held type of an Any object from a pointer to that Any object (NULL if empty )
+ * @brief Extracts a const pointer to the held type of an Any object from a pointer to that Any object (NULL if empty).
  *
- * @param any const Pointer to an Any object
+ * @SINCE_1_0.0
+ * @param[in] any const Pointer to an Any object
  *
  * @return const Pointer to the Type held
  */
-template<typename Type>inline const Type* AnyCast( const Any* any )
+template<typename Type>
+inline const Type* AnyCast( const Any* any )
 {
   return any->GetPointer<Type>();
 }
 
 /**
- * @brief Extract a held value of type Type from an Any object from a reference to that Any object
+ * @brief Extracts a held value of type Type from an Any object from a reference to that Any object.
  *
- * @param any reference to an Any object
+ * @SINCE_1_0.0
+ * @param[in] any The reference to an Any object
  *
  * @return Type value of type Type
  */
-template<typename Type>inline Type AnyCast( Any& any )
+template<typename Type>
+inline Type AnyCast( Any& any )
 {
   return any.Get<Type>();
 }
 
 /**
- * @brief Extract a held value of type Type from an Any object from a const reference to that Any object
+ * @brief Extracts a held value of type Type from an Any object from a const reference to that Any object.
  *
- * @param any reference to an Any object
+ * @SINCE_1_0.0
+ * @param[in] any The reference to an Any object
  *
  * @return Type value of type Type
  */
-template<typename Type>inline Type AnyCast( const Any& any )
+template<typename Type>
+inline Type AnyCast( const Any& any )
 {
   return any.Get<Type>();
 }
 
 /**
- * @brief Extract a reference to the held value of type Type from an Any object from a reference to that Any object
+ * @brief Extracts a reference to the held value of type Type from an Any object from a reference to that Any object
  *
- * @param any reference to an Any object
+ * @SINCE_1_0.0
+ * @param[in] any The reference to an Any object
  *
  * @return A reference to the Type value of type Type
  */
-template<typename Type>inline Type& AnyCastReference( Any& any )
+template<typename Type>
+inline Type& AnyCastReference( Any& any )
 {
   return any.Get<Type>();
 }
 
 /**
- * @brief Extract a const reference to the held value of type Type from an Any object from a const reference to that Any object
+ * @brief Extracts a const reference to the held value of type Type from an Any object from a const reference to that Any object.
  *
- * @param any reference to an Any object
+ * @SINCE_1_0.0
+ * @param[in] any The reference to an Any object
  *
  * @return A const reference to the Type value of type Type
  */
-template<typename Type>inline const Type& AnyCastReference( const Any& any )
+template<typename Type>
+inline const Type& AnyCastReference( const Any& any )
 {
   return any.Get<Type>();
 }
 
+/**
+ * @}
+ */
 } // namespace Dali
 
 #endif // __DALI_ANY_TYPE_H__