Coverage Report

Created: 2025-07-18 07:08

/src/ogre/OgreMain/include/OgreAny.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
// -- Based on boost::any, original copyright information follows --
29
// Copyright Kevlin Henney, 2000, 2001, 2002. All rights reserved.
30
//
31
// Distributed under the Boost Software License, Version 1.0. (See
32
// accompAnying file LICENSE_1_0.txt or copy at
33
// http://www.boost.org/LICENSE_1_0.txt)
34
// -- End original copyright --
35
36
#ifndef __OGRE_ANY_H__
37
#define __OGRE_ANY_H__
38
39
#include "OgrePrerequisites.h"
40
#include <typeinfo>
41
#include "OgreHeaderPrefix.h"
42
43
namespace Ogre
44
{
45
  // resolve circular dependency
46
    class Any;
47
    template<typename ValueType> ValueType
48
    any_cast(const Any & operand);
49
50
    /** \addtogroup Core
51
    *  @{
52
    */
53
    /** \addtogroup General
54
    *  @{
55
    */
56
    /** Variant type that can hold Any other type.
57
    */
58
    class Any 
59
    {
60
    public: // constructors
61
62
        Any()
63
4
          : mContent(0)
64
4
        {
65
4
        }
66
67
        template<typename ValueType>
68
        Any(const ValueType & value)
69
0
          : mContent(OGRE_NEW_T(holder<ValueType>, MEMCATEGORY_GENERAL)(value))
70
0
        {
71
0
        }
Unexecuted instantiation: Ogre::Any::Any<std::__1::shared_ptr<Ogre::TerrainGroup> >(std::__1::shared_ptr<Ogre::TerrainGroup> const&)
Unexecuted instantiation: Ogre::Any::Any<bool>(bool const&)
Unexecuted instantiation: Ogre::Any::Any<float>(float const&)
Unexecuted instantiation: Ogre::Any::Any<int>(int const&)
Unexecuted instantiation: Ogre::Any::Any<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)
Unexecuted instantiation: Ogre::Any::Any<Ogre::Terrain::DerivedDataRequest>(Ogre::Terrain::DerivedDataRequest const&)
Unexecuted instantiation: Ogre::Any::Any<Ogre::Terrain::DerivedDataResponse>(Ogre::Terrain::DerivedDataResponse const&)
Unexecuted instantiation: Ogre::Any::Any<Ogre::TerrainGroup::TerrainSlot*>(Ogre::TerrainGroup::TerrainSlot* const&)
Unexecuted instantiation: Ogre::Any::Any<Ogre::TerrainLodManager::LoadLodRequest>(Ogre::TerrainLodManager::LoadLodRequest const&)
Unexecuted instantiation: Ogre::Any::Any<Ogre::Terrain const*>(Ogre::Terrain const* const&)
Unexecuted instantiation: Ogre::Any::Any<std::__1::vector<float, std::__1::allocator<float> > >(std::__1::vector<float, std::__1::allocator<float> > const&)
Unexecuted instantiation: Ogre::Any::Any<std::__1::shared_ptr<Ogre::RTShader::TargetRenderState> >(std::__1::shared_ptr<Ogre::RTShader::TargetRenderState> const&)
Unexecuted instantiation: Ogre::Any::Any<Ogre::SceneNode*>(Ogre::SceneNode* const&)
72
73
        Any(const Any & other)
74
0
          : mContent(other.mContent ? other.mContent->clone() : 0)
75
0
        {
76
0
        }
77
78
        virtual ~Any()
79
6.81k
        {
80
6.81k
            reset();
81
6.81k
        }
82
83
    public: // modifiers
84
85
        Any& swap(Any & rhs)
86
0
        {
87
0
            std::swap(mContent, rhs.mContent);
88
0
            return *this;
89
0
        }
90
91
        template<typename ValueType>
92
        Any& operator=(const ValueType & rhs)
93
0
        {
94
0
            Any(rhs).swap(*this);
95
0
            return *this;
96
0
        }
Unexecuted instantiation: Ogre::Any& Ogre::Any::operator=<bool>(bool const&)
Unexecuted instantiation: Ogre::Any& Ogre::Any::operator=<float>(float const&)
Unexecuted instantiation: Ogre::Any& Ogre::Any::operator=<int>(int const&)
Unexecuted instantiation: Ogre::Any& Ogre::Any::operator=<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)
97
98
        Any & operator=(const Any & rhs)
