xref: /trunk/main/sd/source/core/sdiocmpt.cxx (revision 79aad27f)
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_sd.hxx"
26 
27 
28 #include <tools/debug.hxx>
29 
30 #include "sdiocmpt.hxx"
31 
32 //////////////////////////////////////////////////////////////////////////////
33 
old_SdrDownCompat(SvStream & rNewStream,sal_uInt16 nNewMode)34 old_SdrDownCompat::old_SdrDownCompat(SvStream& rNewStream, sal_uInt16 nNewMode)
35 :	rStream(rNewStream),
36 	nSubRecSiz(0),
37 	nSubRecPos(0),
38 	nMode(nNewMode),
39 	bOpen(sal_False)
40 {
41 	OpenSubRecord();
42 }
43 
~old_SdrDownCompat()44 old_SdrDownCompat::~old_SdrDownCompat()
45 {
46 	if(bOpen)
47 		CloseSubRecord();
48 }
49 
Read()50 void old_SdrDownCompat::Read()
51 {
52 	rStream >> nSubRecSiz;
53 }
54 
Write()55 void old_SdrDownCompat::Write()
56 {
57 	rStream << nSubRecSiz;
58 }
59 
OpenSubRecord()60 void old_SdrDownCompat::OpenSubRecord()
61 {
62 	if(rStream.GetError())
63 		return;
64 
65 	nSubRecPos = rStream.Tell();
66 
67 	if(nMode == STREAM_READ)
68 	{
69 		Read();
70 	}
71 	else if(nMode == STREAM_WRITE)
72 	{
73 		Write();
74 	}
75 
76 	bOpen = sal_True;
77 }
78 
CloseSubRecord()79 void old_SdrDownCompat::CloseSubRecord()
80 {
81 	if(rStream.GetError())
82 		return;
83 
84 	sal_uInt32 nAktPos(rStream.Tell());
85 
86 	if(nMode == STREAM_READ)
87 	{
88 		sal_uInt32 nReadAnz(nAktPos - nSubRecPos);
89 		if(nReadAnz != nSubRecSiz)
90 		{
91 			rStream.Seek(nSubRecPos + nSubRecSiz);
92 		}
93 	}
94 	else if(nMode == STREAM_WRITE)
95 	{
96 		nSubRecSiz = nAktPos - nSubRecPos;
97 		rStream.Seek(nSubRecPos);
98 		Write();
99 		rStream.Seek(nAktPos);
100 	}
101 
102 	bOpen = sal_False;
103 }
104 
105 /*************************************************************************
106 |*
107 |* Konstruktor, schreibt bzw. liest Versionsnummer
108 |*
109 \************************************************************************/
110 
SdIOCompat(SvStream & rNewStream,sal_uInt16 nNewMode,sal_uInt16 nVer)111 SdIOCompat::SdIOCompat(SvStream& rNewStream, sal_uInt16 nNewMode, sal_uInt16 nVer)
112 :	old_SdrDownCompat(rNewStream, nNewMode), nVersion(nVer)
113 {
114 	if (nNewMode == STREAM_WRITE)
115 	{
116 		DBG_ASSERT(nVer != SDIOCOMPAT_VERSIONDONTKNOW,
117 				   "kann unbekannte Version nicht schreiben");
118 		rNewStream << nVersion;
119 	}
120 	else if (nNewMode == STREAM_READ)
121 	{
122 		DBG_ASSERT(nVer == SDIOCOMPAT_VERSIONDONTKNOW,
123 				   "Lesen mit Angabe der Version ist Quatsch!");
124 		rNewStream >> nVersion;
125 	}
126 }
127 
~SdIOCompat()128 SdIOCompat::~SdIOCompat()
129 {
130 }
131 
132 // eof
133