From eb99df894a8ceed0cd0e4d06443fbac4f2d7353f Mon Sep 17 00:00:00 2001 From: Chris White Date: Fri, 16 Jun 2017 09:58:32 -0400 Subject: [PATCH] Make Array::className() support all Array::Type's Array::className() had fallen out of date with respect to Array::Type. This commit updates it, and adds documentation and a debug message to serve as a reminder for future additions of values to Array::Type. --- include/osg/Array | 18 ++++++++++++++++-- src/osg/Array.cpp | 12 ++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/include/osg/Array b/include/osg/Array index d7ae6609c..7155ddeee 100644 --- a/include/osg/Array +++ b/include/osg/Array @@ -62,6 +62,7 @@ class OSG_EXPORT Array : public BufferData public: + /// The type of data stored in this array. enum Type { ArrayType = 0, @@ -115,9 +116,16 @@ class OSG_EXPORT Array : public BufferData QuatArrayType = 35, UInt64ArrayType = 36, - Int64ArrayType = 37 + Int64ArrayType = 37, + + LastArrayType = 37 + // If new array types are added, update this and + // update Array::className() in src/osg/Array.cpp. + // Array::Type values are from ArrayType to + // LastArrayType, inclusive. }; + /// The scope of applicability of the values in this array enum Binding { BIND_UNDEFINED=-1, @@ -146,6 +154,9 @@ class OSG_EXPORT Array : public BufferData virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast(obj)!=NULL; } virtual const char* libraryName() const { return "osg"; } + + /// Get the class name of this array. Defined in src/osg/Array.cpp + /// for all concrete array types listed below --- doesn't use traits. virtual const char* className() const; virtual void accept(ArrayVisitor&) = 0; @@ -226,6 +237,7 @@ inline osg::Array::Binding getBinding(const osg::Array* array) { return array ? inline bool getNormalize(const osg::Array* array) { return array ? array->getNormalize() : false; } +/// A concrete array holding elements of type T. template class TemplateArray : public Array, public MixinVector { @@ -396,6 +408,8 @@ class TemplateIndexArray : public IndexArray, public MixinVector virtual ~TemplateIndexArray() {} }; +// The predefined array types + typedef TemplateIndexArray ByteArray; typedef TemplateIndexArray ShortArray; typedef TemplateIndexArray IntArray; @@ -407,7 +421,6 @@ typedef TemplateIndexArray typedef TemplateArray FloatArray; typedef TemplateArray DoubleArray; - typedef TemplateArray Vec2bArray; typedef TemplateArray Vec3bArray; typedef TemplateArray Vec4bArray; @@ -447,6 +460,7 @@ typedef TemplateArray typedef TemplateIndexArray UInt64Array; typedef TemplateIndexArray Int64Array; + class ArrayVisitor { public: diff --git a/src/osg/Array.cpp b/src/osg/Array.cpp index 17bd9249f..3e45276f7 100644 --- a/src/osg/Array.cpp +++ b/src/osg/Array.cpp @@ -11,6 +11,7 @@ * OpenSceneGraph Public License for more details. */ #include +#include using namespace osg; @@ -62,13 +63,20 @@ static const char* s_ArrayNames[] = "MatrixArray", //33 "MatrixdArray", //34 + + "QuatArray", //35 + + "UInt64Array", //36 + "Int64Array", //37 }; const char* Array::className() const { - if (_arrayType>=ArrayType && _arrayType<=Vec4dArrayType) + if (_arrayType>=ArrayType && _arrayType<=LastArrayType) return s_ArrayNames[_arrayType]; - else + else { + OSG_DEBUG << "Array::className(): Unknown array type " << _arrayType << std::endl; return "UnknownArray"; + } }