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 
13 namespace MyGUI
14 {
15 
16 	/** UserData is parent of Widget class. Used to store any user data and strings inside widget */
17 	class MYGUI_EXPORT UserData
18 	{
19 	public:
20 		virtual ~UserData() = default;
21 
22 		/** Set user string */
23 		void setUserString(const std::string& _key, const std::string& _value);
24 
25 		/** Get user string or "" if not found */
26 		const std::string& getUserString(const std::string& _key) const;
27 
28 		/** Get map of all user strings */
29 		const MapString& getUserStrings() const;
30 
31 		/** Delete user string */
32 		bool clearUserString(const std::string& _key);
33 
34 		/** Return true if user string with such key exist */
35 		bool isUserString(const std::string& _key) const;
36 
37 		/** Delete all user strings */
38 		void clearUserStrings();
39 
40 		/** Set any user data to store inside widget */
41 		void setUserData(Any _data);
42 
43 		/** Get user data and cast it to ValueType */
44 		template <typename ValueType>
45 		ValueType* getUserData(bool _throw = true) const
46 		{
47 			return mUserData.castType<ValueType>(_throw);
48 		}
49 
50 		/*internal:*/
51 		void _setInternalData(Any _data);
52 
53 		template <typename ValueType>
54 		ValueType* _getInternalData(bool _throw = true) const
55 		{
56 			return mInternalData.castType<ValueType>(_throw);
57 		}
58 
59 	private:
60 		// пользовательские данные
61 		MapString mMapUserString;
62 		Any mUserData;
63 
64 		// для внутренниего использования
65 		Any mInternalData;
66 	};
67 
68 } // namespace MyGUI
69 
70 #endif // MYGUI_WIDGET_USER_DATA_H_
71