Merge "Updated patch coverage script." into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-scene-loader / internal / json-util.h
1 #ifndef DALI_SCENE_LOADER_JSON_UTIL_H_
2 #define DALI_SCENE_LOADER_JSON_UTIL_H_
3 /*
4  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 // INTERNAL INCLUDES
21 #include "dali-scene-loader/public-api/index.h"
22
23 // EXTERNAL INCLUDES
24 #include "dali/public-api/common/vector-wrapper.h"
25 #include "dali/public-api/animation/time-period.h"
26 #include "dali/public-api/object/property.h"
27 #include "dali/public-api/math/vector4.h"
28 #include "dali-toolkit/devel-api/builder/tree-node.h"
29
30 namespace Dali
31 {
32 namespace SceneLoader
33 {
34
35 bool ReadBool(const Toolkit::TreeNode* node, bool& num);
36
37 bool ReadInt(const Toolkit::TreeNode* node, int& num);
38
39 bool ReadFloat(const Toolkit::TreeNode* node, float& num);
40
41 bool ReadIndex(const Toolkit::TreeNode* node, Index& num);
42
43 bool ReadBlob(const Toolkit::TreeNode* node, unsigned int& offset, unsigned int& length);
44
45 /**
46  * @brief Gets the number of numerical element of a JSON array;
47  * @return 0 if not an array, otherwise the number of float or integer elements
48  *  at the front of the array.
49  */
50 size_t GetNumericalArraySize(const Toolkit::TreeNode* node);
51
52 bool ReadVector(const Toolkit::TreeNode* node, float* num, unsigned int size);
53
54 bool ReadVector(const Toolkit::TreeNode* node, int* num, unsigned int size);
55
56 /**
57  * @brief Reads a color.
58  * 
59  * The node contents could be a vector of 4 floats [r,g,b,a].
60  * 
61  * @param[in] node The tree node with the color.
62  * @param[out] color The RGBA color.
63  * 
64  * @return true if succedded to read the color.
65  */
66 bool ReadColor(const Toolkit::TreeNode* node, Vector4& color);
67
68 bool ReadTimePeriod(const Toolkit::TreeNode* node, TimePeriod& timePeriod);
69
70 bool ReadString(const Toolkit::TreeNode* node, std::string& strValue);
71
72 bool ReadStringVector(const Toolkit::TreeNode* node, std::vector<std::string>& strvector);
73
74 /**
75  * @brief Attempts to read a property of the given type from the given JSON node.
76  * @return The property value that it could interpret. If unsuccessful, its type will be NONE.
77  * @note Currently only numerical types are supported (including boolean).
78  */
79 Property::Value ReadPropertyValue(const Property::Type& propType, const Toolkit::TreeNode& tn);
80
81 /**
82  * @brief Attempts to read a property, whose type it will attempt to determine from the given
83  *  JSON node.
84  * @return The property value that it could interpret. If unsuccessful, its type will be NONE.
85  * @note Currently only numerical types are supported (including boolean).
86  * @note Supports a disambiguation syntax, whereby the type can be specified explicitly:
87  *  { "type": "rotation", "value": [...] } .
88  * @note: rotation / rectangle / extents type properties must be disambiguated in all circumstances.
89  */
90 Property::Value ReadPropertyValue(const Toolkit::TreeNode& tn);
91
92 }
93 }
94
95 #endif //DALI_SCENE_LOADER_JSON_UTIL_H_