blob: cdefdcbc52543ef4d479bbaae0c53456e70b8515 (
plain)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
#ifndef BU_NIDS_H
#define BU_NIDS_H
#include <stdint.h>
#include "bu/bitstring.h"
#include "bu/exceptionbase.h"
namespace Bu
{
class Stream;
class NidsStream;
subExceptionDecl( NidsException )
/**
* Numerically Indexed Data Streams. This is a working name so I can
* actually get some code written instead of agonizing over the name.
*
* This is a system for creating streams that contain other streams in
* a flexible block-allocated system.
*/
class Nids
{
friend class NidsStream;
public:
Nids( Bu::Stream &sStore );
virtual ~Nids();
/**
* Initialize this object based on the data already in the assosiated
* stream. This will be called automatically for you if you forget,
* but if you want to pre-initialize for some reason, just call this
* once before you actually start doing anything with your Nids.
*/
void initialize();
/**
* Create a new Nids system in the assosiated stream. This should be
* used carefully, it will destroy all data already within the stream.
* More options will probably be added soon.
*/
void initialize( int iBlockSize, int iPreAllocate=1 );
/**
* Create a new stream within the Nids system. The ID of the new stream
* is returned.
*/
int createStream( int iPreAllocate=1 );
/**
* Delete a stream that's already within the Nids.
*/
void deleteStream( int iID );
/**
* Return a new Stream object assosiated with the given stream ID.
*/
NidsStream openStream( int iID );
int getBlockSize();
private:
typedef struct Block
{
uint32_t uFirstBlock;
uint32_t uNextBlock;
uint32_t uPrevBlock;
uint32_t uBytesUsed;
uint32_t uReserved;
unsigned char pData[0];
} Block;
enum
{
blockUnused = 0xFFFFFFFFUL
};
uint32_t createBlock( uint32_t uFirstBlock, uint32_t uPrevBlock,
int iPreAllocate=1 );
void getBlock( uint32_t uIndex, struct Nids::Block *pBlock );
void setBlock( uint32_t uIndex, struct Nids::Block *pBlock );
void updateStreamSize( uint32_t uIndex, uint32_t uSize );
uint32_t getNextBlock( uint32_t uIndex, struct Nids::Block *pBlock );
Block *newBlock();
void deleteBlock( Block *pBlock );
private:
Bu::Stream &sStore;
int iBlockSize;
int iBlocks;
int iBlockStart;
Bu::BitString bsBlockUsed;
};
};
#endif
|