/src/libreoffice/tools/source/stream/vcompat.cxx
Line | Count | Source |
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/stream.hxx> |
21 | | #include <tools/vcompat.hxx> |
22 | | |
23 | | VersionCompatRead::VersionCompatRead(SvStream& rStm) |
24 | 592k | : mrRStm(rStm) |
25 | 592k | , mnCompatPos(0) |
26 | 592k | , mnTotalSize(0) |
27 | 592k | , mnVersion(1) |
28 | 592k | { |
29 | 592k | if (mrRStm.GetError()) |
30 | 0 | return; |
31 | | |
32 | 592k | mrRStm.ReadUInt16(mnVersion); |
33 | 592k | mrRStm.ReadUInt32(mnTotalSize); |
34 | 592k | mnCompatPos = mrRStm.Tell(); |
35 | 592k | } |
36 | | |
37 | | VersionCompatWrite::VersionCompatWrite(SvStream& rStm, sal_uInt16 nVersion) |
38 | 59.1k | : mrWStm(rStm) |
39 | 59.1k | , mnCompatPos(0) |
40 | 59.1k | , mnTotalSize(0) |
41 | 59.1k | { |
42 | 59.1k | if (mrWStm.GetError()) |
43 | 0 | return; |
44 | | |
45 | 59.1k | mrWStm.WriteUInt16(nVersion); |
46 | 59.1k | mnCompatPos = mrWStm.Tell(); |
47 | 59.1k | mnTotalSize = mnCompatPos + 4; |
48 | 59.1k | mrWStm.SeekRel(4); |
49 | 59.1k | } |
50 | | |
51 | | VersionCompatRead::~VersionCompatRead() |
52 | 592k | { |
53 | 592k | const sal_uInt32 nReadSize = mrRStm.Tell() - mnCompatPos; |
54 | | |
55 | 592k | if (mnTotalSize > nReadSize) |
56 | 37.0k | mrRStm.SeekRel(mnTotalSize - nReadSize); |
57 | 592k | } |
58 | | |
59 | | VersionCompatWrite::~VersionCompatWrite() |
60 | 59.1k | { |
61 | 59.1k | const sal_uInt32 nEndPos = mrWStm.Tell(); |
62 | | |
63 | 59.1k | mrWStm.Seek(mnCompatPos); |
64 | 59.1k | mrWStm.WriteUInt32(nEndPos - mnTotalSize); |
65 | 59.1k | mrWStm.Seek(nEndPos); |
66 | 59.1k | } |
67 | | |
68 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |