OpenSceneGraph/include/osgIntrospection/Reflection
Robert Osfield 3c2872a36a From Emmanuel Roche, "I'm joining two zip files to this mail for the modified sources and include files of osgIntrospection.
The modifications I made are very small but they are absolutely usefull to use osgIntrospection with visual studio 7.1 or 8 in debug modes.
This should also solve other minor common problems (converter memory leak, virtual destructor for PropertyInfo, etc...).

I choosed two function names : Reflection::uninitialize() and Type::reset(), this can of course be changed if someone has a better idea...

I made the changes against OSG 2.2.0 public release. I tested the result with VS 7.1, VS 7.1 SP1, VS 8.0 SP1 and AQTime 5.0 on Windows XP SP2... All 4 seem to agree : they detected memory leaks before and don't anymore.

Sorry I haven't take the time to test that on linux but the changes are so small I doubt there could be a problem... I let you check that on your side  :-).

I hope this will help making OSG an even more wonderfull library."
2008-02-25 16:26:30 +00:00

117 lines
4.5 KiB
C++

/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
//osgIntrospection - Copyright (C) 2005 Marco Jez
#ifndef OSGINTROSPECTION_REFLECTION_
#define OSGINTROSPECTION_REFLECTION_
#include <osgIntrospection/Export>
#include <osgIntrospection/ExtendedTypeInfo>
#include <typeinfo>
#include <map>
#include <vector>
#include <list>
/// This macro emulates the behavior of the standard typeid operator,
/// returning the Type object associated to the type of the given
/// expression.
#define typeof(type) osgIntrospection::Reflection::getType(extended_typeid< type >())
#define typeofvalue(val) osgIntrospection::Reflection::getType(osgIntrospection::ExtendedTypeInfo(typeid(val), false, false))
namespace osgIntrospection
{
class Type;
struct Converter;
typedef std::list<const Converter* > ConverterList;
/// A map of types, indexed by their associated ExtendedTypeInfo
/// structure.
typedef std::map<ExtendedTypeInfo, Type*> TypeMap;
enum CastType
{
STATIC_CAST,
DYNAMIC_CAST,
REINTERPRET_CAST,
COMPOSITE_CAST
};
/// This class provides basic reflection services such as registration
/// of new types and queries on the global type map.
class OSGINTROSPECTION_EXPORT Reflection
{
public:
/// Returns the Type object associated to the given
/// ExtendedTypeInfo structure. If the type hasn't been created
/// yet it is automatically created and added to the global type
/// map. Please note that such type will have the status of
/// "declared", you still need to give details about it through
/// a Reflector class before you can query it.
static const Type& getType(const ExtendedTypeInfo &ti);
/// Finds a Type object given its qualified name, which must
/// be identical to the qualified name returned by that Type's
/// getQualifiedName() method. If the type hasn't been created
/// yet, an exception is thrown.
static const Type& getType(const std::string& qname);
/// Returns the global map of types.
static const TypeMap& getTypes();
/// Return the Type object associated to the C++ type 'void'.
/// This is a shortcut for typeof(void), which may be slow if
/// the type map is large.
static const Type& type_void();
static const Converter* getConverter(const Type& source, const Type& dest);
static bool getConversionPath(const Type& source, const Type& dest, ConverterList& conv);
// This function should be called (at least on windows platforms using Visual Studio 7.1 or 8 as compiler) to unregister
// all the known types before exiting your program: otherwise, you will get a lot of false positive memory leaks in debug builds.
// It might also be used to dynamically reload the description of the known types (?)
static void uninitialize();
private:
template<typename C> friend class Reflector;
template<typename C> friend struct TypeNameAliasProxy;
friend struct ConverterProxy;
struct StaticData
{
TypeMap typemap;
const Type* type_void;
typedef std::map<const Type* , const Converter* > ConverterMap;
typedef std::map<const Type* , ConverterMap> ConverterMapMap;
ConverterMapMap convmap;
~StaticData();
};
static StaticData& getOrCreateStaticData();
static Type* registerType(const ExtendedTypeInfo &ti);
static Type* getOrRegisterType(const ExtendedTypeInfo &ti, bool replace_if_defined = false);
static void registerConverter(const Type& source, const Type& dest, const Converter* cvt);
private:
static bool accum_conv_path(const Type& source, const Type& dest, ConverterList& conv, std::vector<const Type* > &chain, CastType castType);
static StaticData* _static_data;
};
}
#endif