From Marco Jez, hack/fix for VS compile/link problems related to STL containers.

This commit is contained in:
Robert Osfield
2005-12-02 00:25:40 +00:00
parent 784574670e
commit 8d8229cc05
6 changed files with 127 additions and 47 deletions

View File

@@ -42,33 +42,6 @@
# define OSG_EXPORT
#endif
// export template instances for basic types
#if (_MSC_VER >= 1300) && !defined( OSG_LIBRARY_STATIC )
#include <vector>
#if defined( OSG_LIBRARY )
template class __declspec(dllexport) std::allocator<int>; // GLsizei
template class __declspec(dllexport) std::vector<int, std::allocator<int> >; // GLsizei
template class __declspec(dllexport) std::allocator<unsigned char>; // GLubyte
template class __declspec(dllexport) std::vector<unsigned char, std::allocator<unsigned char> >; // GLubyte
template class __declspec(dllexport) std::allocator<unsigned short>; // GLushort
template class __declspec(dllexport) std::vector<unsigned short, std::allocator<unsigned short> >; // GLushort
template class __declspec(dllexport) std::allocator<unsigned int>; // GLuint
template class __declspec(dllexport) std::vector<unsigned int, std::allocator<unsigned int> >; // GLuint
#else
#pragma warning ( push )
#pragma warning ( disable : 4231 )
extern template class __declspec(dllimport) std::allocator<int>; // GLsizei
extern template class __declspec(dllimport) std::vector<int, std::allocator<int> >; // GLsizei
extern template class __declspec(dllimport) std::allocator<unsigned char>; // GLubyte
extern template class __declspec(dllimport) std::vector<unsigned char, std::allocator<unsigned char> >; // GLubyte
extern template class __declspec(dllimport) std::allocator<unsigned short>; // GLushort
extern template class __declspec(dllimport) std::vector<unsigned short, std::allocator<unsigned short> >; // GLushort
extern template class __declspec(dllimport) std::allocator<unsigned int>; // GLuint
extern template class __declspec(dllimport) std::vector<unsigned int, std::allocator<unsigned int> >; // GLuint
#pragma warning ( pop )
#endif
#endif
// set up define for whether member templates are supported by VisualStudio compilers.
#ifdef _MSC_VER
# if (_MSC_VER >= 1300)

View File

