Coverage Report

Created: 2025-07-18 07:08

/src/ogre/OgreMain/include/OgreUserObjectBindings.h
Line
Count
Source (jump to first uncovered line)
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-2014 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
    */
47
    class _OgreExport UserObjectBindings : public GeneralAllocatedObject
48
    {
49
    public:
50
        /** Sets any kind of user object on this class instance.
51
52
        This method allows you to associate any user object you like with
53
        this class. This can be a pointer back to one of your own
54
        classes for instance.
55
        @note This method is key less meaning that each call for it will override
56
        previous object that were set. If you need to associate multiple objects
57
        with this class use the extended version that takes key.
58
        */
59
        void setUserAny(const Any& anything);
60
61
        /** Retrieves the custom key less user object associated with this class.
62
        */
63
        const Any& getUserAny(void) const;
64
65
        /** Sets any kind of user object on this class instance.
66
67
        This method allows you to associate multiple object with this class.
68
        This can be a pointer back to one of your own classes for instance.
69
        Use a unique key to distinguish between each of these objects.
70
        @param key The key that this data is associate with.
71
        @param anything The data to associate with the given key.
72
        */
73
        void setUserAny(const String& key, const Any& anything);
74
75
        /** Retrieves the custom user object associated with this class and key.
76
        @param key The key that the requested user object is associated with.
77
78
        In case no object associated with this key the returned Any object will be empty.
79
        */
80
        const Any& getUserAny(const String& key) const;
81
82
        /** Erase the custom user object associated with this class and key from this binding.
83
        @param key The key that the requested user object is associated with.
84
        */
85
        void eraseUserAny(const String& key);
86
87
        /** Clear all user objects from this binding.   */
88
        void clear();
89
90
0
        UserObjectBindings() = default;
91
92
        /** Copy constructor. Performs a copy of all stored UserAny. */
93
        UserObjectBindings(const UserObjectBindings& other);
94
95
        UserObjectBindings& swap(UserObjectBindings& rhs);
96
97
        UserObjectBindings& operator=(const UserObjectBindings& rhs);
98
99
    // Types.
100
    private:
101
        typedef std::map<String, Any>          UserObjectsMap;
102
        typedef UserObjectsMap::iterator        UserObjectsMapIterator;
103
        typedef UserObjectsMap::const_iterator  UserObjectsMapConstIterator;
104
105
        /** Internal class that uses as data storage container.
106
        */
107
        struct Attributes : public GeneralAllocatedObject
108
        {
109
            Attributes() = default;
110
111
            /** Copy ctor. Copies the attribute storage. */
112
            Attributes(const Attributes& other) :
113
                mKeylessAny(other.mKeylessAny)
114
0
            {
115
0
                if (other.mUserObjectsMap)
116
0
                    mUserObjectsMap.reset(new UserObjectsMap(*other.mUserObjectsMap));
117
0
            }
118
119
            Any                 mKeylessAny;// Will hold key less associated user object for fast access.
120
            std::unique_ptr<UserObjectsMap> mUserObjectsMap;// Will hold a map between user keys to user objects.
121
        };
122
123
        /** \brief Protected getter for the attributes map, to allow derived classes to inspect its elements. */
124
0
        const Attributes* getAttributes() const { return mAttributes.get(); }
125
0
        Attributes* getAttributes() { return mAttributes.get(); }
126
127
    // Attributes.
128
    private:
129
        std::unique_ptr<Attributes>     mAttributes;        // Class attributes - will be allocated on demand.
130
    };
131
132
    /** @} */
133
    /** @} */
134
}
135
136
#include "OgreHeaderSuffix.h"
137
138
#endif