summaryrefslogtreecommitdiff
path: root/src/nids.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/nids.cpp')
-rw-r--r--src/nids.cpp93
1 files changed, 93 insertions, 0 deletions
diff --git a/src/nids.cpp b/src/nids.cpp
index b8ea13b..41c4dc1 100644
--- a/src/nids.cpp
+++ b/src/nids.cpp
@@ -1,8 +1,30 @@
1#include "bu/nids.h" 1#include "bu/nids.h"
2#include "bu/stream.h"
3#include "bu/nidsstream.h"
4#include <stdio.h>
2 5
3Bu::Nids::Nids( Bu::Stream &sStore ) : 6Bu::Nids::Nids( Bu::Stream &sStore ) :
4 sStore( sStore ) 7 sStore( sStore )
5{ 8{
9 printf("Stream caps:\n"
10 " canRead: %s\n"
11 " canWrite: %s\n"
12 " isReadable: %s\n"
13 " isWritable: %s\n"
14 " isSeekable: %s\n"
15 " isBlocking: %s\n"
16 " isEOS: %s\n"
17 " isOpen: %s\n",
18 sStore.canRead()?"yes":"no",
19 sStore.canWrite()?"yes":"no",
20 sStore.isReadable()?"yes":"no",
21 sStore.isWritable()?"yes":"no",
22 sStore.isSeekable()?"yes":"no",
23 sStore.isBlocking()?"yes":"no",
24 sStore.isEOS()?"yes":"no",
25 sStore.isOpen()?"yes":"no"
26 );
27 printf("sizeof(Block) = %db\n", sizeof(Block) );
6} 28}
7 29
8Bu::Nids::~Nids() 30Bu::Nids::~Nids()
@@ -11,11 +33,82 @@ Bu::Nids::~Nids()
11 33
12void Bu::Nids::initialize( int iBlockSize, int iPreAllocate ) 34void Bu::Nids::initialize( int iBlockSize, int iPreAllocate )
13{ 35{
36 char cBuf = 0;
37 int iBuf = 0;
38
39 // Magic number
40 sStore.write( "\xFF\xC3\x99\xBD", 4 );
41
42 // Version (0)
43 sStore.write( &cBuf, 1 );
44
45 // Bytes per int
46 cBuf = 4;
47 sStore.write( &cBuf, 1 );
48
49 // The size of each block and the number of blocks we're pre-allocating
50 sStore.write( &iBlockSize, 4 );
51 sStore.write( &iPreAllocate, 4 );
52
53 // The number of used blocks
54 sStore.write( &iBuf, 4 );
55
56 // Reserved space
57 sStore.write( "\x00\x00\x00\x00\x00\x00\x00", 7 );
58
59 this->iBlockSize = iBlockSize;
60 this->iBlocks = iPreAllocate;
61 this->iBlockStart = sStore.tell();
62 bsBlockUsed.setSize( iPreAllocate, true );
63
64 printf("%d blocks, %db each, %db block offset\n",
65 iBlocks, iBlockSize, iBlockStart );
66
67 char *block = new char[iBlockSize];
68 memset( block, 0, iBlockSize );
69 for( int j = 0; j < iPreAllocate; j++ )
70 {
71 sStore.write( block, iBlockSize );
72 }
14} 73}
15 74
16int Bu::Nids::createStream( int iPreAllocate ) 75int Bu::Nids::createStream( int iPreAllocate )
17{ 76{
77 for( int j = 0; j < iBlocks; j++ )
78 {
79 if( !bsBlockUsed.getBit( j ) )
80 {
81 Block b = { j, blockUnused, blockUnused, 0, 0 };
82 bsBlockUsed.setBit( j );
83 sStore.setPos( iBlockStart+(iBlockSize*j) );
84 sStore.write( &b, sizeof(b) );
85 }
86 }
18 return 0; 87 return 0;
19} 88}
20 89
90void Bu::Nids::deleteStream( int iID )
91{
92}
93
94Bu::NidsStream Bu::Nids::openStream( int iID )
95{
96 return NidsStream( *this );
97}
98
99void Bu::Nids::extendStream( int iID, int iBlockCount )
100{
101}
102
103void Bu::Nids::getBlock( int iIndex, Bu::Nids::Block *pBlock )
104{
105 sStore.setPos( iBlockStart + (iBlockSize*iIndex) );
106 sStore.read( pBlock, iBlockSize );
107}
108
109void Bu::Nids::setBlock( int iIndex, Bu::Nids::Block *pBlock )
110{
111 sStore.setPos( iBlockStart + (iBlockSize*iIndex) );
112 sStore.write( pBlock, iBlockSize );
113}
21 114