Remove Emscripten
[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) 2017 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 /*
24  * Definitions for shared library support.
25  *
26  * If a library is configured with --enable-exportall or --enable-debug
27  * then HIDE_DALI_INTERNALS is not defined, and nothing is hidden.
28  * If it is configured without these options (the default), then HIDE_INTERNALS
29  * is defined when building the library, visibility is automatically hidden, and the explicit
30  * defines below come into use.
31  * When building a library that uses DALI, HIDE_DALI_INTERNALS.
32  */
33 #if __GNUC__ >= 4
34 #  ifndef HIDE_DALI_INTERNALS
35 #    define DALI_EXPORT_API
36 #    define DALI_IMPORT_API
37 #    define DALI_INTERNAL
38 #  else
39 #    define DALI_EXPORT_API __attribute__ ((visibility ("default")))
40 #    define DALI_IMPORT_API __attribute__ ((visibility ("default")))
41 #    define DALI_INTERNAL   __attribute__ ((visibility ("hidden")))
42 #  endif
43 #else
44 /** Visibility attribute to show method definitions */
45 #  define DALI_EXPORT_API
46 /** Visibility attribute to show declarations */
47 #  define DALI_IMPORT_API
48 /** Visibility attribute to hide declarations */
49 #  define DALI_INTERNAL
50 #endif
51
52 #ifdef DEPRECATION_WARNING
53 #define DALI_DEPRECATED_API __attribute__((__visibility__("default"), deprecated))
54 #else
55 #define DALI_DEPRECATED_API
56 #endif
57
58 #if defined (__GXX_EXPERIMENTAL_CXX0X__) || (__cplusplus >= 201103L)
59 // C++0x support
60 #define _CPP11
61 #else
62 // C++0x not supported
63 #endif
64
65 /**
66  * @brief Two macros to provide branch predictor information.
67  * DALI_LIKELY should be used when a branch is taken in almost all cases so the
68  * branch predictor can avoid pre-fetching. The code for else branch
69  * DALI_UNLIKELY should be used when a branch is almost never taken.
70  * @SINCE_1_0.0
71  */
72 #define DALI_LIKELY(expression)   __builtin_expect( !!(expression), 1 )
73 #define DALI_UNLIKELY(expression) __builtin_expect( !!(expression), 0 )
74
75 /**
76  * @brief The DALi namespace.
77  * @SINCE_1_0.0
78  */
79 namespace Dali
80 {
81 /**
82  * @addtogroup dali_core_common
83  * @{
84  */
85
86 /**
87  * @brief Method to log assertion message in DALI_ASSERT_ALWAYS macro below.
88  *
89  * @SINCE_1_0.0
90  * @param[in] location Where the assertion occurred
91  * @param[in] condition The assertion condition
92  */
93 DALI_IMPORT_API void DaliAssertMessage( const char* location, const char* condition );
94
95 /**
96  * @brief Exception class for Dali Core library - Raised by assertions in codebase.
97  * @SINCE_1_0.0
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    * @SINCE_1_0.0
108    * @param[in] location The location of the assertion
109    * @param[in] condition The assertion condition
110    */
111   DaliException( const char* location, const char* condition );
112
113   const char* location;
114   const char* condition;
115 };
116
117 /**
118  * @}
119  */
120 }// Dali
121
122 /**
123  * @brief An invariant concurrent assertion to ensure its argument always evaluates TRUE.
124  *
125  * Use this for rules that must always be true regardless of build options.
126  * For example, Actor must only ever have one parent.
127  * To be clear, this test remains compiled into release builds that are deployed
128  * on the platform.
129  * Semantically, a failure of this test is signalling that dali is giving up and
130  * quitting.
131  * Since we don't catch the exception, a failure on any thread other than event
132  * will propagate up the call stack and kill that thread.
133  * A failure on the event thread may give the application an opportunity to
134  * recover if there is an application-written exception handler on the call
135  * stack between the throw site and the thread root and the application is built
136  * with a compatible ABI.
137  * Handle this macro with care at the level you would if it expanded to:
138  *    if(!cond) { exit(EXIT_FAILURE); }
139  * (which it is often equivalent to in effect).
140  * It should not be used for simple parameter validation for instance.
141  */
142
143 /**
144  * @brief Strip assert location for release builds, assert text is descriptive enough.
145  * This is to save space for low spec devices.
146  * @SINCE_1_0.0
147  */
148 #if defined(DEBUG_ENABLED)
149 #define ASSERT_LOCATION __PRETTY_FUNCTION__
150 #else
151 #define ASSERT_LOCATION NULL
152 #endif
153
154 #define DALI_ASSERT_ALWAYS(cond)                \
155   if(DALI_UNLIKELY(!(cond))) \
156   { \
157     Dali::DaliAssertMessage( ASSERT_LOCATION, #cond );   \
158     throw Dali::DaliException( ASSERT_LOCATION, #cond );  \
159   }
160
161 #define DALI_ABORT(message)                \
162   { \
163     Dali::DaliAssertMessage( ASSERT_LOCATION, message );   \
164     throw Dali::DaliException( ASSERT_LOCATION, message );  \
165   }
166
167 /**
168  * @brief An invariant concurrent assertion to ensure its argument evaluates TRUE in debug builds.
169  *
170  * Use this to sanity check algorithms and prevent internal programming errors.
171  * @SINCE_1_0.0
172  */
173 #if defined(DEBUG_ENABLED)
174 #define DALI_ASSERT_DEBUG(cond) DALI_ASSERT_ALWAYS(cond)
175 #else
176 #define DALI_ASSERT_DEBUG(cond)
177 #endif
178
179 #endif // __DALI_COMMON_H__