summaryrefslogtreecommitdiff
path: root/src/nidsstream.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2008-10-01 16:46:32 +0000
committerMike Buland <eichlan@xagasoft.com>2008-10-01 16:46:32 +0000
commitd872f7e07c5367f251cf5ebb70a03916251f5306 (patch)
tree2140986825705e4b6bf35eba8dd556be772888ff /src/nidsstream.cpp
parent467c255511749f018c4572017c9e0e87275524ac (diff)
downloadlibbu++-d872f7e07c5367f251cf5ebb70a03916251f5306.tar.gz
libbu++-d872f7e07c5367f251cf5ebb70a03916251f5306.tar.bz2
libbu++-d872f7e07c5367f251cf5ebb70a03916251f5306.tar.xz
libbu++-d872f7e07c5367f251cf5ebb70a03916251f5306.zip
Ok, NIDS is getting better and better, and I went ahead and cleaned up some
exception related code that's been annoying me. You should no longer have to include any exception header explicitly for normal operations, every class that has it's own exception to throw defines it in it's own headers. This may break some code that uses libbu++, but it's an easy fix, just delete the include for exceptions.h. Sometime soon I would also like to move from Bu::ExceptionBase to Bu::Exception, but that will affect a lot more code than this change did.
Diffstat (limited to 'src/nidsstream.cpp')
-rw-r--r--src/nidsstream.cpp95
1 files changed, 86 insertions, 9 deletions
diff --git a/src/nidsstream.cpp b/src/nidsstream.cpp
index 2f24d69..740dc1f 100644
--- a/src/nidsstream.cpp
+++ b/src/nidsstream.cpp
@@ -1,20 +1,41 @@
1#include "bu/nidsstream.h" 1#include "bu/nidsstream.h"
2 2
3Bu::NidsStream::NidsStream( Nids &rNids ) : 3Bu::NidsStream::NidsStream( Nids &rNids, uint32_t uStream ) :
4 rNids( rNids ), 4 rNids( rNids ),
5 iPos( 0 ) 5 uStream( uStream ),
6 pCurBlock( NULL ),
7 uCurBlock( uStream ),
8 uSize( 0 ),
9 uBlockSize( rNids.iBlockSize-sizeof(Nids::Block) ),
10 uPos( 0 )
6{ 11{
12 printf("NidsStream::allocated\n");
13 pCurBlock = rNids.newBlock();
14 rNids.getBlock( uStream, pCurBlock );
15 uSize = pCurBlock->uBytesUsed;
7} 16}
8 17
18/*
9Bu::NidsStream::NidsStream( const Bu::NidsStream &rSrc ) : 19Bu::NidsStream::NidsStream( const Bu::NidsStream &rSrc ) :
20 Stream( rSrc ),
10 rNids( rSrc.rNids ), 21 rNids( rSrc.rNids ),
11 iPos( 0 ) 22 uStream( rSrc.uStream ),
12{ 23 pCurBlock( NULL ),
13 24 uCurBlock( uStream ),
14} 25 uSize( 0 ),
26 uBlockSize( rSrc.uBlockSize ),
27 iUsable( uBlockSize-sizeof(Nids::Block) ),
28 uPos( 0 )
29{
30 printf("NidsStream::copied\n");
31 pCurBlock = rNids.newBlock();
32 rNids.getBlock( uStream, pCurBlock );
33}*/
15 34
16Bu::NidsStream::~NidsStream() 35Bu::NidsStream::~NidsStream()
17{ 36{
37 rNids.updateStreamSize( uStream, uSize );
38 rNids.deleteBlock( pCurBlock );
18} 39}
19 40
20void Bu::NidsStream::close() 41void Bu::NidsStream::close()
@@ -23,29 +44,85 @@ void Bu::NidsStream::close()
23 44
24size_t Bu::NidsStream::read( void *pBuf, size_t nBytes ) 45size_t Bu::NidsStream::read( void *pBuf, size_t nBytes )
25{ 46{
47 if( uPos%uBlockSize+nBytes < uBlockSize )
48 {
49 size_t iRead = nBytes;
50 if( iRead > pCurBlock->uBytesUsed )
51 iRead = pCurBlock->uBytesUsed;
52 memcpy( pBuf, pCurBlock->pData+(uPos%uBlockSize), iRead );
53 uPos += nBytes;
54 printf("a: block %u = %ub (%ub total)\n",
55 uCurBlock, pCurBlock->uBytesUsed, uSize );
56 return iRead;
57 }
58 else
59 {
60 //size_t iTotal = 0;
61 for(;;)
62 {
63
64 }
65 }
26 return 0; 66 return 0;
27} 67}
28 68
29size_t Bu::NidsStream::write( const void *pBuf, size_t nBytes ) 69size_t Bu::NidsStream::write( const void *pBuf, size_t nBytes )
30{ 70{
31 return 0; 71 if( uPos%uBlockSize+nBytes < uBlockSize )
72 {
73 memcpy( pCurBlock->pData+(uPos%uBlockSize), pBuf, nBytes );
74 pCurBlock->uBytesUsed += nBytes;
75 rNids.setBlock( uCurBlock, pCurBlock );
76 uPos += nBytes;
77 uSize += nBytes;
78 printf("a: block %u = %ub (%ub total)\n",
79 uCurBlock, pCurBlock->uBytesUsed, uSize );
80 return nBytes;
81 }
82 else
83 {
84 size_t nTotal = 0;
85 for(;;)
86 {
87 uint32_t uNow = uBlockSize-(uPos%uBlockSize);
88 if( nBytes < uNow )
89 uNow = nBytes;
90 memcpy( pCurBlock->pData+(uPos%uBlockSize),
91 &((char *)pBuf)[nTotal], uNow );
92 pCurBlock->uBytesUsed += uNow;
93 rNids.setBlock( uCurBlock, pCurBlock );
94 uSize += uNow;
95 uPos += uNow;
96 nTotal += uNow;
97 nBytes -= uNow;
98 printf("b: block %u = %ub (%ub total)\n",
99 uCurBlock, pCurBlock->uBytesUsed, uSize );
100 if( nBytes == 0 )
101 return nTotal;
102 if( pCurBlock->uBytesUsed == uBlockSize )
103 uCurBlock = rNids.getNextBlock( uCurBlock, pCurBlock );
104 }
105 }
32} 106}
33 107
34long Bu::NidsStream::tell() 108long Bu::NidsStream::tell()
35{ 109{
36 return 0; 110 return uPos;
37} 111}
38 112
39void Bu::NidsStream::seek( long offset ) 113void Bu::NidsStream::seek( long offset )
40{ 114{
115 uPos += offset;
41} 116}
42 117
43void Bu::NidsStream::setPos( long pos ) 118void Bu::NidsStream::setPos( long pos )
44{ 119{
120 uPos = pos;
45} 121}
46 122
47void Bu::NidsStream::setPosEnd( long pos ) 123void Bu::NidsStream::setPosEnd( long pos )
48{ 124{
125 uPos = uSize-pos-1;
49} 126}
50 127
51bool Bu::NidsStream::isEOS() 128bool Bu::NidsStream::isEOS()
@@ -92,7 +169,7 @@ bool Bu::NidsStream::isBlocking()
92 return true; 169 return true;
93} 170}
94 171
95void Bu::NidsStream::setBlocking( bool bBlocking ) 172void Bu::NidsStream::setBlocking( bool /*bBlocking*/ )
96{ 173{
97} 174}
98 175