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
static void Encode(std::string &output, const unsigned char *data, unsigned int size)
Encode method encodes binary data to ASCII string in std::string.
void Print(std::ostream &os, itk::Indent indent) const
Method for printing the member variables of this class to an ostream.
virtual void PrintSelf(std::ostream &os, itk::Indent indent) const
Print the object information in a stream.
std::ostream & operator<<(std::ostream &os, const igstk::AffineTransform &o)
void SetSize(unsigned int size)
SetSize method resizes/allocates memory.
BinaryData()
Constructor.
void Append(unsigned char byte)
Append a byte.
std::vector< unsigned char > ContainerType
Data container type definition.
const BinaryData & operator=(const BinaryData &inputBinaryData)
Assign the values of one BinaryData to another.
ContainerType & GetData()
Get a data container.
void CopyFrom(unsigned char *inputBegin, unsigned int inputLength)
Copy data from an array.
virtual ~BinaryData()
Destructor.
bool operator==(const BinaryData &inputBinaryData) const
operator== redefinition
bool operator!=(const BinaryData &inputBinaryData) const
operator!= redefinition
void PrintTrailer(std::ostream &itkNotUsed(os), itk::Indent itkNotUsed(indent)) const
Method for printing the trailer to an ostream.
const ContainerType & GetData() const
Get a data container (returns constant)
bool Decode(const std::string &asciiString)
Decode method decodes encoded ASCII string to binary data.
BinaryData representing a binary data chunk.
void PrintHeader(std::ostream &os, itk::Indent indent) const
Method for printing the header to an ostream.
unsigned int GetSize() const
GetSize method returns the size of data.
unsigned char operator[](const unsigned int index) const
operator[] redefinition
void CopyTo(unsigned char *output) const
Copy data into an array.
bool operator<(const BinaryData &inputBinaryData) const
operator< redefinition