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