FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
C_propertyList.inl
1/*
2 * Copyright 2024 Guillaume Guillet
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
17namespace fge
18{
19
20void PropertyList::delAllProperties()
21{
22 this->g_data.clear();
23}
24void PropertyList::delProperty(std::string const& key)
25{
26 this->g_data.erase(key);
27}
28
29template<class T>
30bool PropertyList::findProperty(std::string const& key) const
31{
32 auto it = this->g_data.find(key);
33 if (it != this->g_data.cend())
34 {
35 return it->second.isType<T>();
36 }
37 return false;
38}
39bool PropertyList::findProperty(std::string const& key) const
40{
41 return this->g_data.find(key) != this->g_data.cend();
42}
43
44template<class T>
45void PropertyList::setProperty(std::string const& key, T&& value)
46{
47 this->g_data[key] = std::forward<T>(value);
48}
49
50template<class T>
51T* PropertyList::getProperty(std::string const& key)
52{
53 return this->g_data[key].getPtr<T>();
54}
55template<class T>
56T const* PropertyList::getProperty(std::string const& key) const
57{
58 auto it = this->g_data.find(key);
59 if (it != this->g_data.cend())
60 {
61 return it->second.getPtr<T>();
62 }
63 return nullptr;
64}
65template<class T, class TDefault>
66T& PropertyList::getProperty(std::string const& key, TDefault&& defaultValue)
67{
68 auto& data = this->g_data[key];
69 if (!data.isType<T>())
70 {
71 return data.setType<T>() = std::forward<TDefault>(defaultValue);
72 }
73 return data.get<T>();
74}
75
76fge::Property& PropertyList::getProperty(std::string const& key)
77{
78 return this->g_data[key];
79}
80fge::Property const* PropertyList::getProperty(std::string const& key) const
81{
82 auto it = this->g_data.find(key);
83 if (it != this->g_data.cend())
84 {
85 return &it->second;
86 }
87 return nullptr;
88}
89
90fge::Property& PropertyList::operator[](std::string const& key)
91{
92 return this->g_data[key];
93}
94fge::Property const* PropertyList::operator[](std::string const& key) const
95{
96 auto it = this->g_data.find(key);
97 if (it != this->g_data.cend())
98 {
99 return &it->second;
100 }
101 return nullptr;
102}
103
104std::size_t PropertyList::count() const
105{
106 return this->g_data.size();
107}
108
109fge::PropertyList::DataType::iterator PropertyList::begin()
110{
111 return this->g_data.begin();
112}
113fge::PropertyList::DataType::iterator PropertyList::end()
114{
115 return this->g_data.end();
116}
117fge::PropertyList::DataType::const_iterator PropertyList::begin() const
118{
119 return this->g_data.begin();
120}
121fge::PropertyList::DataType::const_iterator PropertyList::end() const
122{
123 return this->g_data.end();
124}
125
126void PropertyList::clearAllModificationFlags()
127{
128 for (auto& data: this->g_data)
129 {
130 data.second.setModifiedFlag(false);
131 }
132}
133std::size_t PropertyList::countAllModificationFlags() const
134{
135 std::size_t counter{0};
136
137 for (auto const& data: this->g_data)
138 {
139 if (data.second.isModified())
140 {
141 ++counter;
142 }
143 }
144
145 return counter;
146}
147
148} // namespace fge
A class that can store any type of data.
Definition C_property.hpp:54