xref: /aoo4110/main/sd/source/filter/ppt/pptatom.cpp (revision b1cdbd2c)
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 #ifndef _STREAM_HXX
25 #include <tools/stream.hxx>
26 #endif
27 
28 #ifndef _PPTATOM_HXX_
29 #include "pptatom.hxx"
30 #endif
31 
32 using namespace ppt;
33 
Atom(const DffRecordHeader & rRecordHeader,SvStream & rStream)34 Atom::Atom( const DffRecordHeader& rRecordHeader, SvStream& rStream )
35 : mrStream( rStream )
36 , maRecordHeader( rRecordHeader )
37 , mpFirstChild( 0 )
38 , mpNextAtom( 0 )
39 {
40 	if( isContainer() )
41 	{
42 		if( seekToContent() )
43 		{
44 			DffRecordHeader aChildHeader;
45 
46 			Atom* pLastAtom = NULL;
47 
48 			// retrieve file size (to allow sanity checks)
49 			const sal_Size nStreamPos = mrStream.Tell();
50 			mrStream.Seek( STREAM_SEEK_TO_END );
51 			const sal_Size nStreamSize = mrStream.Tell();
52 			mrStream.Seek( nStreamPos );
53 
54 			while( (mrStream.GetError() == 0 )
55 				&& ( mrStream.Tell() < nStreamSize )
56 				&& ( mrStream.Tell() < maRecordHeader.GetRecEndFilePos() ) )
57 			{
58 				mrStream >> aChildHeader;
59 
60 				if( mrStream.GetError() == 0 )
61 				{
62 					Atom* pAtom = new Atom( aChildHeader, mrStream );
63 
64 					if( pLastAtom )
65 						pLastAtom->mpNextAtom = pAtom;
66 					if( mpFirstChild == NULL )
67 						mpFirstChild = pAtom;
68 
69 					pLastAtom = pAtom;
70 				}
71 			}
72 		}
73 	}
74 
75 	maRecordHeader.SeekToEndOfRecord( mrStream );
76 }
77 
~Atom()78 Atom::~Atom()
79 {
80 	Atom* pChild = mpFirstChild;
81 	while( pChild )
82 	{
83 		Atom* pNextChild = pChild->mpNextAtom;
84 		delete pChild;
85 		pChild = pNextChild;
86 	}
87 }
88 
89 /** imports this atom and its child atoms */
import(const DffRecordHeader & rRootRecordHeader,SvStream & rStCtrl)90 Atom* Atom::import( const DffRecordHeader& rRootRecordHeader, SvStream& rStCtrl )
91 {
92 	Atom* pRootAtom = new Atom( rRootRecordHeader, rStCtrl );
93 
94 	if( rStCtrl.GetError() == 0 )
95 	{
96 		return pRootAtom;
97 	}
98 	else
99 	{
100 		delete pRootAtom;
101 		return NULL;
102 	}
103 }
104 
105 /** returns the next child atom after pLast with nRecType or NULL */
findNextChildAtom(sal_uInt16 nRecType,const Atom * pLast) const106 const Atom* Atom::findNextChildAtom( sal_uInt16 nRecType, const Atom* pLast ) const
107 {
108 	Atom* pChild = pLast != NULL ? pLast->mpNextAtom : mpFirstChild;
109 	while( pChild && pChild->maRecordHeader.nRecType != nRecType )
110 	{
111 		pChild = pChild->mpNextAtom;
112 	}
113 
114 	return pChild;
115 }
116