99
0
        {
100
0
            Any(rhs).swap(*this);
101
0
            return *this;
102
0
        }
103
104
    public: // queries
105
106
        bool has_value() const
107
0
        {
108
0
            return mContent != NULL;
109
0
        }
110
111
        /// @deprecated use has_value() instead
112
0
        OGRE_DEPRECATED bool isEmpty() const { return !has_value(); }
113
114
        const std::type_info& type() const
115
6.81k
        {
116
6.81k
            return mContent ? mContent->getType() : typeid(void);
117
6.81k
        }
118
119
        /// @deprecated use type() instead
120
0
        OGRE_DEPRECATED const std::type_info& getType() const { return type(); }
121
122
        /// @deprecated no longer supported
123
        OGRE_DEPRECATED friend std::ostream& operator <<
124
            ( std::ostream& o, const Any& v )
125
0
        {
126
0
            if (v.mContent)
127
0
                v.mContent->writeToStream(o);
128
0
            return o;
129
0
        }
130
131
        void reset()
132
6.81k
        {
133
6.81k
            OGRE_DELETE_T(mContent, placeholder, MEMCATEGORY_GENERAL);
134
6.81k
            mContent = NULL;
135
6.81k
        }
136
137
        /// @deprecated use reset() instead
138
0
        OGRE_DEPRECATED void destroy() { reset(); }
139
140
    protected: // types
141
142
        class placeholder 
143
        {
144
        public: // structors
145
    
146
            virtual ~placeholder()
147
6.81k
            {
148
6.81k
            }
149
150
        public: // queries
151
152
            virtual const std::type_info& getType() const = 0;
153
154
            virtual placeholder * clone() const = 0;
155
    
156
            virtual void writeToStream(std::ostream& o) = 0;
157
158
        };
159
160
        template<typename ValueType>
161
        class holder : public placeholder
162
        {
163
        public: // structors
164
165
            holder(const ValueType & value)
166
0
              : held(value)
167
0
            {
168
0
            }
Unexecuted instantiation: Ogre::Any::holder<std::__1::shared_ptr<Ogre::TerrainGroup> >::holder(std::__1::shared_ptr<Ogre::TerrainGroup> const&)
Unexecuted instantiation: Ogre::Any::holder<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::holder(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)
Unexecuted instantiation: Ogre::Any::holder<Ogre::Terrain::DerivedDataRequest>::holder(Ogre::Terrain::DerivedDataRequest const&)
Unexecuted instantiation: Ogre::Any::holder<Ogre::Terrain::DerivedDataResponse>::holder(Ogre::Terrain::DerivedDataResponse const&)
Unexecuted instantiation: Ogre::Any::holder<Ogre::TerrainLodManager::LoadLodRequest>::holder(Ogre::TerrainLodManager::LoadLodRequest const&)
Unexecuted instantiation: Ogre::Any::holder<std::__1::vector<float, std::__1::allocator<float> > >::holder(std::__1::vector<float, std::__1::allocator<float> > const&)
Unexecuted instantiation: Ogre::Any::holder<std::__1::shared_ptr<Ogre::RTShader::TargetRenderState> >::holder(std::__1::shared_ptr<Ogre::RTShader::TargetRenderState> const&)
Unexecuted instantiation: Ogre::Any::holder<bool>::holder(bool const&)
Unexecuted instantiation: Ogre::Any::holder<float>::holder(float const&)
Unexecuted instantiation: Ogre::Any::holder<int>::holder(int const&)
Unexecuted instantiation: Ogre::Any::holder<Ogre::TerrainGroup::TerrainSlot*>::holder(Ogre::TerrainGroup::TerrainSlot* const&)
Unexecuted instantiation: Ogre::Any::holder<Ogre::Terrain const*>::holder(Ogre::Terrain const* const&)
Unexecuted instantiation: Ogre::Any::holder<Ogre::SceneNode*>::holder(Ogre::SceneNode* const&)
169
170
        public: // queries
171
172
            const std::type_info & getType() const override
173
0
            {
174
0
                return typeid(ValueType);
175
0
            }
Unexecuted instantiation: Ogre::Any::holder<std::__1::shared_ptr<Ogre::TerrainGroup> >::getType() const
Unexecuted instantiation: Ogre::Any::holder<bool>::getType() const
Unexecuted instantiation: Ogre::Any::holder<float>::getType() const
Unexecuted instantiation: Ogre::Any::holder<int>::getType() const
Unexecuted instantiation: Ogre::Any::holder<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::getType() const
Unexecuted instantiation: Ogre::Any::holder<Ogre::Terrain::DerivedDataRequest>::getType() const
Unexecuted instantiation: Ogre::Any::holder<Ogre::Terrain::DerivedDataResponse>::getType() const
Unexecuted instantiation: Ogre::Any::holder<Ogre::TerrainGroup::TerrainSlot*>::getType() const
Unexecuted instantiation: Ogre::Any::holder<Ogre::TerrainLodManager::LoadLodRequest>::getType() const
Unexecuted instantiation: Ogre::Any::holder<Ogre::Terrain const*>::getType() const
Unexecuted instantiation: Ogre::Any::holder<std::__1::vector<float, std::__1::allocator<float> > >::getType() const
Unexecuted instantiation: Ogre::Any::holder<std::__1::shared_ptr<Ogre::RTShader::TargetRenderState> >::getType() const
Unexecuted instantiation: Ogre::Any::holder<Ogre::SceneNode*>::getType() const
176
177
            placeholder * clone() const override
178
0
            {
179
0
                return OGRE_NEW_T(holder, MEMCATEGORY_GENERAL)(held);
180
0
            }
Unexecuted instantiation: Ogre::Any::holder<std::__1::shared_ptr<Ogre::TerrainGroup> >::clone() const
Unexecuted instantiation: Ogre::Any::holder<bool>::clone() const
Unexecuted instantiation: Ogre::Any::holder<float>::clone() const
Unexecuted instantiation: Ogre::Any::holder<int>::clone() const
Unexecuted instantiation: Ogre::Any::holder<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::clone() const
Unexecuted instantiation: Ogre::Any::holder<Ogre::Terrain::DerivedDataRequest>::clone() const
Unexecuted instantiation: Ogre::Any::holder<Ogre::Terrain::DerivedDataResponse>::clone() const
Unexecuted instantiation: Ogre::Any::holder<Ogre::TerrainGroup::TerrainSlot*>::clone() const
Unexecuted instantiation: Ogre::Any::holder<Ogre::TerrainLodManager::LoadLodRequest>::clone() const
Unexecuted instantiation: Ogre::Any::holder<Ogre::Terrain const*>::clone() const
Unexecuted instantiation: Ogre::Any::holder<std::__1::vector<float, std::__1::allocator<float> > >::clone() const
Unexecuted instantiation: Ogre::Any::holder<std::__1::shared_ptr<Ogre::RTShader::TargetRenderState> >::clone() const
Unexecuted instantiation: Ogre::Any::holder<Ogre::SceneNode*>::clone() const
181
182
            void writeToStream(std::ostream& o) override
183
0
            {
184
0
                o << "Any::ValueType";
185
0
            }
Unexecuted instantiation: Ogre::Any::holder<std::__1::shared_ptr<Ogre::TerrainGroup> >::writeToStream(std::__1::basic_ostream<char, std::__1::char_traits<char> >&)
Unexecuted instantiation: Ogre::Any::holder<bool>::writeToStream(std::__1::basic_ostream<char, std::__1::char_traits<char> >&)
Unexecuted instantiation: Ogre::Any::holder<float>::writeToStream(std::__1::basic_ostream<char, std::__1::char_traits<char> >&)
Unexecuted instantiation: Ogre::Any::holder<int>::writeToStream(std::__1::basic_ostream<char, std::__1::char_traits<char> >&)
Unexecuted instantiation: Ogre::Any::holder<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::writeToStream(std::__1::basic_ostream<char, std::__1::char_traits<char> >&)
Unexecuted instantiation: Ogre::Any::holder<Ogre::Terrain::DerivedDataRequest>::writeToStream(std::__1::basic_ostream<char, std::__1::char_traits<char> >&)
Unexecuted instantiation: Ogre::Any::holder<Ogre::Terrain::DerivedDataResponse>::writeToStream(std::__1::basic_ostream<char, std::__1::char_traits<char> >&)
Unexecuted instantiation: Ogre::Any::holder<Ogre::TerrainGroup::TerrainSlot*>::writeToStream(std::__1::basic_ostream<char, std::__1::char_traits<char> >&)
Unexecuted instantiation: Ogre::Any::holder<Ogre::TerrainLodManager::LoadLodRequest>::writeToStream(std::__1::basic_ostream<char, std::__1::char_traits<char> >&)
Unexecuted instantiation: Ogre::Any::holder<Ogre::Terrain const*>::writeToStream(std::__1::basic_ostream<char, std::__1::char_traits<char> >&)
Unexecuted instantiation: Ogre::Any::holder<std::__1::vector<float, std::__1::allocator<float> > >::writeToStream(std::__1::basic_ostream<char, std::__1::char_traits<char> >&)
Unexecuted instantiation: Ogre::Any::holder<std::__1::shared_ptr<Ogre::RTShader::TargetRenderState> >::writeToStream(std::__1::basic_ostream<char, std::__1::char_traits<char> >&)
Unexecuted instantiation: Ogre::Any::holder<Ogre::SceneNode*>::writeToStream(std::__1::basic_ostream<char, std::__1::char_traits<char> >&)
186
187
188
        public: // representation
189
190
            ValueType held;
191
192
        };
