1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: mbstream.cxx,v $
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 ************************************************************************/
32 #include <cosv/mbstream.hxx>
34 // NOT FULLY DECLARED SERVICES
43 mbstream::mbstream( uintt i_nSize
)
44 : dpOwnedMemorySpace( new char[i_nSize
+1] ),
48 dpOwnedMemorySpace
[i_nSize
] = '\0';
53 delete [] dpOwnedMemorySpace
;
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
;
67 mbstream::do_read( void * out_pDest
,
70 uintt ret
= min( i_nNrofBytes
, nSize
- nCurPosition
);
71 memcpy( out_pDest
, dpOwnedMemorySpace
, ret
);
77 mbstream::inq_eod() const
79 return nCurPosition
== nSize
;
83 mbstream::do_write( const void * i_pSrc
,
86 resize( max( 3 * (nSize
+1) / 2, nCurPosition
+ i_nNrofBytes
) );
87 memcpy( dpOwnedMemorySpace
+nCurPosition
, i_pSrc
, i_nNrofBytes
);
88 nCurPosition
+= i_nNrofBytes
;
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
);
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
);
106 case end
: if ( i_nDistance
< 0
107 AND
uintt(-i_nDistance
) < nSize
- 1 )
108 nCurPosition
= uintt( intt(nSize
) - 1 + i_nDistance
);
115 mbstream::inq_position() const