-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathDataBuffer.h
More file actions
65 lines (53 loc) · 1.88 KB
/
DataBuffer.h
File metadata and controls
65 lines (53 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
* DataBuffer.h
* C700
*
* Created by osoumen on 12/10/10.
* Copyright 2012 __MyCompanyName__. All rights reserved.
*
*/
#pragma once
#if _WIN32
#include <windows.h>
#endif
class DataBuffer {
public:
typedef struct {
int pos;
int used;
} DataBufferState;
DataBuffer( int allocMemSize );
DataBuffer( const void *data, int dataSize, bool copy=false ); // falseだとコピーも解放もされない
DataBuffer( const char *path );
virtual ~DataBuffer();
void Clear();
const unsigned char *GetDataPtr() const { return m_pData; }
int GetDataUsed() const { return mDataUsed; }
int GetDataSize() const { return mDataSize; }
int GetLeftSize() const { return (mDataSize - mDataPos - 1); }
int GetDataPos() const { return mDataPos; }
void AdvDataPos( int adv ) { mDataPos+=adv; }
bool setPos( int pos );
int getPos() { return mDataPos; }
bool isReadOnly() { return mReadOnly; }
bool readData( void *data, long byte, long *actualReadByte=NULL );
bool writeData( const void *data, long byte, long *actualWriteByte=NULL );
bool writeByte( unsigned char byte );
bool writeByte( unsigned char byte, int len );
bool writeU16( unsigned short word );
bool writeU24( int value );
bool writeS32( int value );
DataBufferState SaveState();
void RestoreState(const DataBufferState &state);
bool WriteToFile(const char *path);
void SetAllowExtend( bool enable ) { mAllowExtend = enable; }
protected:
bool mIsBufferInternal;
unsigned char *m_pData;
int mDataSize;
int mDataUsed;
int mDataPos;
bool mReadOnly;
bool mAllowExtend;
void extendDataSize(int extendBytes);
};