1 #ifndef __DALI_COMMON_H__
2 #define __DALI_COMMON_H__
5 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
24 #include <emscripten/emscripten.h>
28 * Definitions for shared library support
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
38 # ifndef HIDE_DALI_INTERNALS
39 # define DALI_EXPORT_API
40 # define DALI_IMPORT_API
41 # define DALI_INTERNAL
43 # define DALI_EXPORT_API __attribute__ ((visibility ("default")))
44 # define DALI_IMPORT_API __attribute__ ((visibility ("default")))
45 # define DALI_INTERNAL __attribute__ ((visibility ("hidden")))
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
56 #if defined (__GXX_EXPERIMENTAL_CXX0X__) || (__cplusplus >= 201103L)
60 // C++0x not supported
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
79 * Two macros to provide branch predictor information.
80 * DALI_LIKELY should be used when a branch is taken in almost all cases so the
81 * branch predictor can avoid pre-fetching the code for else branch
82 * DALI_UNLIKELY should be used when a branch is almost never taken
84 #define DALI_LIKELY(expression) __builtin_expect( !!(expression), 1 )
85 #define DALI_UNLIKELY(expression) __builtin_expect( !!(expression), 0 )
88 * @brief The DALi namespace
93 * @addtogroup dali_core_common
98 * @brief Method to log assertion message in DALI_ASSERT_ALWAYS macro below.
100 * @param[in] location Where the assertion occurred
101 * @param[in] condition The assertion condition
103 DALI_IMPORT_API void DaliAssertMessage( const char* location, const char* condition );
106 * @brief Exception class for Dali Core library - Raised by assertions in codebase.
108 class DALI_IMPORT_API DaliException
112 * @brief Constructor.
114 * Will always display a backtrace when raised in a debug build.
116 * @param[in] location - the location of the assertion
117 * @param[in] condition - The assertion condition
119 DaliException( const char* location, const char* condition );
121 const char* location;
122 const char* condition;
131 * @brief An invariant concurrent assertion to ensure its argument always evaluates TRUE.
133 * Use this for rules that must always be true regardless of build options.
134 * For example, Actor must only ever have one parent.
135 * To be clear, this test remains compiled into release builds that are deployed
137 * Semantically, a failure of this test is signalling that dali is giving up and
139 * Since we don't catch the exception, a failure on any thread other than event
140 * will propagate up the call stack and kill that thread.
141 * A failure on the event thread may give the application an opportunity to
142 * recover if there is an application-written exception handler on the call
143 * stack between the throw site and the thread root and the application is built
144 * with a compatible ABI.
145 * Handle this macro with care at the level you would if it expanded to:
146 * if(!cond) { exit(EXIT_FAILURE); }
147 * (which it is often equivalent to in effect).
148 * It should not be used for simple parameter validation for instance.
152 * Strip assert location for release builds, assert text is descriptive enough
153 * This is to save space for low spec devices
155 #if defined(DEBUG_ENABLED)
156 #define ASSERT_LOCATION __PRETTY_FUNCTION__
158 #define ASSERT_LOCATION NULL
163 #define DALI_ASSERT_ALWAYS(cond) \
164 if(DALI_UNLIKELY(!(cond))) \
166 Dali::DaliAssertMessage( ASSERT_LOCATION, #cond ); \
167 throw Dali::DaliException( ASSERT_LOCATION, #cond ); \
168 EM_ASM(print(new Error().stack)); \
172 #define DALI_ASSERT_ALWAYS(cond) \
173 if(DALI_UNLIKELY(!(cond))) \
175 Dali::DaliAssertMessage( ASSERT_LOCATION, #cond ); \
176 throw Dali::DaliException( ASSERT_LOCATION, #cond ); \
181 * @brief An invariant concurrent assertion to ensure its argument evaluates TRUE in debug builds.
183 * Use this to sanity check algorithms and prevent internal programming errors
185 #if defined(DEBUG_ENABLED)
186 #define DALI_ASSERT_DEBUG(cond) DALI_ASSERT_ALWAYS(cond)
188 #define DALI_ASSERT_DEBUG(cond)
191 #endif // __DALI_COMMON_H__