Coverage Report

Created: 2025-11-25 06:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ogre/OgreMain/src/OgreUserObjectBindings.cpp
Line
Count
Source
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
#include <memory>
29
30
#include "OgreStableHeaders.h"
31
32
namespace Ogre {
33
    static Any emptyAny;
34
35
    //--------------------------------------------------------------------------
36
    UserObjectBindings::UserObjectBindings(const UserObjectBindings& other)
37
0
    {
38
0
        if (other.mAttributes)
39
0
            mAttributes = std::make_unique<Attributes>(*other.mAttributes);
40
0
    }
41
42
    UserObjectBindings& UserObjectBindings::swap(UserObjectBindings& rhs)
43
0
    {
44
0
        std::swap(mAttributes, rhs.mAttributes);
45
0
        return *this;
46
0
    }
47
48
    UserObjectBindings& UserObjectBindings::operator=(const UserObjectBindings& rhs)
49
0
    {
50
0
        UserObjectBindings(rhs).swap(*this);
51
0
        return *this;
52
0
    }
53
54
    //-----------------------------------------------------------------------
55
    void UserObjectBindings::setUserAny( const Any& anything )
56
0
    {
57
        // Allocate attributes on demand.
58
0
        if (!mAttributes)
59
0
            mAttributes = std::make_unique<Attributes>();
60
61
0
        mAttributes->mKeylessAny = anything;
62
0
    }
63
64
    //-----------------------------------------------------------------------
65
    const Any& UserObjectBindings::getUserAny() const
66
0
    {
67
        // Allocate attributes on demand.
68
0
        if (!mAttributes)
69
0
            return emptyAny;
70
71
0
        return mAttributes->mKeylessAny;
72
0
    }
73
74
    //-----------------------------------------------------------------------
75
    void UserObjectBindings::setUserAny(const String& key, const Any& anything)
76
0
    {
77
        // Allocate attributes on demand.
78
0
        if (!mAttributes)
79
0
            mAttributes = std::make_unique<Attributes>();
80
81
        // Case map doesn't exists.
82
0
        if (!mAttributes->mUserObjectsMap)
83
0
            mAttributes->mUserObjectsMap = std::make_unique<UserObjectsMap>();
84
85
0
        (*mAttributes->mUserObjectsMap)[key] = anything;
86
0
    }
87
88
    //-----------------------------------------------------------------------
89
    const Any& UserObjectBindings::getUserAny(const String& key) const
90
0
    {
91
0
        if (!mAttributes)
92
0
            return emptyAny;
93
94
        // Case map doesn't exists.
95
0
        if (!mAttributes->mUserObjectsMap)
96
0
            return emptyAny;
97
98
0
        UserObjectsMapConstIterator it = mAttributes->mUserObjectsMap->find(key);
99
100
        // Case user data found.
101
0
        if (it != mAttributes->mUserObjectsMap->end())
102
0
        {
103
0
            return it->second;
104
0
        }
105
106
0
        return emptyAny;
107
0
    }
108
109
    //-----------------------------------------------------------------------
110
    void UserObjectBindings::eraseUserAny(const String& key)
111
0
    {
112
        // Case attributes and map allocated.
113
0
        if (mAttributes && mAttributes->mUserObjectsMap)
114
0
        {
115
0
            UserObjectsMapIterator it = mAttributes->mUserObjectsMap->find(key);
116
117
            // Case object found -> erase it from the map.
118
0
            if (it != mAttributes->mUserObjectsMap->end())
119
0
            {
120
0
                mAttributes->mUserObjectsMap->erase(it);
121
0
            }
122
0
        }
123
0
    }
124
125
    //-----------------------------------------------------------------------
126
    void UserObjectBindings::clear()
127
0
    {
128
0
        mAttributes.reset();
129
0
    }
130
}