1 | /* |
---|
2 | ----------------------------------------------------------------------------- |
---|
3 | This source file is part of OGRE |
---|
4 | (Object-oriented Graphics Rendering Engine) |
---|
5 | For the latest info, see http://www.ogre3d.org/ |
---|
6 | |
---|
7 | Copyright (c) 2000-2013 Torus Knot Software Ltd |
---|
8 | |
---|
9 | Permission is hereby granted, free of charge, to any person obtaining a copy |
---|
10 | of this software and associated documentation files (the "Software"), to deal |
---|
11 | in the Software without restriction, including without limitation the rights |
---|
12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
---|
13 | copies of the Software, and to permit persons to whom the Software is |
---|
14 | furnished to do so, subject to the following conditions: |
---|
15 | |
---|
16 | The above copyright notice and this permission notice shall be included in |
---|
17 | all copies or substantial portions of the Software. |
---|
18 | |
---|
19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
---|
22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
---|
24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
---|
25 | THE SOFTWARE. |
---|
26 | ----------------------------------------------------------------------------- |
---|
27 | */ |
---|
28 | #ifndef _UserObjectsBinding_H__ |
---|
29 | #define _UserObjectsBinding_H__ |
---|
30 | |
---|
31 | #include "OgrePrerequisites.h" |
---|
32 | #include "OgreAny.h" |
---|
33 | #include "OgreHeaderPrefix.h" |
---|
34 | |
---|
35 | namespace Ogre { |
---|
36 | |
---|
37 | /** \addtogroup Core |
---|
38 | * @{ |
---|
39 | */ |
---|
40 | /** \addtogroup Scene |
---|
41 | * @{ |
---|
42 | */ |
---|
43 | |
---|
44 | /** Class that provides convenient interface to establish a linkage between |
---|
45 | custom user application objects and Ogre core classes. |
---|
46 | Any instance of Ogre class that will derive from this class could be associated with custom |
---|
47 | application object using this class interface. |
---|
48 | */ |
---|
49 | class _OgreExport UserObjectBindings : public GeneralAllocatedObject |
---|
50 | { |
---|
51 | public: |
---|
52 | /** Class constructor. */ |
---|
53 | UserObjectBindings(); |
---|
54 | |
---|
55 | /** Class destructor. */ |
---|
56 | virtual ~UserObjectBindings(); |
---|
57 | |
---|
58 | /** Sets any kind of user object on this class instance. |
---|
59 | @remarks |
---|
60 | This method allows you to associate any user object you like with |
---|
61 | this class. This can be a pointer back to one of your own |
---|
62 | classes for instance. |
---|
63 | @note This method is key less meaning that each call for it will override |
---|
64 | previous object that were set. If you need to associate multiple objects |
---|
65 | with this class use the extended version that takes key. |
---|
66 | */ |
---|
67 | void setUserAny(const Any& anything); |
---|
68 | |
---|
69 | /** Retrieves the custom key less user object associated with this class. |
---|
70 | */ |
---|
71 | const Any& getUserAny(void) const; |
---|
72 | |
---|
73 | /** Sets any kind of user object on this class instance. |
---|
74 | @remarks |
---|
75 | This method allows you to associate multiple object with this class. |
---|
76 | This can be a pointer back to one of your own classes for instance. |
---|
77 | Use a unique key to distinguish between each of these objects. |
---|
78 | @param key The key that this data is associate with. |
---|
79 | @param anything The data to associate with the given key. |
---|
80 | */ |
---|
81 | void setUserAny(const String& key, const Any& anything); |
---|
82 | |
---|
83 | /** Retrieves the custom user object associated with this class and key. |
---|
84 | @param key The key that the requested user object is associated with. |
---|
85 | @remarks |
---|
86 | In case no object associated with this key the returned Any object will be empty. |
---|
87 | */ |
---|
88 | const Any& getUserAny(const String& key) const; |
---|
89 | |
---|
90 | /** Erase the custom user object associated with this class and key from this binding. |
---|
91 | @param key The key that the requested user object is associated with. |
---|
92 | */ |
---|
93 | void eraseUserAny(const String& key); |
---|
94 | |
---|
95 | /** Clear all user objects from this binding. */ |
---|
96 | void clear() const; |
---|
97 | |
---|
98 | /** Returns empty user any object. |
---|
99 | */ |
---|
100 | static const Any& getEmptyUserAny() { return msEmptyAny; } |
---|
101 | |
---|
102 | // Types. |
---|
103 | protected: |
---|
104 | typedef map<String, Any>::type UserObjectsMap; |
---|
105 | typedef UserObjectsMap::iterator UserObjectsMapIterator; |
---|
106 | typedef UserObjectsMap::const_iterator UserObjectsMapConstIterator; |
---|
107 | |
---|
108 | /** Internal class that uses as data storage container. |
---|
109 | */ |
---|
110 | class Attributes : public GeneralAllocatedObject |
---|
111 | { |
---|
112 | public: |
---|
113 | /** Attribute storage ctor. */ |
---|
114 | Attributes() : mUserObjectsMap(NULL) {} |
---|
115 | |
---|
116 | /** Attribute storage dtor. */ |
---|
117 | ~Attributes() |
---|
118 | { |
---|
119 | if (mUserObjectsMap != NULL) |
---|
120 | { |
---|
121 | OGRE_DELETE mUserObjectsMap; |
---|
122 | mUserObjectsMap = NULL; |
---|
123 | } |
---|
124 | } |
---|
125 | |
---|
126 | Any mKeylessAny; // Will hold key less associated user object for fast access. |
---|
127 | UserObjectsMap* mUserObjectsMap; // Will hold a map between user keys to user objects. |
---|
128 | }; |
---|
129 | |
---|
130 | // Attributes. |
---|
131 | private: |
---|
132 | static Any msEmptyAny; // Shared empty any object. |
---|
133 | mutable Attributes* mAttributes; // Class attributes - will be allocated on demand. |
---|
134 | |
---|
135 | }; |
---|
136 | |
---|
137 | /** @} */ |
---|
138 | /** @} */ |
---|
139 | } |
---|
140 | |
---|
141 | #include "OgreHeaderSuffix.h" |
---|
142 | |
---|
143 | #endif |
---|