1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
29 #include <cosv/mbstream.hxx>
31 // NOT FULLY DECLARED SERVICES
40 mbstream::mbstream( uintt i_nSize
)
41 : dpOwnedMemorySpace( new char[i_nSize
+1] ),
45 dpOwnedMemorySpace
[i_nSize
] = '\0';
50 delete [] dpOwnedMemorySpace
;
54 mbstream::resize( uintt i_nSize
)
56 DYN
char * pNew
= new char[i_nSize
];
57 memcpy( pNew
, dpOwnedMemorySpace
, min(i_nSize
,nSize
) );
58 delete [] dpOwnedMemorySpace
;
59 dpOwnedMemorySpace
= pNew
;
64 mbstream::do_read( void * out_pDest
,
67 uintt ret
= min( i_nNrofBytes
, nSize
- nCurPosition
);
68 memcpy( out_pDest
, dpOwnedMemorySpace
, ret
);
74 mbstream::inq_eod() const
76 return nCurPosition
== nSize
;
80 mbstream::do_write( const void * i_pSrc
,
83 resize( max( 3 * (nSize
+1) / 2, nCurPosition
+ i_nNrofBytes
) );
84 memcpy( dpOwnedMemorySpace
+nCurPosition
, i_pSrc
, i_nNrofBytes
);
85 nCurPosition
+= i_nNrofBytes
;
90 mbstream::do_seek( intt i_nDistance
,
91 seek_dir i_eStartPoint
)
93 switch ( i_eStartPoint
)
95 case beg
: if ( uintt(i_nDistance
) < nSize
)
96 nCurPosition
= uintt(i_nDistance
);
98 case cur
: if ( i_nDistance
< 0
99 ? uintt(-i_nDistance
) <= nCurPosition
100 : uintt(i_nDistance
) + nCurPosition
< nSize
)
101 nCurPosition
= uintt( intt(nCurPosition
) + i_nDistance
);
103 case end
: if ( i_nDistance
< 0
104 AND
uintt(-i_nDistance
) < nSize
- 1 )
105 nCurPosition
= uintt( intt(nSize
) - 1 + i_nDistance
);
112 mbstream::inq_position() const