1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * The Contents of this file are made available subject to the terms of
5 * either of the following licenses
7 * - GNU Lesser General Public License Version 2.1
8 * - Sun Industry Standards Source License Version 1.1
10 * Sun Microsystems Inc., October, 2000
12 * GNU Lesser General Public License Version 2.1
13 * =============================================
14 * Copyright 2000 by Sun Microsystems, Inc.
15 * 901 San Antonio Road, Palo Alto, CA 94303, USA
17 * This library is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU Lesser General Public
19 * License version 2.1, as published by the Free Software Foundation.
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * Lesser General Public License for more details.
26 * You should have received a copy of the GNU Lesser General Public
27 * License along with this library; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32 * Sun Industry Standards Source License Version 1.1
33 * =================================================
34 * The contents of this file are subject to the Sun Industry Standards
35 * Source License Version 1.1 (the "License"); You may not use this file
36 * except in compliance with the License. You may obtain a copy of the
37 * License at http://www.openoffice.org/license.html.
39 * Software provided under this License is provided on an "AS IS" basis,
40 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
41 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
42 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
43 * See the License for the specific provisions governing your rights and
44 * obligations concerning the Software.
46 * The Initial Developer of the Original Code is: IBM Corporation
48 * Copyright: 2008 by IBM Corporation
50 * All Rights Reserved.
52 * Contributor(s): _______________________________________
55 ************************************************************************/
56 #ifndef INCLUDED_LOTUSWORDPRO_SOURCE_FILTER_BENTO_HXX
57 #define INCLUDED_LOTUSWORDPRO_SOURCE_FILTER_BENTO_HXX
59 #include <sal/config.h>
64 #include <lwpsvstream.hxx>
66 #define BEN_CC __stdcall
68 #define BEN_EXPORT __declspec(dllexport)
74 #include <tools/stream.hxx>
75 #include <tools/solar.h>
77 namespace OpenStormBento
80 #define BEN_CURR_MAJOR_VERSION 2
81 #define BEN_CURR_MINOR_VERSION 0
82 #define BEN_MAGIC_BYTES_SIZE 8
83 #define BEN_LABEL_SIZE 24
85 #define BEN_MAGIC_BYTES "\xA4""CM""\xA5""Hdr""\xD7"
90 BenErr_NameConflict
= 1,
91 BenErr_DuplicateObjectID
= 2,
92 BenErr_UnknownBentoFormatVersion
= 3,
93 BenErr_NamedObjectError
= 4,
94 BenErr_NamedObjectIllegalValue
= 5,
95 BenErr_InvalidTOC
= 6,
96 BenErr_64BitOffsetNotSupported
= 7,
97 BenErr_ReadPastEndOfTOC
= 8,
98 BenErr_ContainerWithNoObjects
= 9,
99 BenErr_ObjectWithNoProperties
= 10,
100 BenErr_PropertyWithNoValues
= 11,
101 BenErr_IllegalInMemoryTOC
= 12,
102 BenErr_PropertyAlreadyExists
= 13,
103 BenErr_UnexpectedEndOfFile
= 14,
104 BenErr_InvalidWriteOffset
= 15,
105 BenErr_InvalidImmediateWrite
= 16,
106 BenErr_TOCSeedError
= 17,
107 BenErr_ReadPastEndOfContainer
= 18,
108 BenErr_DuplicateName
= 19,
109 BenErr_BadReferencedList
= 20,
110 BenErr_IllegalContinuedImmediate
= 21,
111 BenErr_NotBentoContainer
= 22,
112 BenErr_PropertyWithMoreThanOneValue
= 23
114 // IMPORTANT - UtStream errors (UtErr_...) are also valid Bento
115 // errors. They have codes of 100 and higher. When, say, a Bento
116 // container open fails due to an access violation (somebody else, say,
117 // has it open exclusive), will get a UtErr code. If define own
118 // subclass of UtStream (custom handler), can define own error codes--
119 // those should start at 200
122 class LtcBenContainer
;
126 class CBenValueSegment
;
127 class CBenNamedObject
;
128 class CBenPropertyName
;
130 typedef sal_uInt8 BenByte
;
131 typedef sal_uInt16 BenWord
;
132 typedef sal_uInt32 BenDWord
;
134 typedef sal_uInt32 BenContainerPos
;
135 typedef sal_uInt32 BenObjectID
;
136 typedef sal_uInt32 BenGeneration
;
138 BenError
BenOpenContainer(LwpSvStream
* pStream
, std::unique_ptr
<LtcBenContainer
>* ppContainer
);
140 class CBenIDListElmt
: public CUtListElmt
142 public: // Internal methods
143 CBenIDListElmt(BenObjectID ID
, CUtListElmt
* pPrev
) : CUtListElmt(pPrev
), cID(ID
)
145 explicit CBenIDListElmt(BenObjectID ID
) : cID(ID
) { }
146 BenObjectID
GetID() const { return cID
; }
152 class CBenNamedObjectListElmt
: public CUtListElmt
155 // added to remove warning
156 explicit CBenNamedObjectListElmt(CUtListElmt
* pPrev
) : CUtListElmt(pPrev
)
157 { cpNamedObject
= nullptr; }
158 void SetNamedObject(CBenNamedObject
* pObj
)
160 cpNamedObject
= pObj
;
163 CBenNamedObject
* GetNamedObject() { return cpNamedObject
; }
166 CBenNamedObject
* cpNamedObject
;
169 class LtcUtBenValueStream
: public SvStream
172 explicit LtcUtBenValueStream(CBenValue
* pValue
);
173 virtual ~LtcUtBenValueStream() override
;
175 public: // Overridden methods
178 sal_uInt64
GetSize() const { return m_ulValueLength
; };
179 protected: // Overridden methods
181 virtual std::size_t GetData(void* pData
, std::size_t nSize
) override
;
182 virtual std::size_t PutData(const void* pData
, std::size_t nSize
) override
;
183 virtual sal_uInt64
SeekPos( sal_uInt64 nPos
) override
;
184 virtual void SetSize( sal_uInt64 nSize
) override
;
185 virtual void FlushData() override
;
189 size_t cCurrentPosition
;
191 sal_uInt64 m_ulValueLength
; // Added by , sum of length of all sub-valuesegments
194 class LtcBenContainer
198 void RegisterPropertyName(const char * sPropertyName
,
199 CBenPropertyName
** ppPropertyName
);
200 // Pass NULL to begin iteration. Done when returns NULL.
201 // Objects are returned in order of increasing ID
202 CBenObject
* GetNextObject(CBenObject
const * pCurrObject
);
203 CBenObject
* FindNextObjectWithProperty(CBenObject
* pCurrObject
,
204 BenObjectID PropertyID
);
206 public: // Internal methods
207 explicit LtcBenContainer(LwpSvStream
* pStream
);
210 sal_uInt64
remainingSize() const;
211 void Read(void * pBuffer
, size_t MaxSize
,
213 BenError
ReadKnownSize(void * pBuffer
, size_t Amt
);
214 void SeekToPosition(BenContainerPos Pos
);
215 void SeekFromEnd(tools::Long Offset
);
217 void SetNextAvailObjectID(BenObjectID ID
) { cNextAvailObjectID
= ID
; }
218 CUtList
& GetObjects() { return cObjects
; }
219 CUtList
& GetNamedObjects() { return cNamedObjects
; }
221 LtcUtBenValueStream
* FindNextValueStreamWithPropertyName(const char * sPropertyName
);
222 LtcUtBenValueStream
* FindValueStreamWithPropertyName(const char * sPropertyName
);
223 std::vector
<sal_uInt8
> GetGraphicData(const char *pObjectName
);
225 sal_uInt64
GetSize() const { return m_ulLength
; }
227 CUtOwningList cObjects
;
228 CUtList cNamedObjects
;
229 LwpSvStream
* cpStream
;
230 sal_uInt64 m_ulLength
; // Added for TOCRead.cpp
231 BenObjectID cNextAvailObjectID
; // for new object
234 class CBenObject
: public CBenIDListElmt
237 CBenProperty
* UseProperty(BenObjectID PropertyID
);
238 CBenValue
* UseValue(BenObjectID PropertyID
);
239 LtcBenContainer
* GetContainer() { return cpContainer
; }
240 public: // Internal methods
241 CBenObject(LtcBenContainer
* pContainer
, BenObjectID ObjectID
,
242 CUtListElmt
* pPrev
) : CBenIDListElmt(ObjectID
, pPrev
)
243 { cpContainer
= pContainer
; }
244 CUtList
& GetProperties() { return cProperties
; }
247 LtcBenContainer
* cpContainer
;
248 CUtOwningList cProperties
;
251 class CBenValue
: public CBenIDListElmt
254 size_t GetValueSize();
255 void ReadValueData(void * pBuffer
,
256 size_t Offset
, size_t MaxSize
, size_t* pAmtRead
);
258 CBenProperty
* BEN_EXPORT
GetProperty() { return cpProperty
; }
260 public: // Internal methods
261 // added to remove WARNING
262 explicit CBenValue(BenObjectID TypeID
):CBenIDListElmt(TypeID
)
264 cpProperty
= nullptr;
267 void SetProperty(CBenProperty
* pProperty
)
269 cpProperty
= pProperty
;
272 inline CBenValueSegment
* GetNextValueSegment(CBenValueSegment
const *
274 CUtList
& GetValueSegments() { return cValueSegments
; }
277 CBenProperty
* cpProperty
;
278 CUtOwningList cValueSegments
;
281 class CBenProperty
: public CBenIDListElmt
284 // In the Apple Bento, a property can have multiple values, each of a
285 // different type. But we never use it that way, so in this code a
286 // property has exactly one value
288 CBenValue
& UseValue() { return cValue
; }
289 CBenObject
* GetBenObject() { return cpObject
; }
290 LtcBenContainer
* GetContainer() { return GetBenObject()->GetContainer(); }
292 public: // Internal methods
293 // changed to remove WARNING here
294 CBenProperty(CBenObject
* pObject
, BenObjectID PropertyID
,
295 BenObjectID TypeID
, CUtListElmt
* pPrevProperty
) :
296 CBenIDListElmt(PropertyID
, pPrevProperty
), cValue(TypeID
)
299 cValue
.SetProperty(this);
302 CBenObject
* cpObject
;
306 class CBenValueSegment
: public CUtListElmt
308 public: // Internal methods
309 CBenValueSegment(CBenValue
* pValue
, BenContainerPos Pos
,
310 size_t Size
) : CUtListElmt(&pValue
->GetValueSegments())
311 { cImmediate
= false; cPos
= Pos
;
313 CBenValueSegment(CBenValue
* pValue
, const void * pImmData
,
314 unsigned short Size
) : CUtListElmt(&pValue
->GetValueSegments())
316 std::memcpy(cImmData
, pImmData
, Size
); cSize
= Size
; }
317 bool IsImmediate() const { return cImmediate
; }
318 BenContainerPos
GetPosition() const { return cPos
; }
319 size_t GetSize() const { return cSize
; }
320 BenByte
* GetImmediateData() { return cImmData
; }
326 BenContainerPos cPos
;
332 inline CBenValueSegment
* CBenValue::GetNextValueSegment(CBenValueSegment
const *
334 { return static_cast<CBenValueSegment
*>( cValueSegments
.GetNextOrNULL(pCurrValueSegment
) ); }
337 class CBenNamedObject
: public CBenObject
340 virtual bool IsPropertyName();
342 public: // Internal methods
343 CBenNamedObject(LtcBenContainer
* pContainer
, BenObjectID ObjectID
,
344 CUtListElmt
* pPrevObject
, OString aName
,
345 CUtListElmt
* pPrevNamedObjectListElmt
);
347 const OString
& GetName() const { return csName
; }
351 CBenNamedObjectListElmt cNameListElmt
;
354 class CBenPropertyName
: public CBenNamedObject
356 public: // Internal methods
357 CBenPropertyName(LtcBenContainer
* pContainer
, BenObjectID ObjectID
,
358 CUtListElmt
* pPrevObject
, const OString
& rName
,
359 CUtListElmt
* pPrevNamedObjectListElmt
) :
360 CBenNamedObject(pContainer
, ObjectID
, pPrevObject
, rName
,
361 pPrevNamedObjectListElmt
) { ; }
362 virtual bool IsPropertyName() override
;
365 class CBenTypeName
: public CBenNamedObject
367 public: // Internal methods
368 CBenTypeName(LtcBenContainer
* pContainer
, BenObjectID ObjectID
,
369 CUtListElmt
* pPrevObject
, const OString
& rName
,
370 CUtListElmt
* pPrevNamedObjectListElmt
) :
371 CBenNamedObject(pContainer
, ObjectID
, pPrevObject
, rName
,
372 pPrevNamedObjectListElmt
) { ; }
375 } // end namespace OpenStormBento
378 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */