LibreOffice Module sd (master) 1
pptatom.cxx
Go to the documentation of this file.
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 "pptatom.hxx"
22
23using namespace ppt;
24
25Atom::Atom( const DffRecordHeader& rRecordHeader, SvStream& rStream )
26: mrStream( rStream )
27, maRecordHeader( rRecordHeader )
28, mpFirstChild( nullptr )
29, mpNextAtom( nullptr )
30{
31 if( isContainer() )
32 {
33 if( seekToContent() )
34 {
35 DffRecordHeader aChildHeader;
36
37 Atom* pLastAtom = nullptr;
38
39 // retrieve file size (to allow sanity checks)
40 sal_uInt64 const nStreamSize = mrStream.TellEnd();
41
42 while( mrStream.good()
43 && ( mrStream.Tell() < nStreamSize )
45 {
46 if (ReadDffRecordHeader(mrStream, aChildHeader))
47 {
48 Atom* pAtom = new Atom( aChildHeader, mrStream );
49
50 if( pLastAtom )
51 pLastAtom->mpNextAtom = pAtom;
52 if( mpFirstChild == nullptr )
53 mpFirstChild = pAtom;
54
55 pLastAtom = pAtom;
56 }
57 }
58 }
59 }
60
63}
64
66{
67 Atom* pChild = mpFirstChild;
68 while( pChild )
69 {
70 Atom* pNextChild = pChild->mpNextAtom;
71 delete pChild;
72 pChild = pNextChild;
73 }
74}
75
77Atom* Atom::import( const DffRecordHeader& rRootRecordHeader, SvStream& rStCtrl )
78{
79 Atom* pRootAtom = new Atom( rRootRecordHeader, rStCtrl );
80
81 if( rStCtrl.GetError() == ERRCODE_NONE )
82 {
83 return pRootAtom;
84 }
85 else
86 {
87 delete pRootAtom;
88 return nullptr;
89 }
90}
91
93const Atom* Atom::findNextChildAtom( sal_uInt16 nRecType, const Atom* pLast ) const
94{
95 Atom* pChild = pLast != nullptr ? pLast->mpNextAtom : mpFirstChild;
96 while( pChild && pChild->maRecordHeader.nRecType != nRecType )
97 {
98 pChild = pChild->mpNextAtom;
99 }
100
101 return pChild;
102}
103
104/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uLong GetRecEndFilePos() const
bool SeekToEndOfRecord(SvStream &rIn) const
sal_uInt16 nRecType
sal_uInt64 Tell() const
bool good() const
virtual sal_uInt64 TellEnd()
void SetError(ErrCode nErrorCode)
ErrCode GetError() const
Atom * mpFirstChild
Definition: pptatom.hxx:69
Atom(const DffRecordHeader &rRecordHeader, SvStream &rStCtrl)
Definition: pptatom.cxx:25
SvStream & mrStream
Definition: pptatom.hxx:67
bool seekToContent() const
seeks to the contents of this atom
Definition: pptatom.hxx:92
Atom * mpNextAtom
Definition: pptatom.hxx:70
static Atom * import(const DffRecordHeader &rRootRecordHeader, SvStream &rStCtrl)
imports this atom and its child atoms
Definition: pptatom.cxx:77
DffRecordHeader maRecordHeader
Definition: pptatom.hxx:68
bool isContainer() const
Definition: pptatom.hxx:90
const Atom * findNextChildAtom(sal_uInt16 nRecType, const Atom *pLast) const
returns the next child atom after pLast with nRecType or NULL
Definition: pptatom.cxx:93
bool ReadDffRecordHeader(SvStream &rIn, DffRecordHeader &rRec)
#define SVSTREAM_FILEFORMAT_ERROR
#define ERRCODE_NONE