MyGUI  3.0.1
MyGUI_WidgetUserData.h
Go to the documentation of this file.
1 
7 /*
8  This file is part of MyGUI.
9 
10  MyGUI is free software: you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  MyGUI is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
22 */
23 #ifndef __MYGUI_WIDGET_USER_DATA_H__
24 #define __MYGUI_WIDGET_USER_DATA_H__
25 
26 #include "MyGUI_Prerequest.h"
27 #include "MyGUI_WidgetDefines.h"
28 #include "MyGUI_Any.h"
29 
30 namespace MyGUI
31 {
34  {
35  public:
36  UserData() { }
37  virtual ~UserData() { }
38 
40  void setUserString(const std::string& _key, const std::string& _value)
41  {
42  mMapUserString[_key] = _value;
43  }
44 
46  const std::string& getUserString(const std::string& _key)
47  {
48  MapString::iterator iter = mMapUserString.find(_key);
49  if (iter == mMapUserString.end())
50  {
51  static std::string empty;
52  return empty;
53  }
54  return iter->second;
55  }
56 
58  bool clearUserString(const std::string& _key)
59  {
60  MapString::iterator iter = mMapUserString.find(_key);
61  if (iter != mMapUserString.end())
62  {
63  mMapUserString.erase(iter);
64  return true;
65  }
66  return false;
67  }
68 
70  bool isUserString(const std::string& _key)
71  {
72  return mMapUserString.find(_key) != mMapUserString.end();
73  }
74 
76  void clearUserStrings()
77  {
78  mMapUserString.clear();
79  }
80 
82  void setUserData(Any _data) { mUserData = _data; }
83 
85  template <typename ValueType>
86  ValueType * getUserData(bool _throw = true)
87  {
88  return mUserData.castType<ValueType>(_throw);
89  }
90 
91  /*internal:*/
92  void _setInternalData(Any _data) { mInternalData = _data; }
93 
94  template <typename ValueType>
95  ValueType * _getInternalData(bool _throw = true)
96  {
97  return mInternalData.castType<ValueType>(_throw);
98  }
99 
100  /*obsolete:*/
101 #ifndef MYGUI_DONT_USE_OBSOLETE
102 
103  MYGUI_OBSOLETE("use : template <typename ValueType> ValueType * UserData::getUserData(bool _throw)")
104  void * getUserData()
105  {
106  return mUserData.castUnsafe();
107  }
108 
109 #endif // MYGUI_DONT_USE_OBSOLETE
110 
111  private:
112  // пользовательские данные
113  MapString mMapUserString;
114  Any mUserData;
115 
116  // для внутренниего использования
117  Any mInternalData;
118 
119  };
120 
121 } // namespace MyGUI
122 
123 #endif // __MYGUI_WIDGET_USER_DATA_H__