3 /// Class to deal with pre-saved data files
7 Copyright (C) 2005-2007, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
32 unsigned char *m_data
;
33 size_t m_bufsize
; //< size of m_data buffer allocated
34 size_t m_datasize
; //< number of bytes of actual data
37 // copy on write feature
38 const unsigned char *m_externalData
;
41 // output format flags
42 static bool bPrintAscii
;
45 void MakeSpace(size_t desiredsize
);
46 void CopyOnWrite(size_t desiredsize
);
50 explicit Data(int endpoint
, size_t startsize
= 0x4000);
51 Data(const void *ValidData
, size_t size
);
52 Data(const Data
&other
);
55 void InputHexLine(std::istream
&is
);
56 void DumpHexLine(std::ostream
&os
, size_t index
, size_t size
) const;
57 void DumpHex(std::ostream
&os
) const;
59 int GetEndpoint() const { return m_endpoint
; }
61 const unsigned char * GetData() const { return m_external
? m_externalData
: m_data
; }
62 size_t GetSize() const { return m_datasize
; }
64 unsigned char * GetBuffer(size_t requiredsize
= 0);
65 size_t GetBufSize() const { return m_bufsize
; }
66 void ReleaseBuffer(int datasize
= -1);
68 void AppendHexString(const char *str
);
72 Data
& operator=(const Data
&other
);
76 static void PrintAscii(bool setting
) { bPrintAscii
= setting
; }
77 static bool PrintAscii() { return bPrintAscii
; }
80 std::istream
& operator>> (std::istream
&is
, Data
&data
);
81 std::ostream
& operator<< (std::ostream
&os
, const Data
&data
);
86 const Data
&m_old
, &m_new
;
88 void Compare(std::ostream
&os
, size_t index
, size_t size
) const;
91 Diff(const Data
&old
, const Data
&new_
);
93 void Dump(std::ostream
&os
) const;
96 std::ostream
& operator<< (std::ostream
&os
, const Diff
&diff
);
100 bool LoadDataArray(const std::string
&filename
, std::vector
<Data
> &array
);