From 1e9fb4ab030fe3cb4153dd5ceb6ee9aba002dd55 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 20 Jul 2005 19:42:59 +0000 Subject: [PATCH] From Marco Jez (with tweaks by Robert Osfield) : clean up of inheritance from std::vector<> classes --- include/osg/PrimitiveSet | 117 +++++++----------------- include/osgText/String | 93 +++++++++---------- src/osg/PrimitiveSet.cpp | 8 +- src/osgPlugins/ive/DrawArrayLengths.cpp | 2 +- src/osgText/String.cpp | 2 +- src/osgWrappers/osg/PrimitiveSet.cpp | 16 ++-- src/osgWrappers/osgText/String.cpp | 4 +- 7 files changed, 90 insertions(+), 152 deletions(-) diff --git a/include/osg/PrimitiveSet b/include/osg/PrimitiveSet index a473b0315..96cf012c1 100644 --- a/include/osg/PrimitiveSet +++ b/include/osg/PrimitiveSet @@ -71,69 +71,16 @@ public: virtual void end() = 0; }; -#ifndef _MSC_VER - -typedef std::vector VectorSizei; -typedef std::vector VectorUByte; -typedef std::vector VectorUShort; -typedef std::vector VectorUInt; - -#else // _MSC_VER - -// Following Vector wrapper classes are work arounds for MS linker problems with -// multiply implemented methods. -// -// An alternative, sent in by Clay Fowler, is workaround in VS to prevent the problem: -// the following changes have to be made to the project to make it compile, -// but NO changes are required to the actual source code: -// In the osgUtil project, go to the project properties, select the Linker/Command Line property page, -// and add the following switch in the "Additional Options" field: -// FORCE:MULTIPLE - -class VectorSizei: public std::vector { - typedef std::vector inherited; -public: - VectorSizei(): inherited() {} - explicit VectorSizei(size_type n): inherited(n) {} - VectorSizei(const VectorSizei ©): inherited(copy) {} - //VectorSizei(value_type *beg_, value_type *end_): inherited(beg_, end_) {} - template - VectorSizei(InputIterator beg_, InputIterator end_): inherited(beg_, end_) {} -}; - -class VectorUByte: public std::vector { - typedef std::vector inherited; -public: - VectorUByte(): inherited() {} - explicit VectorUByte(size_type n): inherited(n) {} - VectorUByte(const VectorUByte ©): inherited(copy) {} - //VectorUByte(value_type *beg_, value_type *end_): inherited(beg_, end_) {} - template - VectorUByte(InputIterator beg_, InputIterator end_): inherited(beg_, end_) {} -}; - -class VectorUShort: public std::vector { - typedef std::vector inherited; -public: - VectorUShort(): inherited() {} - explicit VectorUShort(size_type n): inherited(n) {} - VectorUShort(const VectorUShort ©): inherited(copy) {} - //VectorUShort(value_type *beg_, value_type *end_): inherited(beg_, end_) {} - template - VectorUShort(InputIterator beg_, InputIterator end_): inherited(beg_, end_) {} -}; - -class VectorUInt: public std::vector { - typedef std::vector inherited; -public: - VectorUInt(): inherited() {} - explicit VectorUInt(size_type n): inherited(n) {} - VectorUInt(const VectorUInt ©): inherited(copy) {} - //VectorUInt(value_type *beg_, value_type *end_): inherited(beg_, end_) {} - template - VectorUInt(InputIterator beg_, InputIterator end_): inherited(beg_, end_) {} -}; - +// export template instances that are used as base classes +#ifdef _MSC_VER +template class __declspec(dllexport) std::allocator; +template class __declspec(dllexport) std::vector >; +template class __declspec(dllexport) std::allocator; +template class __declspec(dllexport) std::vector >; +template class __declspec(dllexport) std::allocator; +template class __declspec(dllexport) std::vector >; +template class __declspec(dllexport) std::allocator; +template class __declspec(dllexport) std::vector >; #endif @@ -289,7 +236,7 @@ class OSG_EXPORT DrawArrays : public PrimitiveSet GLsizei _count; }; -class OSG_EXPORT DrawArrayLengths : public PrimitiveSet, public VectorSizei +class OSG_EXPORT DrawArrayLengths : public PrimitiveSet, public std::vector { public: @@ -299,22 +246,22 @@ class OSG_EXPORT DrawArrayLengths : public PrimitiveSet, public VectorSizei DrawArrayLengths(const DrawArrayLengths& dal,const CopyOp& copyop=CopyOp::SHALLOW_COPY): PrimitiveSet(dal,copyop), - VectorSizei(dal), + std::vector(dal), _first(dal._first) {} DrawArrayLengths(GLenum mode, GLint first, unsigned int no, GLsizei* ptr) : PrimitiveSet(DrawArrayLengthsPrimitiveType,mode), - VectorSizei(ptr,ptr+no), + std::vector(ptr,ptr+no), _first(first) {} DrawArrayLengths(GLenum mode,GLint first, unsigned int no) : PrimitiveSet(DrawArrayLengthsPrimitiveType,mode), - VectorSizei(no), + std::vector(no), _first(first) {} DrawArrayLengths(GLenum mode,GLint first) : PrimitiveSet(DrawArrayLengthsPrimitiveType,mode), - VectorSizei(), + std::vector(), _first(first) {} @@ -362,24 +309,26 @@ class OSG_EXPORT DrawArrayLengths : public PrimitiveSet, public VectorSizei GLint _first; }; -class OSG_EXPORT DrawElementsUByte : public PrimitiveSet, public VectorUByte +class OSG_EXPORT DrawElementsUByte : public PrimitiveSet, public std::vector { public: + + typedef std::vector vector_type; DrawElementsUByte(GLenum mode=0): PrimitiveSet(DrawElementsUBytePrimitiveType,mode) {} DrawElementsUByte(const DrawElementsUByte& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY): PrimitiveSet(array,copyop), - VectorUByte(array) {} + vector_type(array) {} DrawElementsUByte(GLenum mode,unsigned int no,GLubyte* ptr) : PrimitiveSet(DrawElementsUBytePrimitiveType,mode), - VectorUByte(ptr,ptr+no) {} + vector_type(ptr,ptr+no) {} DrawElementsUByte(GLenum mode,unsigned int no) : PrimitiveSet(DrawElementsUBytePrimitiveType,mode), - VectorUByte(no) {} + vector_type(no) {} virtual Object* cloneType() const { return new DrawElementsUByte(); } virtual Object* clone(const CopyOp& copyop) const { return new DrawElementsUByte(*this,copyop); } @@ -409,29 +358,31 @@ class OSG_EXPORT DrawElementsUByte : public PrimitiveSet, public VectorUByte }; -class OSG_EXPORT DrawElementsUShort : public PrimitiveSet, public VectorUShort +class OSG_EXPORT DrawElementsUShort : public PrimitiveSet, public std::vector { public: + typedef std::vector vector_type; + DrawElementsUShort(GLenum mode=0): PrimitiveSet(DrawElementsUShortPrimitiveType,mode) {} DrawElementsUShort(const DrawElementsUShort& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY): PrimitiveSet(array,copyop), - VectorUShort(array) {} + vector_type(array) {} DrawElementsUShort(GLenum mode,unsigned int no,GLushort* ptr) : PrimitiveSet(DrawElementsUShortPrimitiveType,mode), - VectorUShort(ptr,ptr+no) {} + vector_type(ptr,ptr+no) {} DrawElementsUShort(GLenum mode,unsigned int no) : PrimitiveSet(DrawElementsUShortPrimitiveType,mode), - VectorUShort(no) {} + vector_type(no) {} template DrawElementsUShort(GLenum mode, InputIterator first,InputIterator last) : PrimitiveSet(DrawElementsUShortPrimitiveType,mode), - VectorUShort(first,last) {} + vector_type(first,last) {} virtual Object* cloneType() const { return new DrawElementsUShort(); } virtual Object* clone(const CopyOp& copyop) const { return new DrawElementsUShort(*this,copyop); } @@ -460,29 +411,31 @@ class OSG_EXPORT DrawElementsUShort : public PrimitiveSet, public VectorUShort virtual ~DrawElementsUShort(); }; -class OSG_EXPORT DrawElementsUInt : public PrimitiveSet, public VectorUInt +class OSG_EXPORT DrawElementsUInt : public PrimitiveSet, public std::vector { public: + typedef std::vector vector_type; + DrawElementsUInt(GLenum mode=0): PrimitiveSet(DrawElementsUIntPrimitiveType,mode) {} DrawElementsUInt(const DrawElementsUInt& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY): PrimitiveSet(array,copyop), - VectorUInt(array) {} + vector_type(array) {} DrawElementsUInt(GLenum mode,unsigned int no,GLuint* ptr) : PrimitiveSet(DrawElementsUIntPrimitiveType,mode), - VectorUInt(ptr,ptr+no) {} + vector_type(ptr,ptr+no) {} DrawElementsUInt(GLenum mode,unsigned int no) : PrimitiveSet(DrawElementsUIntPrimitiveType,mode), - VectorUInt(no) {} + vector_type(no) {} template DrawElementsUInt(GLenum mode, InputIterator first,InputIterator last) : PrimitiveSet(DrawElementsUIntPrimitiveType,mode), - VectorUInt(first,last) {} + vector_type(first,last) {} virtual Object* cloneType() const { return new DrawElementsUInt(); } virtual Object* clone(const CopyOp& copyop) const { return new DrawElementsUInt(*this,copyop); } diff --git a/include/osgText/String b/include/osgText/String index 83636d113..9bbd20981 100644 --- a/include/osgText/String +++ b/include/osgText/String @@ -25,71 +25,60 @@ namespace osgText { class Text; -#ifndef _MSC_VER - -typedef std::vector VectorUInt; - -#else // _MSC_VER - -class VectorUInt: public std::vector { - typedef std::vector inherited; -public: - VectorUInt(): inherited() {} - explicit VectorUInt(size_type n): inherited(n) {} - VectorUInt(const VectorUInt ©): inherited(copy) {} - //VectorUInt(value_type *beg_, value_type *end_): inherited(beg_, end_) {} - template - VectorUInt(InputIterator beg_, InputIterator end_): inherited(beg_, end_) {} -}; - +// export template instances that are used as base classes +#ifdef _MSC_VER +template class __declspec(dllexport) std::allocator; +template class __declspec(dllexport) std::vector >; #endif -class OSGTEXT_EXPORT String : public osg::Referenced, public VectorUInt +class OSGTEXT_EXPORT String : public osg::Referenced, public std::vector { -public: + public: - /** - * Types of string encodings supported - */ - enum Encoding - { - ENCODING_UNDEFINED, /// not using Unicode - ENCODING_ASCII = ENCODING_UNDEFINED,/// unsigned char ASCII - ENCODING_UTF8, /// 8-bit unicode transformation format - ENCODING_UTF16, /// 16-bit signature - ENCODING_UTF16_BE, /// 16-bit big-endian - ENCODING_UTF16_LE, /// 16-bit little-endian - ENCODING_UTF32, /// 32-bit signature - ENCODING_UTF32_BE, /// 32-bit big-endian - ENCODING_UTF32_LE, /// 32-bit little-endian - ENCODING_SIGNATURE /// detect encoding from signature - }; + typedef std::vector vector_type; + + /** + * Types of string encodings supported + */ + enum Encoding + { + ENCODING_UNDEFINED, /// not using Unicode + ENCODING_ASCII = ENCODING_UNDEFINED,/// unsigned char ASCII + ENCODING_UTF8, /// 8-bit unicode transformation format + ENCODING_UTF16, /// 16-bit signature + ENCODING_UTF16_BE, /// 16-bit big-endian + ENCODING_UTF16_LE, /// 16-bit little-endian + ENCODING_UTF32, /// 32-bit signature + ENCODING_UTF32_BE, /// 32-bit big-endian + ENCODING_UTF32_LE, /// 32-bit little-endian + ENCODING_SIGNATURE /// detect encoding from signature + }; - String() {} - String(const String& str); - String(const std::string& str) { set(str); } - String(const wchar_t* text) { set(text); } - String(const std::string& text,Encoding encoding) { set(text,encoding); } + String() {} + String(const String& str); + String(const std::string& str) { set(str); } + String(const wchar_t* text) { set(text); } + String(const std::string& text,Encoding encoding) { set(text,encoding); } - virtual ~String() {} // public temporily while osgText is still in flux. + virtual ~String() {} // public temporily while osgText is still in flux. - String& operator = (const String& str); + String& operator = (const String& str); - void set(const std::string& str); + void set(const std::string& str); - /** Set the text using a wchar_t string, - * which is converted to an internal TextString.*/ - void set(const wchar_t* text); + /** Set the text using a wchar_t string, + * which is converted to an internal TextString.*/ + void set(const wchar_t* text); - /** Set the text using a Unicode encoded std::string, which is converted to an internal TextString. - * The encoding parameter specificies which Unicode encodeding is used in the std::string. */ - void set(const std::string& text,Encoding encoding); + /** Set the text using a Unicode encoded std::string, which is converted to an internal TextString. + * The encoding parameter specificies which Unicode encodeding is used in the std::string. */ + void set(const std::string& text,Encoding encoding); - /** returns a UTF8 encoded version of this osgText::String.*/ - std::string createUTF8EncodedString() const; + /** returns a UTF8 encoded version of this osgText::String.*/ + std::string createUTF8EncodedString() const; -protected: + protected: }; diff --git a/src/osg/PrimitiveSet.cpp b/src/osg/PrimitiveSet.cpp index 31b2e0220..67e059e1b 100644 --- a/src/osg/PrimitiveSet.cpp +++ b/src/osg/PrimitiveSet.cpp @@ -34,7 +34,7 @@ void DrawArrays::accept(PrimitiveIndexFunctor& functor) const void DrawArrayLengths::draw(State&, bool) const { GLint first = _first; - for(VectorSizei::const_iterator itr=begin(); + for(vector_type::const_iterator itr=begin(); itr!=end(); ++itr) { @@ -46,7 +46,7 @@ void DrawArrayLengths::draw(State&, bool) const void DrawArrayLengths::accept(PrimitiveFunctor& functor) const { GLint first = _first; - for(VectorSizei::const_iterator itr=begin(); + for(vector_type::const_iterator itr=begin(); itr!=end(); ++itr) { @@ -58,7 +58,7 @@ void DrawArrayLengths::accept(PrimitiveFunctor& functor) const void DrawArrayLengths::accept(PrimitiveIndexFunctor& functor) const { GLint first = _first; - for(VectorSizei::const_iterator itr=begin(); + for(vector_type::const_iterator itr=begin(); itr!=end(); ++itr) { @@ -70,7 +70,7 @@ void DrawArrayLengths::accept(PrimitiveIndexFunctor& functor) const unsigned int DrawArrayLengths::getNumIndices() const { unsigned int count = 0; - for(VectorSizei::const_iterator itr=begin(); + for(vector_type::const_iterator itr=begin(); itr!=end(); ++itr) { diff --git a/src/osgPlugins/ive/DrawArrayLengths.cpp b/src/osgPlugins/ive/DrawArrayLengths.cpp index cdbde3dcf..2b6582f7b 100644 --- a/src/osgPlugins/ive/DrawArrayLengths.cpp +++ b/src/osgPlugins/ive/DrawArrayLengths.cpp @@ -35,7 +35,7 @@ void DrawArrayLengths::write(DataOutputStream* out){ // Write array length and its elements. out->writeInt(size()); for(unsigned int i=0; iwriteInt(((osg::VectorSizei)(*this))[i]); + out->writeInt(((*this))[i]); } } diff --git a/src/osgText/String.cpp b/src/osgText/String.cpp index 2fe9d43fa..3e28cd2a1 100644 --- a/src/osgText/String.cpp +++ b/src/osgText/String.cpp @@ -237,7 +237,7 @@ unsigned int getNextCharacter(look_ahead_iterator& charString,String::Encoding e String::String(const String& str): osg::Referenced(), - VectorUInt(str) + vector_type(str) { } diff --git a/src/osgWrappers/osg/PrimitiveSet.cpp b/src/osgWrappers/osg/PrimitiveSet.cpp index 0e9c320ea..62060ec49 100644 --- a/src/osgWrappers/osg/PrimitiveSet.cpp +++ b/src/osgWrappers/osg/PrimitiveSet.cpp @@ -74,6 +74,8 @@ BEGIN_OBJECT_REFLECTOR(osg::DrawArrays) I_Property(GLint, First); END_REFLECTOR +TYPE_NAME_ALIAS(std::vector< GLubyte >, osg::DrawElementsUByte::vector_type); + BEGIN_OBJECT_REFLECTOR(osg::DrawElementsUByte) I_BaseType(osg::PrimitiveSet); I_ConstructorWithDefaults1(IN, GLenum, mode, 0); @@ -98,6 +100,8 @@ BEGIN_OBJECT_REFLECTOR(osg::DrawElementsUByte) I_ReadOnlyProperty(unsigned int, TotalDataSize); END_REFLECTOR +TYPE_NAME_ALIAS(std::vector< GLuint >, osg::DrawElementsUInt::vector_type); + BEGIN_OBJECT_REFLECTOR(osg::DrawElementsUInt) I_BaseType(osg::PrimitiveSet); I_ConstructorWithDefaults1(IN, GLenum, mode, 0); @@ -122,6 +126,8 @@ BEGIN_OBJECT_REFLECTOR(osg::DrawElementsUInt) I_ReadOnlyProperty(unsigned int, TotalDataSize); END_REFLECTOR +TYPE_NAME_ALIAS(std::vector< GLushort >, osg::DrawElementsUShort::vector_type); + BEGIN_OBJECT_REFLECTOR(osg::DrawElementsUShort) I_BaseType(osg::PrimitiveSet); I_ConstructorWithDefaults1(IN, GLenum, mode, 0); @@ -231,16 +237,6 @@ BEGIN_ABSTRACT_OBJECT_REFLECTOR(osg::PrimitiveSet) I_ReadOnlyProperty(osg::PrimitiveSet::Type, Type); END_REFLECTOR -TYPE_NAME_ALIAS(std::vector< GLsizei >, osg::VectorSizei); - -TYPE_NAME_ALIAS(std::vector< GLubyte >, osg::VectorUByte); - -TYPE_NAME_ALIAS(std::vector< GLushort >, osg::VectorUShort); - -TYPE_NAME_ALIAS(std::vector< GLuint >, osg::VectorUInt); - -STD_VECTOR_REFLECTOR(std::vector< GLsizei >); - STD_VECTOR_REFLECTOR(std::vector< GLubyte >); STD_VECTOR_REFLECTOR(std::vector< GLuint >); diff --git a/src/osgWrappers/osgText/String.cpp b/src/osgWrappers/osgText/String.cpp index 5f8ec084b..3ae4d327a 100644 --- a/src/osgWrappers/osgText/String.cpp +++ b/src/osgWrappers/osgText/String.cpp @@ -19,6 +19,8 @@ #undef OUT #endif +TYPE_NAME_ALIAS(std::vector< unsigned int >, osgText::String::vector_type); + BEGIN_ENUM_REFLECTOR(osgText::String::Encoding) I_EnumLabel(osgText::String::ENCODING_UNDEFINED); I_EnumLabel(osgText::String::ENCODING_ASCII); @@ -46,5 +48,3 @@ BEGIN_OBJECT_REFLECTOR(osgText::String) I_WriteOnlyProperty(const wchar_t *, ); END_REFLECTOR -TYPE_NAME_ALIAS(std::vector< unsigned int >, osgText::VectorUInt); -