Emscripten workarounds and llvm syntax fixes
[platform/core/uifw/dali-core.git] / capi / dali / public-api / common / dali-common.h
1 #ifndef __DALI_COMMON_H__
2 #define __DALI_COMMON_H__
3
4 //
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 //
7 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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  * @addtogroup CAPI_DALI_FRAMEWORK
22  * @{
23  */
24
25 // EXTERNAL INCLUDES
26 #include <string>
27 #include <cstdio>
28
29
30 /**
31  * Definitions for shared library support
32  *
33  * If a library is configured with --enable-exportall or --enable-debug
34  * then HIDE_DALI_INTERNALS is not defined, and nothing is hidden.
35  * If it is configured without these options (the default), then HIDE_INTERNALS
36  * is defined when building the library, visibility is automatically hidden, and the explicit
37  * defines below come into use.
38  * When building a library that uses DALI, HIDE_DALI_INTERNALS
39  */
40 #if __GNUC__ >= 4
41 #  ifndef HIDE_DALI_INTERNALS
42 #    define DALI_EXPORT_API
43 #    define DALI_IMPORT_API
44 #    define DALI_INTERNAL
45 #  else
46 #    define DALI_EXPORT_API __attribute__ ((visibility ("default")))
47 #    define DALI_IMPORT_API __attribute__ ((visibility ("default")))
48 #    define DALI_INTERNAL   __attribute__ ((visibility ("hidden")))
49 #  endif
50 #else
51 #  define DALI_EXPORT_API
52 #  define DALI_IMPORT_API
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=c11
72 #endif
73
74 #define _CPP11
75
76 #endif
77
78 namespace Dali
79 {
80
81 /**
82  * Method to log assertion message in DALI_ASSERT_ALWAYS macro below
83  * @param[in] condition The assertion condition
84  * @param[in] file The file in which the assertion occurred
85  * @param[in] line The line number at which the assertion occured
86  */
87 DALI_IMPORT_API void DaliAssertMessage(const char* condition, const char* file, int line);
88
89 /**
90  * Exception class for Dali Core library - Raised by assertions in codebase.
91  */
92 class DALI_IMPORT_API DaliException
93 {
94 public:
95   /**
96    * Constructor. Will always display a backtrace when raised in a debug build.
97    *
98    * @param[in] location  - the location of the assertion
99    * @param[in] condition - The assertion condition
100    */
101   DALI_IMPORT_API DaliException(const char *location, const char* condition);
102
103   std::string mLocation;
104   std::string mCondition;
105 };
106
107 }// Dali
108
109 /**
110  * An invariant concurrent assertion to ensure its argument always evaluates TRUE
111  * Use this for rules that must always be true regardless of build options.
112  * For example, Actor must only ever have one parent.
113  * To be clear, this test remains compiled into release builds that are deployed
114  * on the platform.
115  * Semantically, a failure of this test is signalling that dali is giving up and
116  * quitting.
117  * Since we don't catch the exception, a failure on any thread other than event
118  * will propagate up the call stack and kill that thread.
119  * A failure on the event thread may give the application an opportunity to
120  * recover if there is an application-written exception handler on the call
121  * stack between the throw site and the thread root and the application is built
122  * with a compatible ABI.
123  * Handle this macro with care at the level you would if it expanded to:
124  *    if(!cond) { exit(EXIT_FAILURE); }
125  * (which it is often equivalent to in effect).
126  * It should not be used for simple parameter validation for instance.
127  */
128 #define DALI_ASSERT_ALWAYS(cond) \
129   if(!(cond)) \
130   { \
131     Dali::DaliAssertMessage(#cond, __FILE__, __LINE__);   \
132     throw Dali::DaliException(__PRETTY_FUNCTION__, #cond);  \
133   }\
134
135 /**
136  * An invariant concurrent assertion to ensure its argument evaluates TRUE in debug builds
137  * Use this to sanity check algorithms and prevent internal programming errors
138  */
139 #if defined(DEBUG_ENABLED)
140 #define DALI_ASSERT_DEBUG(cond) DALI_ASSERT_ALWAYS(cond)
141 #else
142 #define DALI_ASSERT_DEBUG(cond)
143 #endif
144
145 /**
146  * @}
147  */
148 #endif // __DALI_COMMON_H__