MyGUI 3.5.3
MyGUI_WidgetUserData.h
Go to the documentation of this file.
1/*
2 * This source file is part of MyGUI. For the latest info, see http://mygui.info/
3 * Distributed under the MIT License
4 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
5 */
6
7#ifndef MYGUI_WIDGET_USER_DATA_H_
8#define MYGUI_WIDGET_USER_DATA_H_
9
10#include "MyGUI_Prerequest.h"
11#include "MyGUI_Any.h"
12#include "MyGUI_Types.h"
13
14namespace MyGUI
15{
16
18 class MYGUI_EXPORT UserData
19 {
20 public:
21 virtual ~UserData() = default;
22
24 void setUserString(std::string_view _key, std::string_view _value);
25
27 std::string_view getUserString(std::string_view _key) const;
28
30 const MapString& getUserStrings() const;
31
33 bool clearUserString(std::string_view _key);
34
36 bool isUserString(std::string_view _key) const;
37
39 void clearUserStrings();
40
42 void setUserData(Any _data);
43
45 template<typename ValueType>
46 ValueType* getUserData(bool _throw = true)
47 {
48 return mUserData.castType<ValueType>(_throw);
49 }
50
51 template<typename ValueType>
52 const ValueType* getUserData(bool _throw = true) const
53 {
54 return mUserData.castType<ValueType>(_throw);
55 }
56
57 /*internal:*/
58 void _setInternalData(Any _data);
59
60 template<typename ValueType>
61 ValueType* _getInternalData(bool _throw = true)
62 {
63 return mInternalData.castType<ValueType>(_throw);
64 }
65
66 template<typename ValueType>
67 const ValueType* _getInternalData(bool _throw = true) const
68 {
69 return mInternalData.castType<ValueType>(_throw);
70 }
71
72 private:
73 // User data
74 MapString mMapUserString;
75 Any mUserData;
76
77 // For internal use
78 Any mInternalData;
79 };
80
81} // namespace MyGUI
82
83#endif // MYGUI_WIDGET_USER_DATA_H_
#define MYGUI_EXPORT
std::map< std::string, std::string, std::less<> > MapString
Definition MyGUI_Types.h:39