VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkXMLDataHeaderPrivate.h 00005 00006 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00007 All rights reserved. 00008 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00009 00010 This software is distributed WITHOUT ANY WARRANTY; without even 00011 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00012 PURPOSE. See the above copyright notice for more information. 00013 00014 =========================================================================*/ 00015 00016 #ifndef vtkXMLDataHeaderPrivate_DoNotInclude 00017 # error "do not include unless you know what you are doing" 00018 #endif 00019 00020 #ifndef __vtkXMLDataHeaderPrivate_h 00021 #define __vtkXMLDataHeaderPrivate_h 00022 00023 #include "vtkType.h" 00024 #include <vector> 00025 00026 // Abstract interface using type vtkTypeUInt64 to access an array 00027 // of either vtkTypeUInt32 or vtkTypeUInt64. Shared by vtkXMLWriter 00028 // and vtkXMLDataParser to write/read binary data headers. 00029 class vtkXMLDataHeader 00030 { 00031 public: 00032 virtual void Resize(size_t count) = 0; 00033 virtual vtkTypeUInt64 Get(size_t index) const = 0; 00034 virtual bool Set(size_t index, vtkTypeUInt64 value) = 0; 00035 virtual size_t WordSize() const = 0; 00036 virtual size_t WordCount() const = 0; 00037 virtual unsigned char* Data() = 0; 00038 size_t DataSize() const { return this->WordCount()*this->WordSize(); } 00039 virtual ~vtkXMLDataHeader() {} 00040 static inline vtkXMLDataHeader* New(int width, size_t count); 00041 }; 00042 00043 template <typename T> 00044 class vtkXMLDataHeaderImpl: public vtkXMLDataHeader 00045 { 00046 std::vector<T> Header; 00047 public: 00048 vtkXMLDataHeaderImpl(size_t n): Header(n, 0) {} 00049 virtual void Resize(size_t count) 00050 { this->Header.resize(count, 0); } 00051 virtual vtkTypeUInt64 Get(size_t index) const 00052 { return this->Header[index]; } 00053 virtual bool Set(size_t index, vtkTypeUInt64 value) 00054 { 00055 this->Header[index] = T(value); 00056 return vtkTypeUInt64(this->Header[index]) == value; 00057 } 00058 virtual size_t WordSize() const { return sizeof(T); } 00059 virtual size_t WordCount() const { return this->Header.size(); } 00060 virtual unsigned char* Data() 00061 { return reinterpret_cast<unsigned char*>(&this->Header[0]); } 00062 }; 00063 00064 vtkXMLDataHeader* vtkXMLDataHeader::New(int width, size_t count) 00065 { 00066 switch(width) 00067 { 00068 case 32: return new vtkXMLDataHeaderImpl<vtkTypeUInt32>(count); 00069 case 64: return new vtkXMLDataHeaderImpl<vtkTypeUInt64>(count); 00070 } 00071 return 0; 00072 } 00073 00074 #endif 00075 // VTK-HeaderTest-Exclude: vtkXMLDataHeaderPrivate.h