aboutsummaryrefslogtreecommitdiff
path: root/src/staticmembuf.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2012-02-09 05:30:38 +0000
committerMike Buland <eichlan@xagasoft.com>2012-02-09 05:30:38 +0000
commit10747b4fb6ff74fa83384859b09ba695378aea60 (patch)
tree24af7800d3392a4b7add7fc31b9961b6295465a6 /src/staticmembuf.cpp
parent5a6476514c075743ca13d566bd306b2d71d1952a (diff)
downloadlibbu++-10747b4fb6ff74fa83384859b09ba695378aea60.tar.gz
libbu++-10747b4fb6ff74fa83384859b09ba695378aea60.tar.bz2
libbu++-10747b4fb6ff74fa83384859b09ba695378aea60.tar.xz
libbu++-10747b4fb6ff74fa83384859b09ba695378aea60.zip
Added StaticMemBuf and used it in bin2cpp. You can also set the name of the
class that bin2cpp generates for you.
Diffstat (limited to 'src/staticmembuf.cpp')
-rw-r--r--src/staticmembuf.cpp135
1 files changed, 135 insertions, 0 deletions
diff --git a/src/staticmembuf.cpp b/src/staticmembuf.cpp
new file mode 100644
index 0000000..74fae31
--- /dev/null
+++ b/src/staticmembuf.cpp
@@ -0,0 +1,135 @@
1/*
2 * Copyright (C) 2007-2011 Xagasoft, All rights reserved.
3 *
4 * This file is part of the libbu++ library and is released under the
5 * terms of the license contained in the file LICENSE.
6 */
7
8#include "bu/staticmembuf.h"
9
10using namespace Bu;
11
12Bu::StaticMemBuf::StaticMemBuf( const void *pData, size iSize ) :
13 pData( pData ),
14 iSize( iSize ),
15 nPos( 0 )
16{
17}
18
19Bu::StaticMemBuf::~StaticMemBuf()
20{
21}
22
23void Bu::StaticMemBuf::close()
24{
25}
26
27size Bu::StaticMemBuf::read( void *pBuf, size nBytes )
28{
29 if( iSize-nPos < nBytes )
30 nBytes = iSize-nPos;
31
32 memcpy( pBuf, ((char *)pData)+nPos, nBytes );
33 nPos += nBytes;
34
35 return nBytes;
36}
37
38size Bu::StaticMemBuf::write( const void *, size )
39{
40 return -1;
41}
42
43size Bu::StaticMemBuf::tell()
44{
45 return nPos;
46}
47
48void Bu::StaticMemBuf::seek( size offset )
49{
50 nPos += offset;
51 if( nPos < 0 ) nPos = 0;
52 else if( nPos > iSize ) nPos = iSize;
53}
54
55void Bu::StaticMemBuf::setPos( size pos )
56{
57 nPos = pos;
58 if( nPos < 0 ) nPos = 0;
59 else if( nPos > iSize ) nPos = iSize;
60}
61
62void Bu::StaticMemBuf::setPosEnd( size pos )
63{
64 nPos = iSize-pos;
65 if( nPos < 0 ) nPos = 0;
66 else if( nPos > iSize ) nPos = iSize;
67}
68
69bool Bu::StaticMemBuf::isEos()
70{
71 return (nPos == iSize);
72}
73
74bool Bu::StaticMemBuf::isOpen()
75{
76 return true;
77}
78
79void Bu::StaticMemBuf::flush()
80{
81}
82
83bool Bu::StaticMemBuf::canRead()
84{
85 return !isEos();
86}
87
88bool Bu::StaticMemBuf::canWrite()
89{
90 return false;
91}
92
93bool Bu::StaticMemBuf::isReadable()
94{
95 return true;
96}
97
98bool Bu::StaticMemBuf::isWritable()
99{
100 return false;
101}
102
103bool Bu::StaticMemBuf::isSeekable()
104{
105 return true;
106}
107
108bool Bu::StaticMemBuf::isBlocking()
109{
110 return true;
111}
112
113void Bu::StaticMemBuf::setBlocking( bool )
114{
115}
116
117void Bu::StaticMemBuf::setSize( size )
118{
119}
120
121Bu::size Bu::StaticMemBuf::getSize() const
122{
123 return iSize;
124}
125
126Bu::size Bu::StaticMemBuf::getBlockSize() const
127{
128 return iSize;
129}
130
131Bu::String Bu::StaticMemBuf::getLocation() const
132{
133 return "";
134}
135