@@ -25,6 +25,60 @@
namespace osg {
// ******************************** HACK **********************************
// Following classes are needed by VC++ in order to avoid linking errors due
// to multiply defined member functions. Classes that would normally derive
// from std::vector<T> (and that are exported via OSG_EXPORT) should derive
// from one of these classes instead.
//
// NOTE: to keep the interface consistent and avoid breaking introspection
// wrappers, this hack was deliberately made not Microsoft-specific
// even though other compilers like GCC actually don't need that.
//
// Marco Jez, Dec 2005
class VectorGLsizei: public std::vector<GLsizei>
{
typedef std::vector<value_type> vector_type;
public:
VectorGLsizei(): vector_type() {}
VectorGLsizei(const VectorGLsizei &copy): vector_type(copy) {}
VectorGLsizei(GLsizei* beg, GLsizei* end): vector_type(beg, end) {}
explicit VectorGLsizei(VectorGLsizei::size_type n): vector_type(n) {}
};
class VectorGLubyte: public std::vector<GLubyte>
{
typedef std::vector<value_type> vector_type;
public:
VectorGLubyte(): vector_type() {}
VectorGLubyte(const VectorGLubyte &copy): vector_type(copy) {}
VectorGLubyte(GLubyte* beg, GLubyte* end): vector_type(beg, end) {}
explicit VectorGLubyte(VectorGLubyte::size_type n): vector_type(n) {}
};
class VectorGLushort: public std::vector<GLushort>
{
typedef std::vector<value_type> vector_type;
public:
VectorGLushort(): vector_type() {}
VectorGLushort(const VectorGLushort &copy): vector_type(copy) {}
VectorGLushort(GLushort* beg, GLushort* end): vector_type(beg, end) {}
explicit VectorGLushort(VectorGLushort::size_type n): vector_type(n) {}
};
class VectorGLuint: public std::vector<GLuint>
{
typedef std::vector<value_type> vector_type;
public:
VectorGLuint(): vector_type() {}
VectorGLuint(const VectorGLuint &copy): vector_type(copy) {}
VectorGLuint(GLuint* beg, GLuint* end): vector_type(beg, end) {}
explicit VectorGLuint(VectorGLuint::size_type n): vector_type(n) {}
};
// **************************************************************************
class State;
class PrimitiveFunctor
{
@@ -252,11 +306,11 @@ class OSG_EXPORT DrawArrays : public PrimitiveSet
GLsizei _count;
};
class OSG_EXPORT DrawArrayLengths : public PrimitiveSet, public std::vector<GLsizei>
class OSG_EXPORT DrawArrayLengths : public PrimitiveSet, public VectorGLsizei
{
public:
typedef std::vector<GLsizei> vector_type;
typedef VectorGLsizei vector_type;
DrawArrayLengths(GLenum mode=0):
PrimitiveSet(DrawArrayLengthsPrimitiveType,mode),
@@ -327,11 +381,11 @@ class OSG_EXPORT DrawArrayLengths : public PrimitiveSet, public std::vector<GLsi
GLint _first;
};
class OSG_EXPORT DrawElementsUByte : public PrimitiveSet, public std::vector<GLubyte>
class OSG_EXPORT DrawElementsUByte : public PrimitiveSet, public VectorGLubyte
{
public:
typedef std::vector<GLubyte> vector_type;
typedef VectorGLubyte vector_type;
DrawElementsUByte(GLenum mode=0):
PrimitiveSet(DrawElementsUBytePrimitiveType,mode) {}
@@ -378,11 +432,11 @@ class OSG_EXPORT DrawElementsUByte : public PrimitiveSet, public std::vector<GLu
};
class OSG_EXPORT DrawElementsUShort : public PrimitiveSet, public std::vector<GLushort>
class OSG_EXPORT DrawElementsUShort : public PrimitiveSet, public VectorGLushort
{
public:
typedef std::vector<GLushort> vector_type;
typedef VectorGLushort vector_type;
DrawElementsUShort(GLenum mode=0):
PrimitiveSet(DrawElementsUShortPrimitiveType,mode) {}
@@ -432,11 +486,11 @@ class OSG_EXPORT DrawElementsUShort : public PrimitiveSet, public std::vector<GL
mutable GLObjectList _vboList;
};
class OSG_EXPORT DrawElementsUInt : public PrimitiveSet, public std::vector<GLuint>
class OSG_EXPORT DrawElementsUInt : public PrimitiveSet, public VectorGLuint
{
public:
typedef std::vector<GLuint> vector_type;
typedef VectorGLuint vector_type;
DrawElementsUInt(GLenum mode=0):
PrimitiveSet(DrawElementsUIntPrimitiveType,mode) {}

View File

@@ -23,13 +23,29 @@
namespace osgText {
// ******************************** HACK **********************************
// Following class is needed to work around a DLL export problem. See file
// include/osg/PrimitiveSet for details.
class VectorUInt: public std::vector<unsigned int>
{
typedef std::vector<value_type> vector_type;
public:
VectorUInt(): vector_type() {}
VectorUInt(const VectorUInt &copy): vector_type(copy) {}
VectorUInt(unsigned int* beg, unsigned int* end): vector_type(beg, end) {}
explicit VectorUInt(VectorUInt::size_type n): vector_type(n) {}
};
// **************************************************************************
class Text;
class OSGTEXT_EXPORT String : public osg::Referenced, public std::vector<unsigned int>
class OSGTEXT_EXPORT String : public osg::Referenced, public VectorUInt
{
public:
typedef std::vector<unsigned int> vector_type;
typedef VectorUInt vector_type;
/**
* Types of string encodings supported

View File

@@ -595,7 +595,7 @@ bool CullVisitor::updateCalculatedNearFar(const osg::Matrix& matrix,const osg::D
}
}
if (d_far<=0.0) // gwm if ==0 extends purely behind eye, forces far to 0 get invalid projection matrix (ratio near:far=inf)
if (d_far<0.0)
{
// whole object behind the eye point so discard
return false;

View File

@@ -25,10 +25,11 @@
#undef OUT
#endif
TYPE_NAME_ALIAS(std::vector< GLsizei >, osg::DrawArrayLengths::vector_type);
TYPE_NAME_ALIAS(osg::VectorGLsizei, osg::DrawArrayLengths::vector_type);
BEGIN_OBJECT_REFLECTOR(osg::DrawArrayLengths)
I_BaseType(osg::PrimitiveSet);
I_BaseType(osg::VectorGLsizei);
I_ConstructorWithDefaults1(IN, GLenum, mode, 0);
I_ConstructorWithDefaults2(IN, const osg::DrawArrayLengths &, dal, , IN, const osg::CopyOp &, copyop, osg::CopyOp::SHALLOW_COPY);
I_Constructor4(IN, GLenum, mode, IN, GLint, first, IN, unsigned int, no, IN, GLsizei *, ptr);
@@ -76,10 +77,11 @@ BEGIN_OBJECT_REFLECTOR(osg::DrawArrays)
I_Property(GLint, First);
END_REFLECTOR
TYPE_NAME_ALIAS(std::vector< GLubyte >, osg::DrawElementsUByte::vector_type);
TYPE_NAME_ALIAS(osg::VectorGLubyte, osg::DrawElementsUByte::vector_type);
BEGIN_OBJECT_REFLECTOR(osg::DrawElementsUByte)
I_BaseType(osg::PrimitiveSet);
I_BaseType(osg::VectorGLubyte);
I_ConstructorWithDefaults1(IN, GLenum, mode, 0);
I_ConstructorWithDefaults2(IN, const osg::DrawElementsUByte &, array, , IN, const osg::CopyOp &, copyop, osg::CopyOp::SHALLOW_COPY);
I_Constructor3(IN, GLenum, mode, IN, unsigned int, no, IN, GLubyte *, ptr);
@@ -103,10 +105,11 @@ BEGIN_OBJECT_REFLECTOR(osg::DrawElementsUByte)
I_ReadOnlyProperty(unsigned int, TotalDataSize);
END_REFLECTOR
TYPE_NAME_ALIAS(std::vector< GLuint >, osg::DrawElementsUInt::vector_type);
TYPE_NAME_ALIAS(osg::VectorGLuint, osg::DrawElementsUInt::vector_type);
BEGIN_OBJECT_REFLECTOR(osg::DrawElementsUInt)
I_BaseType(osg::PrimitiveSet);
I_BaseType(osg::VectorGLuint);
I_ConstructorWithDefaults1(IN, GLenum, mode, 0);
I_ConstructorWithDefaults2(IN, const osg::DrawElementsUInt &, array, , IN, const osg::CopyOp &, copyop, osg::CopyOp::SHALLOW_COPY);
I_Constructor3(IN, GLenum, mode, IN, unsigned int, no, IN, GLuint *, ptr);
@@ -130,10 +133,11 @@ BEGIN_OBJECT_REFLECTOR(osg::DrawElementsUInt)
I_ReadOnlyProperty(unsigned int, TotalDataSize);
END_REFLECTOR
TYPE_NAME_ALIAS(std::vector< GLushort >, osg::DrawElementsUShort::vector_type);
TYPE_NAME_ALIAS(osg::VectorGLushort, osg::DrawElementsUShort::vector_type);
BEGIN_OBJECT_REFLECTOR(osg::DrawElementsUShort)
I_BaseType(osg::PrimitiveSet);
I_BaseType(osg::VectorGLushort);
I_ConstructorWithDefaults1(IN, GLenum, mode, 0);
I_ConstructorWithDefaults2(IN, const osg::DrawElementsUShort &, array, , IN, const osg::CopyOp &, copyop, osg::CopyOp::SHALLOW_COPY);
I_Constructor3(IN, GLenum, mode, IN, unsigned int, no, IN, GLushort *, ptr);
@@ -243,11 +247,35 @@ BEGIN_ABSTRACT_OBJECT_REFLECTOR(osg::PrimitiveSet)
I_ReadOnlyProperty(osg::PrimitiveSet::Type, Type);
END_REFLECTOR
STD_VECTOR_REFLECTOR(std::vector< GLsizei >);
BEGIN_OBJECT_REFLECTOR(osg::VectorGLsizei)
I_BaseType(std::vector<GLsizei>);
I_Constructor0();
I_Constructor1(IN, const osg::VectorGLsizei &, copy);
I_Constructor2(IN, GLsizei *, beg, IN, GLsizei *, end);
I_Constructor1(IN, osg::VectorGLsizei::size_type, n);
END_REFLECTOR
STD_VECTOR_REFLECTOR(std::vector< GLubyte >);
BEGIN_OBJECT_REFLECTOR(osg::VectorGLubyte)
I_BaseType(std::vector<GLubyte>);
I_Constructor0();
I_Constructor1(IN, const osg::VectorGLubyte &, copy);
I_Constructor2(IN, GLubyte *, beg, IN, GLubyte *, end);
I_Constructor1(IN, osg::VectorGLubyte::size_type, n);
END_REFLECTOR
STD_VECTOR_REFLECTOR(std::vector< GLuint >);
BEGIN_OBJECT_REFLECTOR(osg::VectorGLuint)
I_BaseType(std::vector<GLuint>);
I_Constructor0();
I_Constructor1(IN, const osg::VectorGLuint &, copy);
I_Constructor2(IN, GLuint *, beg, IN, GLuint *, end);
I_Constructor1(IN, osg::VectorGLuint::size_type, n);
END_REFLECTOR
STD_VECTOR_REFLECTOR(std::vector< GLushort >);
BEGIN_OBJECT_REFLECTOR(osg::VectorGLushort)
I_BaseType(std::vector<GLushort>);
I_Constructor0();
I_Constructor1(IN, const osg::VectorGLushort &, copy);
I_Constructor2(IN, GLushort *, beg, IN, GLushort *, end);
I_Constructor1(IN, osg::VectorGLushort::size_type, n);
END_REFLECTOR

View File

@@ -19,7 +19,7 @@
#undef OUT
#endif
TYPE_NAME_ALIAS(std::vector< unsigned int >, osgText::String::vector_type);
TYPE_NAME_ALIAS(osgText::VectorUInt, osgText::String::vector_type);
BEGIN_ENUM_REFLECTOR(osgText::String::Encoding)
I_EnumLabel(osgText::String::ENCODING_UNDEFINED);
@@ -36,6 +36,7 @@ END_REFLECTOR
BEGIN_OBJECT_REFLECTOR(osgText::String)
I_BaseType(osg::Referenced);
I_BaseType(osgText::VectorUInt);
I_Constructor0();
I_Constructor1(IN, const osgText::String &, str);
I_Constructor1(IN, const std::string &, str);
@@ -48,3 +49,11 @@ BEGIN_OBJECT_REFLECTOR(osgText::String)
I_WriteOnlyProperty(const wchar_t *, );
END_REFLECTOR
BEGIN_OBJECT_REFLECTOR(osgText::VectorUInt)
I_BaseType(std::vector<unsigned int>);
I_Constructor0();
I_Constructor1(IN, const osgText::VectorUInt &, copy);
I_Constructor2(IN, unsigned int *, beg, IN, unsigned int *, end);
I_Constructor1(IN, osgText::VectorUInt::size_type, n);
END_REFLECTOR