Moved Text Controller & Markup Processor to sub-folders
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / markup-processor / markup-processor-attribute-helper-functions.h
1 #ifndef DALI_TOOLKIT_TEXT_MARKUP_PROCESSOR_ATTRIBUTE_HELPER_FUNCTIONS_H
2 #define DALI_TOOLKIT_TEXT_MARKUP_PROCESSOR_ATTRIBUTE_HELPER_FUNCTIONS_H
3
4 /*
5  * Copyright (c) 2022 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-toolkit/internal/text/text-definitions.h>
23
24 // EXTERNAL INCLUDES
25 #include <functional>
26
27 namespace Dali
28 {
29 namespace Toolkit
30 {
31 namespace Text
32 {
33 struct Attribute;
34
35 /**
36  * @brief Copy the value from attribute buffer to value.
37  *
38  * @param[in] attribute the value of attribute.
39  * @param[in] maxLengthAttributeValue the maximum length of any of the possible value for attribute
40  * @param[out] value the value container.
41  *
42  */
43 void CopyAttributeValueFromBuffer(const Attribute& attribute, const Length maxLengthAttributeValue, char* value);
44
45 /**
46  * @brief Process the float attribute value from buffer.
47  *
48  * @param[in] attribute the float attribute.
49  *
50  * @return The float value.
51  */
52 float ProcessFloatAttribute(const Attribute& attribute);
53
54 /**
55  * @brief Process the Enumeration attribute value from buffer.
56  *
57  * @param[in] attribute the Enumeration attribute.
58  * @param[in] maxLengthAttributeValue the maximum length of any of the possible value for attribute
59  * @param[in] funcStringToEnum the function converts string value to enum value
60  * @param[out] enumValue the enum value
61  *
62  * @return      True if the enum value was processed successfully
63  *
64  */
65 template<typename T>
66 bool ProcessEnumerationAttribute(const Attribute&                    attribute,
67                                  const Length                        maxLengthAttributeValue,
68                                  std::function<T(const char* const)> funcStringToEnum,
69                                  T&                                  enumValue)
70 {
71   char* value = new char[maxLengthAttributeValue + 1u];
72
73   CopyAttributeValueFromBuffer(attribute, maxLengthAttributeValue, value);
74
75   enumValue = funcStringToEnum(value); // @TODO: the functions that process Enum value should be refactored to return bool from Scripting::GetEnumeration
76
77   delete[] value;
78
79   return true;
80 }
81
82 } // namespace Text
83
84 } // namespace Toolkit
85
86 } // namespace Dali
87
88 #endif // DALI_TOOLKIT_TEXT_MARKUP_PROCESSOR_ATTRIBUTE_HELPER_FUNCTIONS_H