From Marco Jez, improvements to osgIntrospection, and new automatically generated
osgWrappers/osg set.
This commit is contained in:
@@ -166,14 +166,24 @@ class Vec2d
|
||||
return( norm );
|
||||
}
|
||||
|
||||
friend inline std::ostream& operator << (std::ostream& output, const Vec2d& vec)
|
||||
{
|
||||
output << vec._v[0] << " "
|
||||
<< vec._v[1];
|
||||
return output; // to enable cascading
|
||||
}
|
||||
|
||||
}; // end of class Vec2d
|
||||
|
||||
|
||||
// streaming operators
|
||||
|
||||
inline std::ostream& operator << (std::ostream& output, const Vec2d& vec)
|
||||
{
|
||||
output << vec._v[0] << " "
|
||||
<< vec._v[1];
|
||||
return output; // to enable cascading
|
||||
}
|
||||
|
||||
inline std::istream& operator >> (std::istream& input, Vec2d& vec)
|
||||
{
|
||||
input >> vec._v[0] >> vec._v[1];
|
||||
return input;
|
||||
}
|
||||
|
||||
|
||||
} // end of namespace osg
|
||||
#endif
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#define OSG_VEC2F 1
|
||||
|
||||
#include <ostream>
|
||||
#include <istream>
|
||||
|
||||
#include <osg/Math>
|
||||
|
||||
@@ -162,14 +163,25 @@ class Vec2f
|
||||
}
|
||||
return( norm );
|
||||
}
|
||||
|
||||
friend inline std::ostream& operator << (std::ostream& output, const Vec2f& vec)
|
||||
{
|
||||
output << vec._v[0] << " " << vec._v[1];
|
||||
return output; // to enable cascading
|
||||
}
|
||||
|
||||
|
||||
}; // end of class Vec2f
|
||||
|
||||
|
||||
// streaming operators
|
||||
|
||||
inline std::ostream& operator << (std::ostream& output, const Vec2f& vec)
|
||||
{
|
||||
output << vec._v[0] << " " << vec._v[1];
|
||||
return output; // to enable cascading
|
||||
}
|
||||
|
||||
inline std::istream& operator >> (std::istream& input, Vec2f& vec)
|
||||
{
|
||||
input >> vec._v[0] >> vec._v[1];
|
||||
return input;
|
||||
}
|
||||
|
||||
|
||||
} // end of namespace osg
|
||||
#endif
|
||||
|
||||
|
||||
@@ -197,10 +197,11 @@ class Vec3d
|
||||
return( norm );
|
||||
}
|
||||
|
||||
friend inline std::ostream& operator << (std::ostream& output, const Vec3d& vec);
|
||||
|
||||
}; // end of class Vec3d
|
||||
|
||||
|
||||
// streaming operators
|
||||
|
||||
inline std::ostream& operator << (std::ostream& output, const Vec3d& vec)
|
||||
{
|
||||
output << vec._v[0] << " "
|
||||
@@ -209,6 +210,13 @@ inline std::ostream& operator << (std::ostream& output, const Vec3d& vec)
|
||||
return output; // to enable cascading
|
||||
}
|
||||
|
||||
inline std::istream& operator >> (std::istream& input, Vec3d& vec)
|
||||
{
|
||||
input >> vec._v[0] >> vec._v[1] >> vec._v[2];
|
||||
return input;
|
||||
}
|
||||
|
||||
|
||||
} // end of namespace osg
|
||||
|
||||
#endif
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#define OSG_VEC3F 1
|
||||
|
||||
#include <ostream>
|
||||
#include <istream>
|
||||
|
||||
#include <osg/Vec2f>
|
||||
#include <osg/Math>
|
||||
@@ -194,10 +195,10 @@ class Vec3f
|
||||
return( norm );
|
||||
}
|
||||
|
||||
friend inline std::ostream& operator << (std::ostream& output, const Vec3f& vec);
|
||||
|
||||
}; // end of class Vec3f
|
||||
|
||||
// streaming operators
|
||||
|
||||
inline std::ostream& operator << (std::ostream& output, const Vec3f& vec)
|
||||
{
|
||||
output << vec._v[0] << " "
|
||||
@@ -206,6 +207,12 @@ inline std::ostream& operator << (std::ostream& output, const Vec3f& vec)
|
||||
return output; // to enable cascading
|
||||
}
|
||||
|
||||
inline std::istream& operator >> (std::istream& input, Vec3f& vec)
|
||||
{
|
||||
input >> vec._v[0] >> vec._v[1] >> vec._v[2];
|
||||
return input;
|
||||
}
|
||||
|
||||
const Vec3f X_AXIS(1.0,0.0,0.0);
|
||||
const Vec3f Y_AXIS(0.0,1.0,0.0);
|
||||
const Vec3f Z_AXIS(0.0,0.0,1.0);
|
||||
@@ -213,3 +220,4 @@ const Vec3f Z_AXIS(0.0,0.0,1.0);
|
||||
} // end of namespace osg
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -229,18 +229,27 @@ class Vec4f
|
||||
return( norm );
|
||||
}
|
||||
|
||||
friend inline std::ostream& operator << (std::ostream& output, const Vec4f& vec)
|
||||
{
|
||||
output << vec._v[0] << " "
|
||||
<< vec._v[1] << " "
|
||||
<< vec._v[2] << " "
|
||||
<< vec._v[3];
|
||||
return output; // to enable cascading
|
||||
}
|
||||
|
||||
}; // end of class Vec4f
|
||||
|
||||
|
||||
// streaming operators
|
||||
|
||||
inline std::ostream& operator << (std::ostream& output, const Vec4f& vec)
|
||||
{
|
||||
output << vec._v[0] << " "
|
||||
<< vec._v[1] << " "
|
||||
<< vec._v[2] << " "
|
||||
<< vec._v[3];
|
||||
return output; // to enable cascading
|
||||
}
|
||||
|
||||
inline std::istream& operator >> (std::istream& input, Vec4f& vec)
|
||||
{
|
||||
input >> vec._v[0] >> vec._v[1] >> vec._v[2] >> vec._v[3];
|
||||
return input;
|
||||
}
|
||||
|
||||
|
||||
/** Compute the dot product of a (Vec3,1.0) and a Vec4f. */
|
||||
inline Vec4f::value_type operator * (const Vec3f& lhs,const Vec4f& rhs)
|
||||
{
|
||||
@@ -256,3 +265,4 @@ inline Vec4f::value_type operator * (const Vec4f& lhs,const Vec3f& rhs)
|
||||
} // end of namespace osg
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
70
include/osgIntrospection/Converter
Normal file
70
include/osgIntrospection/Converter
Normal file
@@ -0,0 +1,70 @@
|
||||
#ifndef OSGINTROSPECTION_CONVERTER_
|
||||
#define OSGINTROSPECTION_CONVERTER_
|
||||
|
||||
#include <osgIntrospection/Value>
|
||||
#include <vector>
|
||||
|
||||
namespace osgIntrospection
|
||||
{
|
||||
|
||||
struct Converter
|
||||
{
|
||||
virtual Value convert(const Value &) const = 0;
|
||||
virtual ~Converter() {}
|
||||
};
|
||||
|
||||
typedef std::vector<const Converter *> ConverterList;
|
||||
|
||||
class CompositeConverter: public Converter
|
||||
{
|
||||
public:
|
||||
CompositeConverter(const ConverterList &cvt): cvt_(cvt) {}
|
||||
CompositeConverter(ConverterList &cvt) { cvt_.swap(cvt); }
|
||||
virtual ~CompositeConverter() {}
|
||||
|
||||
virtual Value convert(const Value &src) const
|
||||
{
|
||||
Value accum(src);
|
||||
for (ConverterList::const_iterator i=cvt_.begin(); i!=cvt_.end(); ++i)
|
||||
accum = (*i)->convert(accum);
|
||||
return accum;
|
||||
}
|
||||
|
||||
private:
|
||||
ConverterList cvt_;
|
||||
};
|
||||
|
||||
template<typename S, typename D>
|
||||
struct StaticConverter: Converter
|
||||
{
|
||||
virtual ~StaticConverter() {}
|
||||
virtual Value convert(const Value &src) const
|
||||
{
|
||||
return static_cast<D>(variant_cast<S>(src));
|
||||
}
|
||||
};
|
||||
|
||||
template<typename S, typename D>
|
||||
struct DynamicConverter: Converter
|
||||
{
|
||||
virtual ~DynamicConverter() {}
|
||||
virtual Value convert(const Value &src) const
|
||||
{
|
||||
return dynamic_cast<D>(variant_cast<S>(src));
|
||||
}
|
||||
};
|
||||
|
||||
template<typename S, typename D>
|
||||
struct ReinterpretConverter: Converter
|
||||
{
|
||||
virtual ~ReinterpretConverter() {}
|
||||
virtual Value convert(const Value &src) const
|
||||
{
|
||||
return reinterpret_cast<D>(variant_cast<S>(src));
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
22
include/osgIntrospection/ConverterProxy
Normal file
22
include/osgIntrospection/ConverterProxy
Normal file
@@ -0,0 +1,22 @@
|
||||
#ifndef OSGINTROSPECTION_CONVERTERPROXY_
|
||||
#define OSGINTROSPECTION_CONVERTERPROXY_
|
||||
|
||||
#include <osgIntrospection/Reflection>
|
||||
|
||||
namespace osgIntrospection
|
||||
{
|
||||
|
||||
struct Converter;
|
||||
|
||||
struct ConverterProxy
|
||||
{
|
||||
ConverterProxy(const Type &source, const Type &dest, const Converter *cvt)
|
||||
{
|
||||
Reflection::registerConverter(source, dest, cvt);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -13,50 +13,6 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace osg
|
||||
{
|
||||
|
||||
/// ----------------------------------------------------------------------
|
||||
/// TEMPORARY FIX
|
||||
/// (currently osg::Vec? classes don't support input streaming)
|
||||
/// (currently osg::ref_ptr<> class doesn't support I/O streaming)
|
||||
inline std::istream& operator >> (std::istream& input, Vec2f& vec)
|
||||
{
|
||||
input >> vec._v[0] >> vec._v[1];
|
||||
return input;
|
||||
}
|
||||
|
||||
inline std::istream& operator >> (std::istream& input, Vec3f& vec)
|
||||
{
|
||||
input >> vec._v[0] >> vec._v[1] >> vec._v[2];
|
||||
return input;
|
||||
}
|
||||
|
||||
inline std::istream& operator >> (std::istream& input, Vec4& vec)
|
||||
{
|
||||
input >> vec._v[0] >> vec._v[1] >> vec._v[2] >> vec._v[3];
|
||||
return input;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
std::ostream &operator << (std::ostream &s, const osg::ref_ptr<T> &r)
|
||||
{
|
||||
return s << r.get();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
std::istream &operator >> (std::istream &s, osg::ref_ptr<T> &r)
|
||||
{
|
||||
void *ptr;
|
||||
s >> ptr;
|
||||
r = (T *)ptr;
|
||||
return s;
|
||||
}
|
||||
|
||||
///
|
||||
/// END OF TEMPORARY FIX
|
||||
/// ----------------------------------------------------------------------
|
||||
}
|
||||
|
||||
namespace osgIntrospection
|
||||
{
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include <typeinfo>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
/// This macro emulates the behavior of the standard typeid operator,
|
||||
/// returning the Type object associated to the type of the given
|
||||
@@ -15,6 +16,9 @@ namespace osgIntrospection
|
||||
{
|
||||
|
||||
class Type;
|
||||
struct Converter;
|
||||
|
||||
typedef std::vector<const Converter *> ConverterList;
|
||||
|
||||
/// This predicate compares two instances of std::type_info for equality.
|
||||
/// Note that we can't rely on default pointer comparison because it is
|
||||
@@ -58,22 +62,34 @@ namespace osgIntrospection
|
||||
/// 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);
|
||||
|
||||
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 std::type_info &ti);
|
||||
static Type *getOrRegisterType(const std::type_info &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);
|
||||
static StaticData *staticdata__;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
#ifndef OSGINTROSPECTION_REFLECTIONMACROS_
|
||||
#define OSGINTROSPECTION_REFLECTIONMACROS_
|
||||
|
||||
#include <osgIntrospection/Type>
|
||||
#include <osgIntrospection/Reflector>
|
||||
#include <osgIntrospection/TypeNameAliasProxy>
|
||||
#include <osgIntrospection/ConverterProxy>
|
||||
#include <osgIntrospection/Converter>
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// "private" macros, not to be used outside this file
|
||||
@@ -20,6 +23,24 @@
|
||||
|
||||
#define TYPE_NAME_ALIAS(t, n) \
|
||||
namespace { osgIntrospection::TypeNameAliasProxy<t > OSG_RM_LINEID(tnalias) (#n); }
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// TYPE CONVERTERS
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
#define Converter(s, d, c) \
|
||||
namespace { osgIntrospection::ConverterProxy OSG_RM_LINEID(cvt) (s, d, new c); }
|
||||
|
||||
#define StaticConverter(s, d) \
|
||||
Converter(s, d, osgIntrospection::StaticConverter<s, d>);
|
||||
|
||||
#define DynamicConverter(s, d) \
|
||||
Converter(s, d, osgIntrospection::DynamicConverter<s, d>);
|
||||
|
||||
#define ReinterpretConverter(s, d) \
|
||||
Converter(s, d, osgIntrospection::ReinterpretConverter<s, d>);
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// ONE-LINE REFLECTORS
|
||||
@@ -110,7 +131,33 @@
|
||||
#define ReaderWriter(x) setReaderWriter(new x);
|
||||
#define Comparator(x) setComparator(new x);
|
||||
|
||||
#define BaseType(x) addBaseType(typeof(x));
|
||||
#define BaseType(x) \
|
||||
{ \
|
||||
addBaseType(typeof(x)); \
|
||||
const osgIntrospection::Type &st = typeof(reflected_type *); \
|
||||
const osgIntrospection::Type &cst = typeof(const reflected_type *); \
|
||||
const osgIntrospection::Type &dt = typeof(x *); \
|
||||
const osgIntrospection::Type &cdt = typeof(const x *); \
|
||||
osgIntrospection::ConverterProxy cp1(st, dt, new osgIntrospection::StaticConverter<reflected_type *, x *>); \
|
||||
osgIntrospection::ConverterProxy cp2(cst, cdt, new osgIntrospection::StaticConverter<const reflected_type *, const x *>); \
|
||||
osgIntrospection::ConverterProxy cp1c(st, cdt, new osgIntrospection::StaticConverter<reflected_type *, const x *>); \
|
||||
osgIntrospection::ConverterProxy cp3(dt, st, new osgIntrospection::StaticConverter<x *, reflected_type *>); \
|
||||
osgIntrospection::ConverterProxy cp4(cdt, cst, new osgIntrospection::StaticConverter<const x *, const reflected_type *>); \
|
||||
osgIntrospection::ConverterProxy cp3c(dt, cst, new osgIntrospection::StaticConverter<x *, const reflected_type *>); \
|
||||
}
|
||||
|
||||
#define VirtualBaseType(x) \
|
||||
{ \
|
||||
addBaseType(typeof(x)); \
|
||||
const osgIntrospection::Type &st = typeof(reflected_type *); \
|
||||
const osgIntrospection::Type &cst = typeof(const reflected_type *); \
|
||||
const osgIntrospection::Type &dt = typeof(x *); \
|
||||
const osgIntrospection::Type &cdt = typeof(const x *); \
|
||||
osgIntrospection::ConverterProxy cp1(st, dt, new osgIntrospection::StaticConverter<reflected_type *, x *>); \
|
||||
osgIntrospection::ConverterProxy cp2(cst, cdt, new osgIntrospection::StaticConverter<const reflected_type *, const x *>); \
|
||||
osgIntrospection::ConverterProxy cp1c(st, cdt, new osgIntrospection::StaticConverter<reflected_type *, const x *>); \
|
||||
}
|
||||
|
||||
#define EnumLabel(x) addEnumLabel(x, #x, true);
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user