193
194
195
196
    protected: // representation
197
        placeholder * mContent;
198
199
        template<typename ValueType>
200
        friend ValueType * any_cast(Any *);
201
202
203
    public: 
204
        /// @deprecated use Ogre::any_cast instead
205
        template<typename ValueType>
206
        OGRE_DEPRECATED ValueType operator()() const
207
        {
208
            return any_cast<ValueType>(*this);
209
        }
210
211
        /// @deprecated use Ogre::any_cast instead
212
        template <typename ValueType>
213
        OGRE_DEPRECATED ValueType get(void) const
214
        {
215
            return any_cast<ValueType>(*this);
216
        }
217
218
    };
219
220
    template<typename ValueType>
221
    ValueType * any_cast(Any * operand)
222
6.81k
    {
223
6.81k
        return operand &&
224
#if (OGRE_COMPILER == OGRE_COMPILER_GNUC && OGRE_COMP_VER < 450) || OGRE_PLATFORM == OGRE_PLATFORM_APPLE_IOS
225
                (std::strcmp(operand->type().name(), typeid(ValueType).name()) == 0)
226
#else
227
6.81k
                (operand->type() == typeid(ValueType))
228
6.81k
#endif
229
6.81k
                    ? &static_cast<Any::holder<ValueType> *>(operand->mContent)->held
230
6.81k
                    : 0;
231
6.81k
    }
Ogre::Image** Ogre::any_cast<Ogre::Image*>(Ogre::Any*)
Line
Count
Source
222
6.81k
    {
223
6.81k
        return operand &&
224
#if (OGRE_COMPILER == OGRE_COMPILER_GNUC && OGRE_COMP_VER < 450) || OGRE_PLATFORM == OGRE_PLATFORM_APPLE_IOS
225
                (std::strcmp(operand->type().name(), typeid(ValueType).name()) == 0)
226
#else
227
6.81k
                (operand->type() == typeid(ValueType))
228
6.81k
#endif
229
6.81k
                    ? &static_cast<Any::holder<ValueType> *>(operand->mContent)->held
230
6.81k
                    : 0;
231
6.81k
    }
Unexecuted instantiation: Ogre::SceneNode** Ogre::any_cast<Ogre::SceneNode*>(Ogre::Any*)
Unexecuted instantiation: Ogre::Terrain::DerivedDataRequest* Ogre::any_cast<Ogre::Terrain::DerivedDataRequest>(Ogre::Any*)
Unexecuted instantiation: Ogre::Terrain::DerivedDataResponse* Ogre::any_cast<Ogre::Terrain::DerivedDataResponse>(Ogre::Any*)
Unexecuted instantiation: Ogre::TerrainGroup::TerrainSlot** Ogre::any_cast<Ogre::TerrainGroup::TerrainSlot*>(Ogre::Any*)
Unexecuted instantiation: Ogre::TerrainLodManager::LoadLodRequest* Ogre::any_cast<Ogre::TerrainLodManager::LoadLodRequest>(Ogre::Any*)
Unexecuted instantiation: std::__1::shared_ptr<Ogre::RTShader::TargetRenderState>* Ogre::any_cast<std::__1::shared_ptr<Ogre::RTShader::TargetRenderState> >(Ogre::Any*)
Unexecuted instantiation: Ogre::Terrain const** Ogre::any_cast<Ogre::Terrain const*>(Ogre::Any*)
Unexecuted instantiation: float* Ogre::any_cast<float>(Ogre::Any*)
232
233
    template<typename ValueType>
