diff options
author | Mike Buland <eichlan@xagasoft.com> | 2012-03-25 20:00:08 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2012-03-25 20:00:08 +0000 |
commit | 469bbcf0701e1eb8a6670c23145b0da87357e178 (patch) | |
tree | b5b062a16e46a6c5d3410b4e574cd0cc09057211 /src/stable/staticmembuf.cpp | |
parent | ee1b79396076edc4e30aefb285fada03bb45e80d (diff) | |
download | libbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.tar.gz libbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.tar.bz2 libbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.tar.xz libbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.zip |
Code is all reorganized. We're about ready to release. I should write up a
little explenation of the arrangement.
Diffstat (limited to 'src/stable/staticmembuf.cpp')
-rw-r--r-- | src/stable/staticmembuf.cpp | 135 |
1 files changed, 135 insertions, 0 deletions
diff --git a/src/stable/staticmembuf.cpp b/src/stable/staticmembuf.cpp new file mode 100644 index 0000000..74fae31 --- /dev/null +++ b/src/stable/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 | |||
10 | using namespace Bu; | ||
11 | |||
12 | Bu::StaticMemBuf::StaticMemBuf( const void *pData, size iSize ) : | ||
13 | pData( pData ), | ||
14 | iSize( iSize ), | ||
15 | nPos( 0 ) | ||
16 | { | ||
17 | } | ||
18 | |||
19 | Bu::StaticMemBuf::~StaticMemBuf() | ||
20 | { | ||
21 | } | ||
22 | |||
23 | void Bu::StaticMemBuf::close() | ||
24 | { | ||
25 | } | ||
26 | |||
27 | size 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 | |||
38 | size Bu::StaticMemBuf::write( const void *, size ) | ||
39 | { | ||
40 | return -1; | ||
41 | } | ||
42 | |||
43 | size Bu::StaticMemBuf::tell() | ||
44 | { | ||
45 | return nPos; | ||
46 | } | ||
47 | |||
48 | void Bu::StaticMemBuf::seek( size offset ) | ||
49 | { | ||
50 | nPos += offset; | ||
51 | if( nPos < 0 ) nPos = 0; | ||
52 | else if( nPos > iSize ) nPos = iSize; | ||
53 | } | ||
54 | |||
55 | void Bu::StaticMemBuf::setPos( size pos ) | ||
56 | { | ||
57 | nPos = pos; | ||
58 | if( nPos < 0 ) nPos = 0; | ||
59 | else if( nPos > iSize ) nPos = iSize; | ||
60 | } | ||
61 | |||
62 | void 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 | |||
69 | bool Bu::StaticMemBuf::isEos() | ||
70 | { | ||
71 | return (nPos == iSize); | ||
72 | } | ||
73 | |||
74 | bool Bu::StaticMemBuf::isOpen() | ||
75 | { | ||
76 | return true; | ||
77 | } | ||
78 | |||
79 | void Bu::StaticMemBuf::flush() | ||
80 | { | ||
81 | } | ||
82 | |||
83 | bool Bu::StaticMemBuf::canRead() | ||
84 | { | ||
85 | return !isEos(); | ||
86 | } | ||
87 | |||
88 | bool Bu::StaticMemBuf::canWrite() | ||
89 | { | ||
90 | return false; | ||
91 | } | ||
92 | |||
93 | bool Bu::StaticMemBuf::isReadable() | ||
94 | { | ||
95 | return true; | ||
96 | } | ||
97 | |||
98 | bool Bu::StaticMemBuf::isWritable() | ||
99 | { | ||
100 | return false; | ||
101 | } | ||
102 | |||
103 | bool Bu::StaticMemBuf::isSeekable() | ||
104 | { | ||
105 | return true; | ||
106 | } | ||
107 | |||
108 | bool Bu::StaticMemBuf::isBlocking() | ||
109 | { | ||
110 | return true; | ||
111 | } | ||
112 | |||
113 | void Bu::StaticMemBuf::setBlocking( bool ) | ||
114 | { | ||
115 | } | ||
116 | |||
117 | void Bu::StaticMemBuf::setSize( size ) | ||
118 | { | ||
119 | } | ||
120 | |||
121 | Bu::size Bu::StaticMemBuf::getSize() const | ||
122 | { | ||
123 | return iSize; | ||
124 | } | ||
125 | |||
126 | Bu::size Bu::StaticMemBuf::getBlockSize() const | ||
127 | { | ||
128 | return iSize; | ||
129 | } | ||
130 | |||
131 | Bu::String Bu::StaticMemBuf::getLocation() const | ||
132 | { | ||
133 | return ""; | ||
134 | } | ||
135 | |||