1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_tools.hxx"
26
27 #define _VCOMPAT_CXX
28 #include <tools/stream.hxx>
29 #include <tools/vcompat.hxx>
30
31 // -----------------
32 // - VersionCompat -
33 // -----------------
34
VersionCompat(SvStream & rStm,sal_uInt16 nStreamMode,sal_uInt16 nVersion)35 VersionCompat::VersionCompat( SvStream& rStm, sal_uInt16 nStreamMode, sal_uInt16 nVersion ) :
36 mpRWStm ( &rStm ),
37 mnStmMode ( nStreamMode ),
38 mnVersion ( nVersion )
39 {
40 if( !mpRWStm->GetError() )
41 {
42 if( STREAM_WRITE == mnStmMode )
43 {
44 *mpRWStm << mnVersion;
45 mnTotalSize = ( mnCompatPos = mpRWStm->Tell() ) + 4UL;
46 mpRWStm->SeekRel( 4L );
47 }
48 else
49 {
50 *mpRWStm >> mnVersion;
51 *mpRWStm >> mnTotalSize;
52 mnCompatPos = mpRWStm->Tell();
53 }
54 }
55 }
56
57 // ------------------------------------------------------------------------
58
~VersionCompat()59 VersionCompat::~VersionCompat()
60 {
61 if( STREAM_WRITE == mnStmMode )
62 {
63 const sal_uInt32 nEndPos = mpRWStm->Tell();
64
65 mpRWStm->Seek( mnCompatPos );
66 *mpRWStm << ( nEndPos - mnTotalSize );
67 mpRWStm->Seek( nEndPos );
68 }
69 else
70 {
71 const sal_uInt32 nReadSize = mpRWStm->Tell() - mnCompatPos;
72
73 if( mnTotalSize > nReadSize )
74 mpRWStm->SeekRel( mnTotalSize - nReadSize );
75 }
76 }
77