[dali_2.1.31] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-scene-loader / public-api / customization.cpp
1 /*
2  * Copyright (c) 2021 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-scene-loader/public-api/customization.h"
18 #include "dali/devel-api/common/map-wrapper.h"
19
20 namespace Dali
21 {
22 namespace SceneLoader
23 {
24 struct Customization::Map::Impl
25 {
26   std::map<Tag, Customization> mCustomizations;
27 };
28
29 Customization::Map::Map()
30 : mImpl{new Impl}
31 {
32 }
33
34 Customization::Map::~Map() = default;
35
36 Customization* Customization::Map::Set(Tag tag, Customization&& customization)
37 {
38   auto& result = (mImpl->mCustomizations[tag] = customization);
39   return &result;
40 }
41
42 const Customization* Customization::Map::Get(Tag tag) const
43 {
44   auto& customizations = mImpl->mCustomizations;
45   auto  iFind          = customizations.find(tag);
46   if(iFind != customizations.end())
47   {
48     return &iFind->second;
49   }
50   return nullptr;
51 }
52
53 Customization* Customization::Map::Get(Tag tag)
54 {
55   auto& customizations = mImpl->mCustomizations;
56   auto  iFind          = customizations.find(tag);
57   if(iFind != customizations.end())
58   {
59     return &iFind->second;
60   }
61   return nullptr;
62 }
63
64 uint32_t Customization::Map::Size() const
65 {
66   return mImpl->mCustomizations.size();
67 }
68
69 void Customization::Map::Clear()
70 {
71   mImpl->mCustomizations.clear();
72 }
73
74 struct Customization::Choices::Impl
75 {
76   std::map<Tag, OptionType> mOptions;
77 };
78
79 Customization::Choices::Choices()
80 : mImpl{new Impl}
81 {
82 }
83
84 Customization::Choices::~Choices() = default;
85
86 void Customization::Choices::Set(Tag tag, OptionType option)
87 {
88   mImpl->mOptions[tag] = option;
89 }
90
91 Customization::OptionType Customization::Choices::Get(Tag tag) const
92 {
93   auto& options = mImpl->mOptions;
94   auto  iFind   = options.find(tag);
95   if(iFind != options.end())
96   {
97     return iFind->second;
98   }
99   return NONE;
100 }
101
102 uint32_t Customization::Choices::Size() const
103 {
104   return mImpl->mOptions.size();
105 }
106
107 void Customization::Choices::Clear()
108 {
109   mImpl->mOptions.clear();
110 }
111
112 } // namespace SceneLoader
113 } // namespace Dali