From Marco Jez (with tweaks by Robert Osfield) : clean up of inheritance from std::vector<> classes
This commit is contained in:
parent
b9e651baf1
commit
1e9fb4ab03
@ -71,69 +71,16 @@ public:
|
||||
virtual void end() = 0;
|
||||
};
|
||||
|
||||
#ifndef _MSC_VER
|
||||
|
||||
typedef std::vector<GLsizei> VectorSizei;
|
||||
typedef std::vector<GLubyte> VectorUByte;
|
||||
typedef std::vector<GLushort> VectorUShort;
|
||||
typedef std::vector<GLuint> 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<GLsizei> {
|
||||
typedef std::vector<value_type> 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<class InputIterator>
|
||||
VectorSizei(InputIterator beg_, InputIterator end_): inherited(beg_, end_) {}
|
||||
};
|
||||
|
||||
class VectorUByte: public std::vector<GLubyte> {
|
||||
typedef std::vector<value_type> 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<class InputIterator>
|
||||
VectorUByte(InputIterator beg_, InputIterator end_): inherited(beg_, end_) {}
|
||||
};
|
||||
|
||||
class VectorUShort: public std::vector<GLushort> {
|
||||
typedef std::vector<value_type> 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<class InputIterator>
|
||||
VectorUShort(InputIterator beg_, InputIterator end_): inherited(beg_, end_) {}
|
||||
};
|
||||
|
||||
class VectorUInt: public std::vector<GLuint> {
|
||||
typedef std::vector<value_type> 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<class InputIterator>
|
||||
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<GLsizei>;
|
||||
template class __declspec(dllexport) std::vector<GLsizei, std::allocator<GLsizei> >;
|
||||
template class __declspec(dllexport) std::allocator<GLubyte>;
|
||||
template class __declspec(dllexport) std::vector<GLubyte, std::allocator<GLubyte> >;
|
||||
template class __declspec(dllexport) std::allocator<GLushort>;
|
||||
template class __declspec(dllexport) std::vector<GLushort, std::allocator<GLushort> >;
|
||||
template class __declspec(dllexport) std::allocator<GLuint>;
|
||||
template class __declspec(dllexport) std::vector<GLuint, std::allocator<GLuint> >;
|
||||
#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<GLsizei>
|
||||
{
|
||||
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<GLsizei>(dal),
|
||||
_first(dal._first) {}
|
||||
|
||||
DrawArrayLengths(GLenum mode, GLint first, unsigned int no, GLsizei* ptr) :
|
||||
PrimitiveSet(DrawArrayLengthsPrimitiveType,mode),
|
||||
VectorSizei(ptr,ptr+no),
|
||||
std::vector<GLsizei>(ptr,ptr+no),
|
||||
_first(first) {}
|
||||
|
||||
DrawArrayLengths(GLenum mode,GLint first, unsigned int no) :
|
||||
PrimitiveSet(DrawArrayLengthsPrimitiveType,mode),
|
||||
VectorSizei(no),
|
||||
std::vector<GLsizei>(no),
|
||||
_first(first) {}
|
||||
|
||||
DrawArrayLengths(GLenum mode,GLint first) :
|
||||
PrimitiveSet(DrawArrayLengthsPrimitiveType,mode),
|
||||
VectorSizei(),
|
||||
std::vector<GLsizei>(),
|
||||
_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<GLubyte>
|
||||
{
|
||||
public:
|
||||
|
||||
typedef std::vector<GLubyte> 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<GLushort>
|
||||
{
|
||||
public:
|
||||
|
||||
typedef std::vector<GLushort> 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 <class InputIterator>
|
||||
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<GLuint>
|
||||
{
|
||||
public:
|
||||
|
||||
typedef std::vector<GLuint> 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 <class InputIterator>
|
||||
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); }
|
||||
|
@ -25,71 +25,60 @@ namespace osgText {
|
||||
|
||||
class Text;
|
||||
|
||||
#ifndef _MSC_VER
|
||||
|
||||
typedef std::vector<unsigned int> VectorUInt;
|
||||
|
||||
#else // _MSC_VER
|
||||
|
||||
class VectorUInt: public std::vector<unsigned int> {
|
||||
typedef std::vector<value_type> 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<class InputIterator>
|
||||
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<unsigned int>;
|
||||
template class __declspec(dllexport) std::vector<unsigned int, std::allocator<unsigned int> >;
|
||||
#endif
|
||||
|
||||
class OSGTEXT_EXPORT String : public osg::Referenced, public VectorUInt
|
||||
class OSGTEXT_EXPORT String : public osg::Referenced, public std::vector<unsigned int>
|
||||
{
|
||||
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<unsigned int> 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:
|
||||
|
||||
};
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -35,7 +35,7 @@ void DrawArrayLengths::write(DataOutputStream* out){
|
||||
// Write array length and its elements.
|
||||
out->writeInt(size());
|
||||
for(unsigned int i=0; i<size(); i++){
|
||||
out->writeInt(((osg::VectorSizei)(*this))[i]);
|
||||
out->writeInt(((*this))[i]);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -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 >);
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user