Modify doxygen group names
[platform/core/uifw/dali-core.git] / dali / public-api / common / dali-common.h
1 #ifndef __DALI_COMMON_H__
2 #define __DALI_COMMON_H__
3
4 /*
5  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22
23 #ifdef EMSCRIPTEN
24 #include <emscripten/emscripten.h>
25 #endif
26
27 /*
28  * Definitions for shared library support
29  *
30  * If a library is configured with --enable-exportall or --enable-debug
31  * then HIDE_DALI_INTERNALS is not defined, and nothing is hidden.
32  * If it is configured without these options (the default), then HIDE_INTERNALS
33  * is defined when building the library, visibility is automatically hidden, and the explicit
34  * defines below come into use.
35  * When building a library that uses DALI, HIDE_DALI_INTERNALS
36  */
37 #if __GNUC__ >= 4
38 #  ifndef HIDE_DALI_INTERNALS
39 #    define DALI_EXPORT_API
40 #    define DALI_IMPORT_API
41 #    define DALI_INTERNAL
42 #  else
43 #    define DALI_EXPORT_API __attribute__ ((visibility ("default")))
44 #    define DALI_IMPORT_API __attribute__ ((visibility ("default")))
45 #    define DALI_INTERNAL   __attribute__ ((visibility ("hidden")))
46 #  endif
47 #else
48 /** Visibility attribute to show method definitions */
49 #  define DALI_EXPORT_API
50 /** Visibility attribute to show declarations */
51 #  define DALI_IMPORT_API
52 /** Visibility attribute to hide declarations */
53 #  define DALI_INTERNAL
54 #endif
55
56 #if defined (__GXX_EXPERIMENTAL_CXX0X__) || (__cplusplus >= 201103L)
57 // C++0x support
58 #define _CPP11
59 #else
60 // C++0x not supported
61 #endif
62
63 #ifdef EMSCRIPTEN
64
65 #ifndef __clang__
66 # error not clang?
67 #endif
68
69 // clang cpp11 check is per feature
70 #if !__has_feature(cxx_constexpr)
71 # error constexpr needed for compile-time-math. Use -std=c+11
72 #endif
73
74 #define _CPP11
75
76 #endif
77
78 /**
79  * @brief The DALi namespace
80  */
81 namespace Dali
82 {
83 /**
84  * @addtogroup dali_core_common
85  * @{
86  */
87
88 /**
89  * @brief Method to log assertion message in DALI_ASSERT_ALWAYS macro below.
90  *
91  * @param[in] location Where the assertion occurred
92  * @param[in] condition The assertion condition
93  */
94 DALI_IMPORT_API void DaliAssertMessage( const char* location, const char* condition );
95
96 /**
97  * @brief Exception class for Dali Core library - Raised by assertions in codebase.
98  */
99 class DALI_IMPORT_API DaliException
100 {
101 public:
102   /**
103    * @brief Constructor.
104    *
105    * Will always display a backtrace when raised in a debug build.
106    *
107    * @param[in] location  - the location of the assertion
108    * @param[in] condition - The assertion condition
109    */
110   DaliException( const char* location, const char* condition );
111
112   const char* location;
113   const char* condition;
114 };
115
116 /**
117  * @}
118  */
119 }// Dali
120
121 /**
122  * @brief An invariant concurrent assertion to ensure its argument always evaluates TRUE.
123  *
124  * Use this for rules that must always be true regardless of build options.
125  * For example, Actor must only ever have one parent.
126  * To be clear, this test remains compiled into release builds that are deployed
127  * on the platform.
128  * Semantically, a failure of this test is signalling that dali is giving up and
129  * quitting.
130  * Since we don't catch the exception, a failure on any thread other than event
131  * will propagate up the call stack and kill that thread.
132  * A failure on the event thread may give the application an opportunity to
133  * recover if there is an application-written exception handler on the call
134  * stack between the throw site and the thread root and the application is built
135  * with a compatible ABI.
136  * Handle this macro with care at the level you would if it expanded to:
137  *    if(!cond) { exit(EXIT_FAILURE); }
138  * (which it is often equivalent to in effect).
139  * It should not be used for simple parameter validation for instance.
140  */
141
142 /**
143  * Strip assert location for release builds, assert text is descriptive enough
144  * This is to save space for low spec devices
145  */
146 #if defined(DEBUG_ENABLED)
147 #define ASSERT_LOCATION __PRETTY_FUNCTION__
148 #else
149 #define ASSERT_LOCATION NULL
150 #endif
151
152 #ifdef EMSCRIPTEN
153
154 #define DALI_ASSERT_ALWAYS(cond)                \
155   if(!(cond)) \
156   { \
157     Dali::DaliAssertMessage( ASSERT_LOCATION, #cond );   \
158     throw Dali::DaliException( ASSERT_LOCATION, #cond );  \
159     EM_ASM(print(new Error().stack)); \
160   }
161 #else
162
163 #define DALI_ASSERT_ALWAYS(cond)                \
164   if(!(cond)) \
165   { \
166     Dali::DaliAssertMessage( ASSERT_LOCATION, #cond );   \
167     throw Dali::DaliException( ASSERT_LOCATION, #cond );  \
168   }
169 #endif
170
171 /**
172  * @brief An invariant concurrent assertion to ensure its argument evaluates TRUE in debug builds.
173  *
174  * Use this to sanity check algorithms and prevent internal programming errors
175  */
176 #if defined(DEBUG_ENABLED)
177 #define DALI_ASSERT_DEBUG(cond) DALI_ASSERT_ALWAYS(cond)
178 #else
179 #define DALI_ASSERT_DEBUG(cond)
180 #endif
181
182 #endif // __DALI_COMMON_H__