[dali_2.1.31] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / public-api / loader / customization.cpp
1 /*
2  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 #include "dali-scene3d/public-api/loader/customization.h"
18 #include "dali/devel-api/common/map-wrapper.h"
19
20 namespace Dali
21 {
22 namespace Scene3D
23 {
24 namespace Loader
25 {
26 struct Customization::Map::Impl
27 {
28   std::map<Tag, Customization> mCustomizations;
29 };
30
31 Customization::Map::Map()
32 : mImpl{new Impl}
33 {
34 }
35
36 Customization::Map::~Map() = default;
37
38 Customization* Customization::Map::Set(Tag tag, Customization&& customization)
39 {
40   auto& result = (mImpl->mCustomizations[tag] = customization);
41   return &result;
42 }
43
44 const Customization* Customization::Map::Get(Tag tag) const
45 {
46   auto& customizations = mImpl->mCustomizations;
47   auto  iFind          = customizations.find(tag);
48   if(iFind != customizations.end())
49   {
50     return &iFind->second;
51   }
52   return nullptr;
53 }
54
55 Customization* Customization::Map::Get(Tag tag)
56 {
57   auto& customizations = mImpl->mCustomizations;
58   auto  iFind          = customizations.find(tag);
59   if(iFind != customizations.end())
60   {
61     return &iFind->second;
62   }
63   return nullptr;
64 }
65
66 uint32_t Customization::Map::Size() const
67 {
68   return mImpl->mCustomizations.size();
69 }
70
71 void Customization::Map::Clear()
72 {
73   mImpl->mCustomizations.clear();
74 }
75
76 struct Customization::Choices::Impl
77 {
78   std::map<Tag, OptionType> mOptions;
79 };
80
81 Customization::Choices::Choices()
82 : mImpl{new Impl}
83 {
84 }
85
86 Customization::Choices::~Choices() = default;
87
88 void Customization::Choices::Set(Tag tag, OptionType option)
89 {
90   mImpl->mOptions[tag] = option;
91 }
92
93 Customization::OptionType Customization::Choices::Get(Tag tag) const
94 {
95   auto& options = mImpl->mOptions;
96   auto  iFind   = options.find(tag);
97   if(iFind != options.end())
98   {
99     return iFind->second;
100   }
101   return NONE;
102 }
103
104 uint32_t Customization::Choices::Size() const
105 {
106   return mImpl->mOptions.size();
107 }
108
109 void Customization::Choices::Clear()
110 {
111   mImpl->mOptions.clear();
112 }
113
114 } // namespace Loader
115 } // namespace Scene3D
116 } // namespace Dali