2010-12-04 16:14:34 +00:00
|
|
|
#ifndef _IO_BINARYREADER_
|
|
|
|
#define _IO_BINARYREADER_
|
|
|
|
|
|
|
|
#include "../Types.h"
|
|
|
|
#include "../Interfaces.h"
|
|
|
|
#include "../Text/Encoding.h"
|
|
|
|
#include "Stream.h"
|
|
|
|
|
|
|
|
using namespace System::Text;
|
|
|
|
|
|
|
|
namespace System
|
|
|
|
{
|
|
|
|
namespace IO
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Reads primitive data types as binary values in a specific encoding.
|
|
|
|
/// </summary>
|
2011-03-10 22:55:43 +00:00
|
|
|
class BinaryReader : public IDisposable, virtual Object
|
2010-12-04 16:14:34 +00:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
bool m_2BytesPerChar;
|
|
|
|
byte* m_buffer;
|
|
|
|
char* m_charBuffer;
|
|
|
|
byte* m_charBytes;
|
|
|
|
char* m_singleChar;
|
2011-03-10 22:55:43 +00:00
|
|
|
Stream* m_stream;
|
2010-12-04 16:14:34 +00:00
|
|
|
Encoding m_encoding;
|
|
|
|
bool m_isMemoryStream;
|
|
|
|
Decoder m_decoder;
|
|
|
|
|
|
|
|
//! 128 chars should cover most strings in one grab.
|
|
|
|
static const int MaxBufferSize = 128;
|
|
|
|
|
|
|
|
bool m_disposed;
|
|
|
|
|
|
|
|
int InternalReadChars(char buffer[], int index, int count);
|
|
|
|
int InternalReadOneChar();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void Dispose(bool disposing);
|
|
|
|
virtual void FillBuffer(int numBytes);
|
|
|
|
|
|
|
|
public:
|
2011-03-10 22:55:43 +00:00
|
|
|
virtual Stream* BaseStream();
|
2010-12-04 16:14:34 +00:00
|
|
|
|
2011-03-10 22:55:43 +00:00
|
|
|
BinaryReader(Stream* input);
|
|
|
|
BinaryReader(Stream* input, Encoding encoding);
|
2010-12-04 16:14:34 +00:00
|
|
|
virtual ~BinaryReader();
|
|
|
|
|
|
|
|
virtual void Close();
|
|
|
|
virtual void Dispose();
|
|
|
|
virtual int PeekChar();
|
|
|
|
virtual int Read();
|
|
|
|
virtual int Read(byte buffer[], int index, int count);
|
|
|
|
virtual int Read(char buffer[], int index, int count);
|
|
|
|
virtual float ReadSingle();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif //_IO_BINARYREADER_
|