IGSTK
igstkBinaryData.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Image Guided Surgery Software Toolkit
4  Module: $RCSfile: igstkBinaryData.h,v $
5  Language: C++
6  Date: $Date: 2008-02-11 01:41:50 $
7  Version: $Revision: 1.9 $
8 
9  Copyright (c) ISC Insight Software Consortium. All rights reserved.
10  See IGSTKCopyright.txt or http://www.igstk.org/copyright.htm for details.
11 
12  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 #ifndef __igstkBinaryData_h
18 #define __igstkBinaryData_h
19 
20 
21 #include <itkObject.h>
22 #include <vector>
23 #include <string>
24 
25 namespace igstk
26 {
27 
39 {
40 public:
41 
43  typedef std::vector<unsigned char> ContainerType;
44 
45 public:
46 
48  BinaryData();
49 
51  BinaryData(const char* encodedString);
52 
54  BinaryData(const std::string& encodedString);
55 
57  virtual ~BinaryData();
58 
60  void SetSize(unsigned int size);
61 
63  unsigned int GetSize() const;
64 
66  const ContainerType& GetData() const { return this->m_Data; }
67 
69  ContainerType& GetData() { return this->m_Data; }
70 
72  void CopyFrom(unsigned char* inputBegin, unsigned int inputLength);
73 
75  void CopyTo(unsigned char* output) const;
76 
78  void Append(unsigned char byte);
79 
81  void Append(const unsigned char* inputBegin, unsigned int inputLength);
82 
84  const BinaryData & operator=( const BinaryData & inputBinaryData );
85 
87  bool operator==( const BinaryData & inputBinaryData ) const;
88 
90  bool operator!=( const BinaryData & inputBinaryData ) const;
91 
93  bool operator<( const BinaryData & inputBinaryData ) const;
94 
96  unsigned char operator[]( const unsigned int index ) const;
97 
99  unsigned char& operator[]( const unsigned int index );
100 
103  operator std::string() const;
104 
106  void Print(std::ostream& os, itk::Indent indent) const;
107 
109  static void Encode( std::string& output, const unsigned char *data,
110  unsigned int size );
111 
113  bool Decode( const std::string& asciiString );
114 
115 protected:
116 
118  void PrintHeader(std::ostream& os, itk::Indent indent) const;
119 
121  void PrintTrailer(std::ostream& itkNotUsed(os),
122  itk::Indent itkNotUsed(indent)) const;
123 
125  virtual void PrintSelf( std::ostream& os, itk::Indent indent ) const;
126 
127 private:
128 
130  ContainerType m_Data;
131 
132 };
133 
135 std::ostream& operator<<(std::ostream& os, const igstk::BinaryData& o);
136 }
137 
138 #endif