234
    const ValueType * any_cast(const Any * operand)
235
6.81k
    {
236
6.81k
        return any_cast<ValueType>(const_cast<Any *>(operand));
237
6.81k
    }
Ogre::Image* const* Ogre::any_cast<Ogre::Image*>(Ogre::Any const*)
Line
Count
Source
235
6.81k
    {
236
6.81k
        return any_cast<ValueType>(const_cast<Any *>(operand));
237
6.81k
    }
Unexecuted instantiation: Ogre::SceneNode* const* Ogre::any_cast<Ogre::SceneNode*>(Ogre::Any const*)
Unexecuted instantiation: Ogre::Terrain::DerivedDataRequest const* Ogre::any_cast<Ogre::Terrain::DerivedDataRequest>(Ogre::Any const*)
Unexecuted instantiation: Ogre::Terrain::DerivedDataResponse const* Ogre::any_cast<Ogre::Terrain::DerivedDataResponse>(Ogre::Any const*)
Unexecuted instantiation: Ogre::TerrainGroup::TerrainSlot* const* Ogre::any_cast<Ogre::TerrainGroup::TerrainSlot*>(Ogre::Any const*)
Unexecuted instantiation: Ogre::TerrainLodManager::LoadLodRequest const* Ogre::any_cast<Ogre::TerrainLodManager::LoadLodRequest>(Ogre::Any const*)
Unexecuted instantiation: std::__1::shared_ptr<Ogre::RTShader::TargetRenderState> const* Ogre::any_cast<std::__1::shared_ptr<Ogre::RTShader::TargetRenderState> >(Ogre::Any const*)
Unexecuted instantiation: Ogre::Terrain const* const* Ogre::any_cast<Ogre::Terrain const*>(Ogre::Any const*)
Unexecuted instantiation: float const* Ogre::any_cast<float>(Ogre::Any const*)
238
239
    template<typename ValueType>
240
    ValueType any_cast(const Any & operand)
241
6.81k
    {
242
6.81k
        const ValueType * result = any_cast<ValueType>(&operand);
243
6.81k
        if(!result)
244
0
        {
245
0
            throw std::bad_cast();
246
0
        }
247
6.81k
        return *result;
248
6.81k
    }
Ogre::Image* Ogre::any_cast<Ogre::Image*>(Ogre::Any const&)
Line
Count
Source
241
6.81k
    {
242
6.81k
        const ValueType * result = any_cast<ValueType>(&operand);
243
6.81k
        if(!result)
244
0
        {
245
0
            throw std::bad_cast();
246
0
        }
247
6.81k
        return *result;
248
6.81k
    }
Unexecuted instantiation: Ogre::SceneNode* Ogre::any_cast<Ogre::SceneNode*>(Ogre::Any const&)
Unexecuted instantiation: Ogre::Terrain::DerivedDataRequest Ogre::any_cast<Ogre::Terrain::DerivedDataRequest>(Ogre::Any const&)
Unexecuted instantiation: Ogre::Terrain::DerivedDataResponse Ogre::any_cast<Ogre::Terrain::DerivedDataResponse>(Ogre::Any const&)
Unexecuted instantiation: Ogre::TerrainGroup::TerrainSlot* Ogre::any_cast<Ogre::TerrainGroup::TerrainSlot*>(Ogre::Any const&)
Unexecuted instantiation: Ogre::TerrainLodManager::LoadLodRequest Ogre::any_cast<Ogre::TerrainLodManager::LoadLodRequest>(Ogre::Any const&)
Unexecuted instantiation: std::__1::shared_ptr<Ogre::RTShader::TargetRenderState> Ogre::any_cast<std::__1::shared_ptr<Ogre::RTShader::TargetRenderState> >(Ogre::Any const&)
Unexecuted instantiation: Ogre::Terrain const* Ogre::any_cast<Ogre::Terrain const*>(Ogre::Any const&)
Unexecuted instantiation: float Ogre::any_cast<float>(Ogre::Any const&)
249
    /** @} */
250
    /** @} */
251
252
253
}
254
255
#include "OgreHeaderSuffix.h"
256
257
#endif
258