merge the formfield patch from ooo-build
[ooovba.git] / cosv / source / storage / mbstream.cxx
blobd8551ab41364a2b58368411c2cae83d875204480
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: mbstream.cxx,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include <precomp.h>
32 #include <cosv/mbstream.hxx>
34 // NOT FULLY DECLARED SERVICES
35 #include <string.h>
38 namespace csv
43 mbstream::mbstream( uintt i_nSize )
44 : dpOwnedMemorySpace( new char[i_nSize+1] ),
45 nSize( i_nSize ),
46 nCurPosition( 0 )
48 dpOwnedMemorySpace[i_nSize] = '\0';
51 mbstream::~mbstream()
53 delete [] dpOwnedMemorySpace;
56 void
57 mbstream::resize( uintt i_nSize )
59 DYN char * pNew = new char[i_nSize];
60 memcpy( pNew, dpOwnedMemorySpace, min(i_nSize,nSize) );
61 delete [] dpOwnedMemorySpace;
62 dpOwnedMemorySpace = pNew;
63 nSize = i_nSize;
66 uintt
67 mbstream::do_read( void * out_pDest,
68 uintt i_nNrofBytes )
70 uintt ret = min( i_nNrofBytes, nSize - nCurPosition );
71 memcpy( out_pDest, dpOwnedMemorySpace, ret );
72 nCurPosition += ret;
73 return ret;
76 bool
77 mbstream::inq_eod() const
79 return nCurPosition == nSize;
82 uintt
83 mbstream::do_write( const void * i_pSrc,
84 uintt i_nNrofBytes )
86 resize( max( 3 * (nSize+1) / 2, nCurPosition + i_nNrofBytes) );
87 memcpy( dpOwnedMemorySpace+nCurPosition, i_pSrc, i_nNrofBytes );
88 nCurPosition += i_nNrofBytes;
89 return i_nNrofBytes;
92 uintt
93 mbstream::do_seek( intt i_nDistance,
94 seek_dir i_eStartPoint )
96 switch ( i_eStartPoint )
98 case beg: if ( uintt(i_nDistance) < nSize )
99 nCurPosition = uintt(i_nDistance);
100 break;
101 case cur: if ( i_nDistance < 0
102 ? uintt(-i_nDistance) <= nCurPosition
103 : uintt(i_nDistance) + nCurPosition < nSize )
104 nCurPosition = uintt( intt(nCurPosition) + i_nDistance );
105 break;
106 case end: if ( i_nDistance < 0
107 AND uintt(-i_nDistance) < nSize - 1 )
108 nCurPosition = uintt( intt(nSize) - 1 + i_nDistance );
109 break;
111 return position();
114 uintt
115 mbstream::inq_position() const
117 return nCurPosition;
121 } // namespace csv