Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <tools/debug.hxx>
21 :
22 : #include "sdiocmpt.hxx"
23 :
24 0 : old_SdrDownCompat::old_SdrDownCompat(SvStream& rNewStream, sal_uInt16 nNewMode)
25 : : rStream(rNewStream),
26 : nSubRecSiz(0),
27 : nSubRecPos(0),
28 : nMode(nNewMode),
29 0 : bOpen(false)
30 : {
31 0 : OpenSubRecord();
32 0 : }
33 :
34 0 : old_SdrDownCompat::~old_SdrDownCompat()
35 : {
36 0 : if(bOpen)
37 0 : CloseSubRecord();
38 0 : }
39 :
40 0 : void old_SdrDownCompat::Read()
41 : {
42 0 : rStream.ReadUInt32( nSubRecSiz );
43 0 : }
44 :
45 0 : void old_SdrDownCompat::Write()
46 : {
47 0 : rStream.WriteUInt32( nSubRecSiz );
48 0 : }
49 :
50 0 : void old_SdrDownCompat::OpenSubRecord()
51 : {
52 0 : if(rStream.GetError())
53 0 : return;
54 :
55 0 : nSubRecPos = rStream.Tell();
56 :
57 0 : if(nMode == STREAM_READ)
58 : {
59 0 : Read();
60 : }
61 0 : else if(nMode == STREAM_WRITE)
62 : {
63 0 : Write();
64 : }
65 :
66 0 : bOpen = true;
67 : }
68 :
69 0 : void old_SdrDownCompat::CloseSubRecord()
70 : {
71 0 : if(rStream.GetError())
72 0 : return;
73 :
74 0 : sal_uInt32 nAktPos(rStream.Tell());
75 :
76 0 : if(nMode == STREAM_READ)
77 : {
78 0 : sal_uInt32 nReadAnz(nAktPos - nSubRecPos);
79 0 : if(nReadAnz != nSubRecSiz)
80 : {
81 0 : rStream.Seek(nSubRecPos + nSubRecSiz);
82 : }
83 : }
84 0 : else if(nMode == STREAM_WRITE)
85 : {
86 0 : nSubRecSiz = nAktPos - nSubRecPos;
87 0 : rStream.Seek(nSubRecPos);
88 0 : Write();
89 0 : rStream.Seek(nAktPos);
90 : }
91 :
92 0 : bOpen = false;
93 : }
94 :
95 : /*************************************************************************
96 : |*
97 : |* Constructor, writes and reads version number
98 : |*
99 : \************************************************************************/
100 :
101 0 : SdIOCompat::SdIOCompat(SvStream& rNewStream, sal_uInt16 nNewMode, sal_uInt16 nVer)
102 0 : : old_SdrDownCompat(rNewStream, nNewMode), nVersion(nVer)
103 : {
104 0 : if (nNewMode == STREAM_WRITE)
105 : {
106 : DBG_ASSERT(nVer != SDIOCOMPAT_VERSIONDONTKNOW,
107 : "canĀ“t write unknown version");
108 0 : rNewStream.WriteUInt16( nVersion );
109 : }
110 0 : else if (nNewMode == STREAM_READ)
111 : {
112 : DBG_ASSERT(nVer == SDIOCOMPAT_VERSIONDONTKNOW,
113 : "referring to the version while reading is silly!");
114 0 : rNewStream.ReadUInt16( nVersion );
115 : }
116 0 : }
117 :
118 0 : SdIOCompat::~SdIOCompat()
119 : {
120 0 : }
121 :
122 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|