LibreOffice Module lotuswordpro (master) 1
bento.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*************************************************************************
3 *
4 * The Contents of this file are made available subject to the terms of
5 * either of the following licenses
6 *
7 * - GNU Lesser General Public License Version 2.1
8 * - Sun Industry Standards Source License Version 1.1
9 *
10 * Sun Microsystems Inc., October, 2000
11 *
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
16 *
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.
20 *
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.
25 *
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,
29 * MA 02111-1307 USA
30 *
31 *
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.
38 *
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.
45 *
46 * The Initial Developer of the Original Code is: IBM Corporation
47 *
48 * Copyright: 2008 by IBM Corporation
49 *
50 * All Rights Reserved.
51 *
52 * Contributor(s): _______________________________________
53 *
54 *
55 ************************************************************************/
56#ifndef INCLUDED_LOTUSWORDPRO_SOURCE_FILTER_BENTO_HXX
57#define INCLUDED_LOTUSWORDPRO_SOURCE_FILTER_BENTO_HXX
58
59#include <sal/config.h>
60
61#include <cstring>
62#include <memory>
63#include <vector>
64#include <lwpsvstream.hxx>
65
66#define BEN_CC __stdcall
67#ifdef COMP_BENTO
68#define BEN_EXPORT __declspec(dllexport)
69#else
70#define BEN_EXPORT
71#endif
72
73#include "utlist.hxx"
74#include <tools/stream.hxx>
75#include <tools/solar.h>
76
77namespace OpenStormBento
78{
79
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
84
85#define BEN_MAGIC_BYTES "\xA4""CM""\xA5""Hdr""\xD7"
86
88{
113
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
121
122class LtcBenContainer;
123class CBenObject;
124class CBenProperty;
125class CBenValue;
126class CBenValueSegment;
127class CBenNamedObject;
128class CBenPropertyName;
129
131typedef sal_uInt16 BenWord;
132typedef sal_uInt32 BenDWord;
133
134typedef sal_uInt32 BenContainerPos;
135typedef sal_uInt32 BenObjectID;
136typedef sal_uInt32 BenGeneration;
137
138sal_uLong BenOpenContainer(LwpSvStream * pStream, std::unique_ptr<LtcBenContainer>* ppContainer);
139
141{
142public: // Internal methods
144 { }
145 explicit CBenIDListElmt(BenObjectID ID) : cID(ID) { }
146 BenObjectID GetID() const { return cID; }
147
148private: // Data
150};
151
153{
154public: // Methods
155 // added to remove warning
157 { cpNamedObject = nullptr; }
159 {
160 cpNamedObject = pObj;
161 }
162
164
165private: // Data
167};
168
170{
171public:
172 explicit LtcUtBenValueStream(CBenValue * pValue);
173 virtual ~LtcUtBenValueStream() override;
174
175public: // Overridden methods
176
177 /* added by */
178 sal_uLong GetSize() const { return m_ulValueLength; };
179protected: // Overridden methods
180
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;
186
187private: // Data
190
191 sal_uLong m_ulValueLength; // Added by , sum of length of all sub-valuesegments
192};
193
195{
196public:
197 BenError Open();
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);
204 BenObjectID PropertyID);
205
206public: // Internal methods
207 explicit LtcBenContainer(LwpSvStream * pStream);
209
210 sal_uLong remainingSize() const;
211 void Read(void * pBuffer, size_t MaxSize,
212 size_t* pAmtRead);
213 BenError ReadKnownSize(void * pBuffer, size_t Amt);
216
220
221 LtcUtBenValueStream * FindNextValueStreamWithPropertyName(const char * sPropertyName);
222 LtcUtBenValueStream * FindValueStreamWithPropertyName(const char * sPropertyName);
223 std::vector<sal_uInt8> GetGraphicData(const char *pObjectName);
224
225 sal_uLong GetSize() const { return m_ulLength; }
226private: // Data
230 sal_uLong m_ulLength; // Added for TOCRead.cpp
232};
233
235{
236public:
238 CBenValue * UseValue(BenObjectID PropertyID);
240public: // Internal methods
241 CBenObject(LtcBenContainer * pContainer, BenObjectID ObjectID,
242 CUtListElmt * pPrev) : CBenIDListElmt(ObjectID, pPrev)
243 { cpContainer = pContainer; }
245
246private: // Data
249};
250
252{
253public:
254 size_t GetValueSize();
255 void ReadValueData(void * pBuffer,
256 size_t Offset, size_t MaxSize, size_t* pAmtRead);
257
259
260public: // Internal methods
261 // added to remove WARNING
262 explicit CBenValue(BenObjectID TypeID):CBenIDListElmt(TypeID)
263 {
264 cpProperty = nullptr;
265 }
266
267 void SetProperty(CBenProperty * pProperty)
268 {
269 cpProperty = pProperty;
270 }
271
273 pCurrValueSegment);
275
276private: // Data
279};
280
282{
283public:
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
287
288 CBenValue& UseValue() { return cValue; }
291
292public: // 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)
297 {
299 cValue.SetProperty(this);
300 }
301private: // Data
304};
305
307{
308public: // Internal methods
310 size_t Size) : CUtListElmt(&pValue->GetValueSegments())
311 { cImmediate = false; cPos = Pos;
312 cSize = Size; }
313 CBenValueSegment(CBenValue * pValue, const void * pImmData,
314 unsigned short Size) : CUtListElmt(&pValue->GetValueSegments())
315 { cImmediate = true;
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; }
321
322private: // Data
324 union
325 {
328 };
329 size_t cSize;
330};
331
333 pCurrValueSegment)
334{ return static_cast<CBenValueSegment *>( cValueSegments.GetNextOrNULL(pCurrValueSegment) ); }
335
336
338{
339public: // Methods
340 virtual bool IsPropertyName();
341
342public: // Internal methods
343 CBenNamedObject(LtcBenContainer * pContainer, BenObjectID ObjectID,
344 CUtListElmt * pPrevObject, OString aName,
345 CUtListElmt * pPrevNamedObjectListElmt);
346
347 const OString& GetName() const { return csName; }
348
349private: // Data
350 OString csName;
352};
353
355{
356public: // Internal methods
358 CUtListElmt * pPrevObject, const OString& rName,
359 CUtListElmt * pPrevNamedObjectListElmt) :
360 CBenNamedObject(pContainer, ObjectID, pPrevObject, rName,
361 pPrevNamedObjectListElmt) { ; }
362 virtual bool IsPropertyName() override;
363};
364
366{
367public: // Internal methods
369 CUtListElmt * pPrevObject, const OString& rName,
370 CUtListElmt * pPrevNamedObjectListElmt) :
371 CBenNamedObject(pContainer, ObjectID, pPrevObject, rName,
372 pPrevNamedObjectListElmt) { ; }
373};
374
375} // end namespace OpenStormBento
376#endif
377
378/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define BEN_EXPORT
Definition: bento.hxx:70
encapsulate XInputStream to provide SvStream like interfaces
Definition: lwpsvstream.hxx:69
BenObjectID GetID() const
Definition: bento.hxx:146
CBenIDListElmt(BenObjectID ID, CUtListElmt *pPrev)
Definition: bento.hxx:143
CBenIDListElmt(BenObjectID ID)
Definition: bento.hxx:145
CBenNamedObjectListElmt(CUtListElmt *pPrev)
Definition: bento.hxx:156
CBenNamedObject * GetNamedObject()
Definition: bento.hxx:163
void SetNamedObject(CBenNamedObject *pObj)
Definition: bento.hxx:158
virtual bool IsPropertyName()
Definition: benname.cxx:73
CBenNamedObject(LtcBenContainer *pContainer, BenObjectID ObjectID, CUtListElmt *pPrevObject, OString aName, CUtListElmt *pPrevNamedObjectListElmt)
Definition: benname.cxx:63
const OString & GetName() const
Definition: bento.hxx:347
CBenNamedObjectListElmt cNameListElmt
Definition: bento.hxx:351
CBenObject(LtcBenContainer *pContainer, BenObjectID ObjectID, CUtListElmt *pPrev)
Definition: bento.hxx:241
CBenProperty * UseProperty(BenObjectID PropertyID)
Definition: benobj.cxx:61
CUtOwningList cProperties
Definition: bento.hxx:248
CUtList & GetProperties()
Definition: bento.hxx:244
LtcBenContainer * cpContainer
Definition: bento.hxx:247
CBenValue * UseValue(BenObjectID PropertyID)
Definition: benobj.cxx:67
LtcBenContainer * GetContainer()
Definition: bento.hxx:239
CBenPropertyName(LtcBenContainer *pContainer, BenObjectID ObjectID, CUtListElmt *pPrevObject, const OString &rName, CUtListElmt *pPrevNamedObjectListElmt)
Definition: bento.hxx:357
virtual bool IsPropertyName() override
Definition: benname.cxx:76
CBenValue & UseValue()
Definition: bento.hxx:288
CBenObject * GetBenObject()
Definition: bento.hxx:289
CBenProperty(CBenObject *pObject, BenObjectID PropertyID, BenObjectID TypeID, CUtListElmt *pPrevProperty)
Definition: bento.hxx:294
LtcBenContainer * GetContainer()
Definition: bento.hxx:290
CBenTypeName(LtcBenContainer *pContainer, BenObjectID ObjectID, CUtListElmt *pPrevObject, const OString &rName, CUtListElmt *pPrevNamedObjectListElmt)
Definition: bento.hxx:368
CBenValueSegment(CBenValue *pValue, BenContainerPos Pos, size_t Size)
Definition: bento.hxx:309
BenContainerPos GetPosition() const
Definition: bento.hxx:318
CBenValueSegment(CBenValue *pValue, const void *pImmData, unsigned short Size)
Definition: bento.hxx:313
void SetProperty(CBenProperty *pProperty)
Definition: bento.hxx:267
CBenProperty *BEN_EXPORT GetProperty()
Definition: bento.hxx:258
CUtOwningList cValueSegments
Definition: bento.hxx:278
CBenProperty * cpProperty
Definition: bento.hxx:277
CBenValue(BenObjectID TypeID)
Definition: bento.hxx:262
void ReadValueData(void *pBuffer, size_t Offset, size_t MaxSize, size_t *pAmtRead)
Definition: benval.cxx:78
CUtList & GetValueSegments()
Definition: bento.hxx:274
CBenValueSegment * GetNextValueSegment(CBenValueSegment const *pCurrValueSegment)
Definition: bento.hxx:332
CUtListElmt * GetNextOrNULL(CUtListElmt const *pCurr)
Definition: utlist.cxx:92
std::vector< sal_uInt8 > GetGraphicData(const char *pObjectName)
Find hazily according to object ID.
Definition: bencont.cxx:272
sal_uLong remainingSize() const
Definition: bencont.cxx:321
BenError ReadKnownSize(void *pBuffer, size_t Amt)
Read buffer from bento file with specified size.
Definition: bencont.cxx:183
sal_uLong GetSize() const
Definition: bento.hxx:225
LtcUtBenValueStream * FindNextValueStreamWithPropertyName(const char *sPropertyName)
Find the next value stream with property name.
Definition: bencont.cxx:214
LtcBenContainer(LwpSvStream *pStream)
Construction.
Definition: bencont.cxx:157
LtcUtBenValueStream * FindValueStreamWithPropertyName(const char *sPropertyName)
Find the unique value stream with property name.
Definition: bencont.cxx:242
CBenObject * GetNextObject(CBenObject const *pCurrObject)
Definition: bencont.cxx:136
void SeekToPosition(BenContainerPos Pos)
Seek to position from the beginning of the bento file.
Definition: bencont.cxx:196
CBenObject * FindNextObjectWithProperty(CBenObject *pCurrObject, BenObjectID PropertyID)
Definition: bencont.cxx:142
void RegisterPropertyName(const char *sPropertyName, CBenPropertyName **ppPropertyName)
Definition: bencont.cxx:110
void SetNextAvailObjectID(BenObjectID ID)
Definition: bento.hxx:217
void Read(void *pBuffer, size_t MaxSize, size_t *pAmtRead)
Read buffer for bento file with specified buffer.
Definition: bencont.cxx:172
void SeekFromEnd(tools::Long Offset)
Seek to position compare to end of bento file.
Definition: bencont.cxx:204
virtual void FlushData() override
Flush data function, not supported now.
Definition: utbenvs.cxx:114
LtcUtBenValueStream(CBenValue *pValue)
Construction.
Definition: utbenvs.cxx:125
virtual sal_uInt64 SeekPos(sal_uInt64 nPos) override
Seek function of value stream.
Definition: utbenvs.cxx:93
virtual void SetSize(sal_uInt64 nSize) override
Set buffer size function.
Definition: utbenvs.cxx:106
virtual std::size_t PutData(const void *pData, std::size_t nSize) override
Value stream write function, not supported now.
Definition: utbenvs.cxx:81
virtual std::size_t GetData(void *pData, std::size_t nSize) override
Value stream read function.
Definition: utbenvs.cxx:66
virtual ~LtcUtBenValueStream() override
Definition: utbenvs.cxx:134
EmbeddedObjectRef * pObject
OUString aName
sal_uLong BenOpenContainer(LwpSvStream *pStream, std::unique_ptr< LtcBenContainer > *ppContainer)
New bento container from file stream.
Definition: bencont.cxx:74
@ BenErr_IllegalContinuedImmediate
Definition: bento.hxx:110
@ BenErr_DuplicateObjectID
Definition: bento.hxx:91
@ BenErr_InvalidTOC
Definition: bento.hxx:95
@ BenErr_DuplicateName
Definition: bento.hxx:108
@ BenErr_IllegalInMemoryTOC
Definition: bento.hxx:101
@ BenErr_NotBentoContainer
Definition: bento.hxx:111
@ BenErr_64BitOffsetNotSupported
Definition: bento.hxx:96
@ BenErr_PropertyAlreadyExists
Definition: bento.hxx:102
@ BenErr_PropertyWithMoreThanOneValue
Definition: bento.hxx:112
@ BenErr_UnknownBentoFormatVersion
Definition: bento.hxx:92
@ BenErr_ContainerWithNoObjects
Definition: bento.hxx:98
@ BenErr_TOCSeedError
Definition: bento.hxx:106
@ BenErr_InvalidWriteOffset
Definition: bento.hxx:104
@ BenErr_UnexpectedEndOfFile
Definition: bento.hxx:103
@ BenErr_InvalidImmediateWrite
Definition: bento.hxx:105
@ BenErr_ObjectWithNoProperties
Definition: bento.hxx:99
@ BenErr_NameConflict
Definition: bento.hxx:90
@ BenErr_NamedObjectError
Definition: bento.hxx:93
@ BenErr_PropertyWithNoValues
Definition: bento.hxx:100
@ BenErr_ReadPastEndOfTOC
Definition: bento.hxx:97
@ BenErr_ReadPastEndOfContainer
Definition: bento.hxx:107
@ BenErr_NamedObjectIllegalValue
Definition: bento.hxx:94
@ BenErr_BadReferencedList
Definition: bento.hxx:109
sal_uInt32 BenContainerPos
Definition: bento.hxx:134
sal_uInt8 BenByte
Definition: bento.hxx:128
sal_uInt32 BenDWord
Definition: bento.hxx:132
sal_uInt16 BenWord
Definition: bento.hxx:131
sal_uInt32 BenObjectID
Definition: bento.hxx:135
sal_uInt32 BenGeneration
Definition: bento.hxx:136
long Long
sal_uIntPtr sal_uLong
unsigned char sal_uInt8