data.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __SB_DATA_H__
00023 #define __SB_DATA_H__
00024
00025 #include "dll.h"
00026 #include <iosfwd>
00027 #include <vector>
00028
00029 namespace Barry {
00030
00031 class BXEXPORT Data
00032 {
00033 unsigned char *m_data;
00034 size_t m_bufsize;
00035 size_t m_datasize;
00036 int m_endpoint;
00037
00038
00039 const unsigned char *m_externalData;
00040 bool m_external;
00041
00042
00043 static bool bPrintAscii;
00044
00045 protected:
00046 void MakeSpace(size_t desiredsize);
00047 void CopyOnWrite(size_t desiredsize);
00048
00049 public:
00050 Data();
00051 explicit Data(int endpoint, size_t startsize = 0x4000);
00052 Data(const void *ValidData, size_t size);
00053 Data(const Data &other);
00054 ~Data();
00055
00056 void InputHexLine(std::istream &is);
00057 void DumpHexLine(std::ostream &os, size_t index, size_t size) const;
00058 void DumpHex(std::ostream &os) const;
00059
00060 int GetEndpoint() const { return m_endpoint; }
00061
00062 const unsigned char * GetData() const { return m_external ? m_externalData : m_data; }
00063 size_t GetSize() const { return m_datasize; }
00064
00065 unsigned char * GetBuffer(size_t requiredsize = 0);
00066 size_t GetBufSize() const { return m_bufsize; }
00067 void ReleaseBuffer(int datasize = -1);
00068
00069 void AppendHexString(const char *str);
00070
00071
00072 void QuickZap() { m_datasize = 0; }
00073 void Zap();
00074
00075 Data& operator=(const Data &other);
00076
00077
00078
00079 static void PrintAscii(bool setting) { bPrintAscii = setting; }
00080 static bool PrintAscii() { return bPrintAscii; }
00081 };
00082
00083 BXEXPORT std::istream& operator>> (std::istream &is, Data &data);
00084 BXEXPORT std::ostream& operator<< (std::ostream &os, const Data &data);
00085
00086
00087 class BXEXPORT Diff
00088 {
00089 const Data &m_old, &m_new;
00090
00091 BXLOCAL void Compare(std::ostream &os, size_t index, size_t size) const;
00092
00093 public:
00094 Diff(const Data &old, const Data &new_);
00095
00096 void Dump(std::ostream &os) const;
00097 };
00098
00099 BXEXPORT std::ostream& operator<< (std::ostream &os, const Diff &diff);
00100
00101
00102
00103 BXEXPORT bool LoadDataArray(const std::string &filename, std::vector<Data> &array);
00104 BXEXPORT bool ReadDataArray(std::istream &is, std::vector<Data> &array);
00105
00106 }
00107
00108 #endif
00109