summaryrefslogtreecommitdiff
path: root/src/stable/staticmembuf.cpp
blob: 008e4ee61ce3c7fb7486cb0bd36351e19b2feb76 (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
 * Copyright (C) 2007-2013 Xagasoft, All rights reserved.
 *
 * This file is part of the libbu++ library and is released under the
 * terms of the license contained in the file LICENSE.
 */

#include "bu/staticmembuf.h"

using namespace Bu;

Bu::StaticMemBuf::StaticMemBuf( const void *pData, size iSize ) :
    pData( pData ),
    iSize( iSize ),
    nPos( 0 )
{
}

Bu::StaticMemBuf::~StaticMemBuf()
{
}

void Bu::StaticMemBuf::close()
{
}

size Bu::StaticMemBuf::read( void *pBuf, size nBytes )
{
    if( iSize-nPos < nBytes )
        nBytes = iSize-nPos;

    memcpy( pBuf, ((char *)pData)+nPos, nBytes );
    nPos += nBytes;

    return nBytes;
}
    
size Bu::StaticMemBuf::write( const void *, size )
{
    return -1;
}

size Bu::StaticMemBuf::tell()
{
    return nPos;
}

void Bu::StaticMemBuf::seek( size offset )
{
    nPos += offset;
    if( nPos < 0 ) nPos = 0;
    else if( nPos > iSize ) nPos = iSize;
}

void Bu::StaticMemBuf::setPos( size pos )
{
    nPos = pos;
    if( nPos < 0 ) nPos = 0;
    else if( nPos > iSize ) nPos = iSize;
}

void Bu::StaticMemBuf::setPosEnd( size pos )
{
    nPos = iSize-pos;
    if( nPos < 0 ) nPos = 0;
    else if( nPos > iSize ) nPos = iSize;
}

bool Bu::StaticMemBuf::isEos()
{
    return (nPos == iSize);
}

bool Bu::StaticMemBuf::isOpen()
{
    return true;
}

void Bu::StaticMemBuf::flush()
{
}

bool Bu::StaticMemBuf::canRead()
{
    return !isEos();
}

bool Bu::StaticMemBuf::canWrite()
{
    return false;
}

bool Bu::StaticMemBuf::isReadable()
{
    return true;
}

bool Bu::StaticMemBuf::isWritable()
{
    return false;
}

bool Bu::StaticMemBuf::isSeekable()
{
    return true;
}

bool Bu::StaticMemBuf::isBlocking()
{
    return true;
}

void Bu::StaticMemBuf::setBlocking( bool )
{
}

void Bu::StaticMemBuf::setSize( size )
{
}

Bu::size Bu::StaticMemBuf::getSize() const
{
    return iSize;
}

Bu::size Bu::StaticMemBuf::getBlockSize() const
{
    return iSize;
}

Bu::String Bu::StaticMemBuf::getLocation() const
{
    return "";
}