data.h

Go to the documentation of this file.
00001 ///
00002 /// \file       data.h
00003 ///             Class to deal with pre-saved data files
00004 ///
00005 
00006 /*
00007     Copyright (C) 2005-2008, Net Direct Inc. (http://www.netdirect.ca/)
00008 
00009     This program is free software; you can redistribute it and/or modify
00010     it under the terms of the GNU General Public License as published by
00011     the Free Software Foundation; either version 2 of the License, or
00012     (at your option) any later version.
00013 
00014     This program is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00017 
00018     See the GNU General Public License in the COPYING file at the
00019     root directory of this project for more details.
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;               //< size of m_data buffer allocated
00035         size_t m_datasize;              //< number of bytes of actual data
00036         int m_endpoint;
00037 
00038         // copy on write feature
00039         const unsigned char *m_externalData;
00040         bool m_external;
00041 
00042         // output format flags
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         void Zap();
00072 
00073         Data& operator=(const Data &other);
00074 
00075 
00076         // static functions
00077         static void PrintAscii(bool setting) { bPrintAscii = setting; }
00078         static bool PrintAscii() { return bPrintAscii; }
00079 };
00080 
00081 BXEXPORT std::istream& operator>> (std::istream &is, Data &data);
00082 BXEXPORT std::ostream& operator<< (std::ostream &os, const Data &data);
00083 
00084 
00085 class BXEXPORT Diff
00086 {
00087         const Data &m_old, &m_new;
00088 
00089         BXLOCAL void Compare(std::ostream &os, size_t index, size_t size) const;
00090 
00091 public:
00092         Diff(const Data &old, const Data &new_);
00093 
00094         void Dump(std::ostream &os) const;
00095 };
00096 
00097 BXEXPORT std::ostream& operator<< (std::ostream &os, const Diff &diff);
00098 
00099 
00100 // utility functions
00101 BXEXPORT bool LoadDataArray(const std::string &filename, std::vector<Data> &array);
00102 BXEXPORT bool ReadDataArray(std::istream &is, std::vector<Data> &array);
00103 
00104 } // namespace Barry
00105 
00106 #endif
00107 

Generated on Wed Sep 24 21:27:31 2008 for Barry by  doxygen 1.5.1