xref: /trunk/main/svtools/source/misc/imap3.cxx (revision 5900e8ec)
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_svtools.hxx"
26 
27 
28 #include <svtools/imap.hxx>
29 
30 #include <tools/debug.hxx>
31 
32 
33 /******************************************************************************
34 |*
35 |* Ctor
36 |*
37 \******************************************************************************/
38 
IMapCompat(SvStream & rStm,const sal_uInt16 nStreamMode)39 IMapCompat::IMapCompat( SvStream& rStm, const sal_uInt16 nStreamMode ) :
40 			pRWStm		( &rStm ),
41 			nStmMode	( nStreamMode )
42 {
43 	DBG_ASSERT( nStreamMode == STREAM_READ || nStreamMode == STREAM_WRITE, "Wrong Mode!" );
44 
45 	if ( !pRWStm->GetError() )
46 	{
47 		if ( nStmMode == STREAM_WRITE )
48 		{
49 			nCompatPos = pRWStm->Tell();
50 			pRWStm->SeekRel( 4 );
51 			nTotalSize = nCompatPos + 4;
52 		}
53 		else
54 		{
55 			sal_uInt32 nTotalSizeTmp;
56 			*pRWStm >> nTotalSizeTmp;
57 			nTotalSize = nTotalSizeTmp;
58 			nCompatPos = pRWStm->Tell();
59 		}
60 	}
61 }
62 
63 
64 /******************************************************************************
65 |*
66 |* Dtor
67 |*
68 \******************************************************************************/
69 
~IMapCompat()70 IMapCompat::~IMapCompat()
71 {
72 	if ( !pRWStm->GetError() )
73 	{
74 		if ( nStmMode == STREAM_WRITE )
75 		{
76 			const sal_uLong	nEndPos = pRWStm->Tell();
77 
78 			pRWStm->Seek( nCompatPos );
79 			*pRWStm << (sal_uInt32) ( nEndPos - nTotalSize );
80 			pRWStm->Seek( nEndPos );
81 		}
82 		else
83 		{
84 			const sal_uLong nReadSize = pRWStm->Tell() - nCompatPos;
85 
86 			if ( nTotalSize > nReadSize )
87 				pRWStm->SeekRel( nTotalSize - nReadSize );
88 		}
89 	}
90 }
91 
92 
93 
94