Update ooo320-m1
[ooovba.git] / tools / source / stream / vcompat.cxx
blobf96784084eb2e2ac23376a524e2a1e312715496c
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: vcompat.cxx,v $
10 * $Revision: 1.5 $
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 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_tools.hxx"
34 #define _VCOMPAT_CXX
35 #include <tools/stream.hxx>
36 #include <tools/vcompat.hxx>
38 // -----------------
39 // - VersionCompat -
40 // -----------------
42 VersionCompat::VersionCompat( SvStream& rStm, USHORT nStreamMode, USHORT nVersion ) :
43 mpRWStm ( &rStm ),
44 mnStmMode ( nStreamMode ),
45 mnVersion ( nVersion )
47 if( !mpRWStm->GetError() )
49 if( STREAM_WRITE == mnStmMode )
51 *mpRWStm << mnVersion;
52 mnTotalSize = ( mnCompatPos = mpRWStm->Tell() ) + 4UL;
53 mpRWStm->SeekRel( 4L );
55 else
57 *mpRWStm >> mnVersion;
58 *mpRWStm >> mnTotalSize;
59 mnCompatPos = mpRWStm->Tell();
64 // ------------------------------------------------------------------------
66 VersionCompat::~VersionCompat()
68 if( STREAM_WRITE == mnStmMode )
70 const UINT32 nEndPos = mpRWStm->Tell();
72 mpRWStm->Seek( mnCompatPos );
73 *mpRWStm << ( nEndPos - mnTotalSize );
74 mpRWStm->Seek( nEndPos );
76 else
78 const UINT32 nReadSize = mpRWStm->Tell() - mnCompatPos;
80 if( mnTotalSize > nReadSize )
81 mpRWStm->SeekRel( mnTotalSize - nReadSize );