//C++ header - Open Scene Graph - Copyright (C) 1998-2002 Robert Osfield //Distributed under the terms of the GNU Library General Public License (LGPL) //as published by the Free Software Foundation. #ifndef OSG_ARRAY #define OSG_ARRAY 1 #include #include #include #include #include #include #include namespace osg { class ArrayVisitor; class SG_EXPORT Array : public Object { public: enum Type { ArrayType = 0, ByteArrayType = 1, ShortArrayType = 2, IntArrayType = 3, UByteArrayType = 4, UShortArrayType = 5, UIntArrayType = 6, UByte4ArrayType = 7, FloatArrayType = 8, Vec2ArrayType = 9, Vec3ArrayType = 10, Vec4ArrayType = 11 }; Array(Type arrayType=ArrayType,GLint dataSize=0,GLenum dataType=0): _arrayType(arrayType), _dataSize(dataSize), _dataType(dataType) {} Array(const Array& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY): Object(array,copyop), _arrayType(array._arrayType), _dataSize(array._dataSize), _dataType(array._dataType) {} virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast(obj)!=NULL; } virtual const char* libraryName() const { return "osg"; } virtual const char* className() const; virtual void accept(ArrayVisitor&) {} Type getType() const { return _arrayType; } GLint getDataSize() const { return _dataSize; } GLenum getDataType() const { return _dataType; } virtual const GLvoid* getDataPointer() const = 0; virtual unsigned int getNumElements() const = 0; protected: virtual ~Array() {} Type _arrayType; GLint _dataSize; GLenum _dataType; }; template class TemplateArray : public Array, public std::vector { public: TemplateArray() : Array(ARRAYTYPE,DataSize,DataType) {} TemplateArray(const TemplateArray& ta,const CopyOp& copyop=CopyOp::SHALLOW_COPY): Array(ta,copyop), std::vector(ta) {} TemplateArray(unsigned int no) : Array(ARRAYTYPE,DataSize,DataType), std::vector(no) {} TemplateArray(unsigned int no,T* ptr) : Array(ARRAYTYPE,DataSize,DataType), std::vector(ptr,ptr+no) {} template TemplateArray(InputIterator first,InputIterator last) : Array(ARRAYTYPE,DataSize,DataType), std::vector(first,last) {} virtual Object* cloneType() const { return osgNew TemplateArray(); } virtual Object* clone(const CopyOp& copyop) const { return osgNew TemplateArray(*this,copyop); } virtual void accept(ArrayVisitor& av) { av.apply(*this); } virtual const GLvoid* getDataPointer() const { if (!empty()) return &front(); else return 0; } virtual unsigned int getNumElements() const { return size(); } protected: virtual ~TemplateArray() {} }; typedef TemplateArray ByteArray; typedef TemplateArray ShortArray; typedef TemplateArray IntArray; typedef TemplateArray UByteArray; typedef TemplateArray UShortArray; typedef TemplateArray UIntArray; typedef TemplateArray UByte4Array; typedef TemplateArray FloatArray; typedef TemplateArray Vec2Array; typedef TemplateArray Vec3Array; typedef TemplateArray Vec4Array; class ArrayVisitor { public: ArrayVisitor() {} virtual void apply(Array&) {} virtual void apply(ByteArray&) {} virtual void apply(ShortArray&) {} virtual void apply(IntArray&) {} virtual void apply(UByteArray&) {} virtual void apply(UShortArray&) {} virtual void apply(UIntArray&) {} virtual void apply(UByte4Array&) {} virtual void apply(FloatArray&) {} virtual void apply(Vec2Array&) {} virtual void apply(Vec3Array&) {} virtual void apply(Vec4Array&) {} }; } #endif