Kiwano Engine v1.3.x
UserData.h
1// Copyright (c) 2018-2019 Kiwano - Nomango
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to deal
5// in the Software without restriction, including without limitation the rights
6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19// THE SOFTWARE.
20
21#pragma once
22#include <kiwano/core/Common.h>
23
24namespace kiwano
25{
30class KGE_API UserData final : public Singleton<UserData>
31{
33
34public:
37 using DataMap = UnorderedMap<String, Any>;
38
41 using DataPair = Pair<const String, Any>;
42
48 Any Get(StringView key, const Any& default_data = Any()) const;
49
54 void Set(StringView key, const Any& data);
55
59 void Set(const DataPair& pair);
60
64 void Set(const std::initializer_list<DataPair>& list);
65
69 void Set(const DataMap& map);
70
74 bool Contains(StringView key) const;
75
78 const DataMap& GetDataMap() const;
79
82 void Clear();
83
84private:
85 UserData() = default;
86 UserData(const UserData&) = default;
87 UserData& operator=(const UserData&) = default;
88
89private:
90 DataMap data_;
91};
92} // namespace kiwano
可储存单个任意对象的容器
Definition: Any.h:32
Definition: Singleton.h:28
用户数据
Definition: UserData.h:31
Pair< const String, Any > DataPair
键值对
Definition: UserData.h:41
UnorderedMap< String, Any > DataMap
数据字典
Definition: UserData.h:37