[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / internal / loader / json-util.h
1 #ifndef DALI_SCENE3D_LOADER_JSON_UTIL_H_
2 #define DALI_SCENE3D_LOADER_JSON_UTIL_H_
3 /*
4  * Copyright (c) 2023 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 // EXTERNAL INCLUDES
21 #include <dali-toolkit/devel-api/builder/tree-node.h>
22 #include <dali/public-api/animation/time-period.h>
23 #include <dali/public-api/common/vector-wrapper.h>
24 #include <dali/public-api/math/vector4.h>
25 #include <dali/public-api/object/property.h>
26
27 // INTERNAL INCLUDES
28 #include <dali-scene3d/public-api/loader/index.h>
29
30 namespace Dali::Scene3D::Loader
31 {
32 bool ReadBool(const Toolkit::TreeNode* node, bool& num);
33
34 bool ReadInt(const Toolkit::TreeNode* node, int& num);
35
36 bool ReadFloat(const Toolkit::TreeNode* node, float& num);
37
38 bool ReadIndex(const Toolkit::TreeNode* node, Index& num);
39
40 bool ReadBlob(const Toolkit::TreeNode* node, unsigned int& offset, unsigned int& length);
41
42 /**
43  * @brief Gets the number of numerical element of a JSON array;
44  * @return 0 if not an array, otherwise the number of float or integer elements
45  *  at the front of the array.
46  */
47 size_t GetNumericalArraySize(const Toolkit::TreeNode* node);
48
49 bool ReadVector(const Toolkit::TreeNode* node, float* num, unsigned int size);
50
51 bool ReadVector(const Toolkit::TreeNode* node, int* num, unsigned int size);
52
53 /**
54  * @brief Reads a color.
55  * 
56  * The node contents could be a vector of 4 floats [r,g,b,a].
57  * 
58  * @param[in] node The tree node with the color.
59  * @param[out] color The RGBA color.
60  * 
61  * @return true if succedded to read the color.
62  */
63 bool ReadColor(const Toolkit::TreeNode* node, Vector4& color);
64
65 bool ReadTimePeriod(const Toolkit::TreeNode* node, TimePeriod& timePeriod);
66
67 bool ReadString(const Toolkit::TreeNode* node, std::string& strValue);
68
69 bool ReadStringVector(const Toolkit::TreeNode* node, std::vector<std::string>& strvector);
70
71 /**
72  * @brief Attempts to read a property of the given type from the given JSON node.
73  * @return The property value that it could interpret. If unsuccessful, its type will be NONE.
74  * @note Currently only numerical types are supported (including boolean).
75  */
76 Property::Value ReadPropertyValue(const Property::Type& propType, const Toolkit::TreeNode& tn);
77
78 /**
79  * @brief Attempts to read a property, whose type it will attempt to determine from the given
80  *  JSON node.
81  * @return The property value that it could interpret. If unsuccessful, its type will be NONE.
82  * @note Currently only numerical types are supported (including boolean).
83  * @note Supports a disambiguation syntax, whereby the type can be specified explicitly:
84  *  { "type": "rotation", "value": [...] } .
85  * @note: rotation / rectangle / extents type properties must be disambiguated in all circumstances.
86  */
87 Property::Value ReadPropertyValue(const Toolkit::TreeNode& tn);
88
89 } // namespace Dali::Scene3D::Loader
90
91 #endif //DALI_SCENE3D_LOADER_JSON_UTIL_H_