xref: /trunk/main/sd/source/core/sdiocmpt.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sd.hxx"
30 
31 
32 #include <tools/debug.hxx>
33 
34 #include "sdiocmpt.hxx"
35 
36 //////////////////////////////////////////////////////////////////////////////
37 
38 old_SdrDownCompat::old_SdrDownCompat(SvStream& rNewStream, sal_uInt16 nNewMode)
39 :   rStream(rNewStream),
40     nSubRecSiz(0),
41     nSubRecPos(0),
42     nMode(nNewMode),
43     bOpen(sal_False)
44 {
45     OpenSubRecord();
46 }
47 
48 old_SdrDownCompat::~old_SdrDownCompat()
49 {
50     if(bOpen)
51         CloseSubRecord();
52 }
53 
54 void old_SdrDownCompat::Read()
55 {
56     rStream >> nSubRecSiz;
57 }
58 
59 void old_SdrDownCompat::Write()
60 {
61     rStream << nSubRecSiz;
62 }
63 
64 void old_SdrDownCompat::OpenSubRecord()
65 {
66     if(rStream.GetError())
67         return;
68 
69     nSubRecPos = rStream.Tell();
70 
71     if(nMode == STREAM_READ)
72     {
73         Read();
74     }
75     else if(nMode == STREAM_WRITE)
76     {
77         Write();
78     }
79 
80     bOpen = sal_True;
81 }
82 
83 void old_SdrDownCompat::CloseSubRecord()
84 {
85     if(rStream.GetError())
86         return;
87 
88     sal_uInt32 nAktPos(rStream.Tell());
89 
90     if(nMode == STREAM_READ)
91     {
92         sal_uInt32 nReadAnz(nAktPos - nSubRecPos);
93         if(nReadAnz != nSubRecSiz)
94         {
95             rStream.Seek(nSubRecPos + nSubRecSiz);
96         }
97     }
98     else if(nMode == STREAM_WRITE)
99     {
100         nSubRecSiz = nAktPos - nSubRecPos;
101         rStream.Seek(nSubRecPos);
102         Write();
103         rStream.Seek(nAktPos);
104     }
105 
106     bOpen = sal_False;
107 }
108 
109 /*************************************************************************
110 |*
111 |* Konstruktor, schreibt bzw. liest Versionsnummer
112 |*
113 \************************************************************************/
114 
115 SdIOCompat::SdIOCompat(SvStream& rNewStream, sal_uInt16 nNewMode, sal_uInt16 nVer)
116 :   old_SdrDownCompat(rNewStream, nNewMode), nVersion(nVer)
117 {
118     if (nNewMode == STREAM_WRITE)
119     {
120         DBG_ASSERT(nVer != SDIOCOMPAT_VERSIONDONTKNOW,
121                    "kann unbekannte Version nicht schreiben");
122         rNewStream << nVersion;
123     }
124     else if (nNewMode == STREAM_READ)
125     {
126         DBG_ASSERT(nVer == SDIOCOMPAT_VERSIONDONTKNOW,
127                    "Lesen mit Angabe der Version ist Quatsch!");
128         rNewStream >> nVersion;
129     }
130 }
131 
132 SdIOCompat::~SdIOCompat()
133 {
134 }
135 
136 // eof
137