IGSTK
|
00001 /*========================================================================= 00002 00003 Program: Image Guided Surgery Software Toolkit 00004 Module: $RCSfile: igstkBinaryData.h,v $ 00005 Language: C++ 00006 Date: $Date: 2008-02-11 01:41:50 $ 00007 Version: $Revision: 1.9 $ 00008 00009 Copyright (c) ISC Insight Software Consortium. All rights reserved. 00010 See IGSTKCopyright.txt or http://www.igstk.org/copyright.htm for details. 00011 00012 This software is distributed WITHOUT ANY WARRANTY; without even 00013 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00014 PURPOSE. See the above copyright notices for more information. 00015 00016 =========================================================================*/ 00017 #ifndef __igstkBinaryData_h 00018 #define __igstkBinaryData_h 00019 00020 00021 #include <itkObject.h> 00022 #include <vector> 00023 #include <string> 00024 00025 namespace igstk 00026 { 00027 00038 class BinaryData 00039 { 00040 public: 00041 00043 typedef std::vector<unsigned char> ContainerType; 00044 00045 public: 00046 00048 BinaryData(); 00049 00051 BinaryData(const char* encodedString); 00052 00054 BinaryData(const std::string& encodedString); 00055 00057 virtual ~BinaryData(); 00058 00060 void SetSize(unsigned int size); 00061 00063 unsigned int GetSize() const; 00064 00066 const ContainerType& GetData() const { return this->m_Data; } 00067 00069 ContainerType& GetData() { return this->m_Data; } 00070 00072 void CopyFrom(unsigned char* inputBegin, unsigned int inputLength); 00073 00075 void CopyTo(unsigned char* output) const; 00076 00078 void Append(unsigned char byte); 00079 00081 void Append(const unsigned char* inputBegin, unsigned int inputLength); 00082 00084 const BinaryData & operator=( const BinaryData & inputBinaryData ); 00085 00087 bool operator==( const BinaryData & inputBinaryData ) const; 00088 00090 bool operator!=( const BinaryData & inputBinaryData ) const; 00091 00093 bool operator<( const BinaryData & inputBinaryData ) const; 00094 00096 unsigned char operator[]( const unsigned int index ) const; 00097 00099 unsigned char& operator[]( const unsigned int index ); 00100 00103 operator std::string() const; 00104 00106 void Print(std::ostream& os, itk::Indent indent) const; 00107 00109 static void Encode( std::string& output, const unsigned char *data, 00110 unsigned int size ); 00111 00113 bool Decode( const std::string& asciiString ); 00114 00115 protected: 00116 00118 void PrintHeader(std::ostream& os, itk::Indent indent) const; 00119 00121 void PrintTrailer(std::ostream& itkNotUsed(os), 00122 itk::Indent itkNotUsed(indent)) const; 00123 00125 virtual void PrintSelf( std::ostream& os, itk::Indent indent ) const; 00126 00127 private: 00128 00130 ContainerType m_Data; 00131 00132 }; 00133 00135 std::ostream& operator<<(std::ostream& os, const igstk::BinaryData& o); 00136 } 00137 00138 #endif