[dali_2.3.28] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / devel-api / scripting / enum-helper.h
1 #ifndef DALI_ENUM_HELPER_H
2 #define DALI_ENUM_HELPER_H
3
4 /*
5  * Copyright (c) 2020 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 // INTERNAL INCLUDES
22 #include <dali/devel-api/scripting/scripting.h>
23
24 namespace Dali
25 {
26 /**
27  * Macros for creating value, typically enumerations, to string tables.
28  * Example:
29  *
30  * DALI_ENUM_TO_STRING_TABLE_BEGIN( SIZE_MODE )
31  * DALI_ENUM_TO_STRING( USE_OWN_SIZE )
32  * DALI_ENUM_TO_STRING( SIZE_EQUAL_TO_PARENT )
33  * DALI_ENUM_TO_STRING_TABLE_END( SIZE_MODE )
34  *
35  * Creates:
36  * const Scripting::StringEnum< SizeMode > SIZE_MODE_TABLE[] = {
37  * { "USE_OWN_SIZE", USE_OWN_SIZE },
38  * { "SIZE_EQUAL_TO_PARENT", SIZE_EQUAL_TO_PARENT },
39  * }; const unsigned int SIZE_MODE_TABLE_COUNT = sizeof( SIZE_MODE_TABLE ) / sizeof( SIZE_MODE_TABLE[0] );
40  *
41  * By default, Dali::Scripting::StringEnum is used as the type for the table, however, a different type can be specified by using
42  * DALI_ENUM_TO_STRING_TABLE_BEGIN_WITH_TYPE.
43  */
44 #define DALI_ENUM_TO_STRING_TABLE_BEGIN_WITH_TYPE(type, t) const type t##_TABLE[] = {
45 #define DALI_ENUM_TO_STRING_TABLE_BEGIN(t) DALI_ENUM_TO_STRING_TABLE_BEGIN_WITH_TYPE(Dali::Scripting::StringEnum, t)
46 #define DALI_ENUM_TO_STRING_TABLE_END(t) \
47   }                                      \
48   ;                                      \
49   const uint32_t t##_TABLE_COUNT = static_cast<uint32_t>(sizeof(t##_TABLE) / sizeof(t##_TABLE[0]));
50 #define DALI_ENUM_TO_STRING(s) {#s, s},
51
52 /**
53  * Adds a value, typically an enum, to the table within a scope but without the scope name
54  * Example converts ( Layer, LAYER_UI ) to ( "LAYER_UI", Layer::LayerUI )
55  */
56 #define DALI_ENUM_TO_STRING_WITH_SCOPE(className, enumName) {#enumName, className::enumName},
57
58 } // namespace Dali
59
60 #endif // DALI_ENUM_HELPER_H