Bump version to 4.3-4
[LibreOffice.git] / lotuswordpro / source / filter / bento.hxx
blob1940e16d7a1019584c117f66546e96dc2db47cf3
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,
29 * MA 02111-1307 USA
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 <string>
60 #include <vector>
61 #include "lwpsvstream.hxx"
63 #define BEN_CC __stdcall
64 #ifdef COMP_BENTO
65 #define BEN_EXPORT __declspec(dllexport)
66 #else
67 #define BEN_EXPORT
68 #endif
70 #include "ut.hxx"
71 #include "utlist.hxx"
72 #include <tools/stream.hxx>
73 #include <sot/storage.hxx>
75 namespace OpenStormBento
78 #define BEN_CURR_MAJOR_VERSION 2
79 #define BEN_CURR_MINOR_VERSION 0
80 #define BEN_MAGIC_BYTES_SIZE 8
81 #define BEN_LABEL_SIZE 24
83 #define BEN_MAGIC_BYTES "\xA4""CM""\xA5""Hdr""\xD7"
85 enum BenError
87 BenErr_OK = 0,
88 BenErr_NameConflict = 1,
89 BenErr_DuplicateObjectID = 2,
90 BenErr_UnknownBentoFormatVersion = 3,
91 BenErr_NamedObjectError = 4,
92 BenErr_NamedObjectIllegalValue = 5,
93 BenErr_InvalidTOC = 6,
94 BenErr_64BitOffsetNotSupported = 7,
95 BenErr_ReadPastEndOfTOC = 8,
96 BenErr_ContainerWithNoObjects = 9,
97 BenErr_ObjectWithNoProperties = 10,
98 BenErr_PropertyWithNoValues = 11,
99 BenErr_IllegalInMemoryTOC = 12,
100 BenErr_PropertyAlreadyExists = 13,
101 BenErr_UnexpectedEndOfFile = 14,
102 BenErr_InvalidWriteOffset = 15,
103 BenErr_InvalidImmediateWrite = 16,
104 BenErr_TOCSeedError = 17,
105 BenErr_ReadPastEndOfContainer = 18,
106 BenErr_DuplicateName = 19,
107 BenErr_BadReferencedList = 20,
108 BenErr_IllegalContinuedImmediate = 21,
109 BenErr_NotBentoContainer = 22,
110 BenErr_PropertyWithMoreThanOneValue = 23
112 // IMPORTANT - UtStream errors (UtErr_....) are also valid Bento
113 // errors. They have codes of 100 and higher. When, say, a Bento
114 // container open fails due to an access violation (somebody else, say,
115 // has it open exclusive), will get a UtErr code. If define own
116 // subclass of UtStream (custom handler), can define own error codes--
117 // those should start at 200
120 UtDefClassP(LtcBenContainer);
121 UtDefClassP(CBenIDListElmt);
122 UtDefClassP(CBenObject);
123 UtDefClassP(CBenProperty);
124 UtDefClassP(CBenReference);
125 UtDefClassP(CBenValue);
126 UtDefClassP(CBenValueSegment);
127 UtDefClassP(CBenNamedObjectListElmt);
128 UtDefClassP(CBenNamedObject);
129 UtDefClassP(CBenPropertyName);
130 UtDefClassP(CBenTypeName);
132 typedef unsigned char BenByte;
133 typedef unsigned short BenWord;
134 typedef unsigned long BenDWord;
135 typedef void * BenDataPtr;
136 typedef const void * BenConstDataPtr;
138 typedef unsigned long BenContainerPos;
139 typedef unsigned long BenObjectID;
140 typedef unsigned long BenGeneration;
142 sal_uLong BenOpenContainer(LwpSvStream * pStream, pLtcBenContainer * ppContainer);
144 class CBenIDListElmt : public CUtListElmt
146 public: // Internal methods
147 CBenIDListElmt(BenObjectID ID, pCBenIDListElmt pPrev) : CUtListElmt(pPrev)
148 { cID = ID; }
149 CBenIDListElmt(BenObjectID ID) { cID = ID; }
150 BenObjectID GetID() { return cID; }
152 private: // Data
153 BenObjectID cID;
156 class CBenNamedObjectListElmt : public CUtListElmt
158 public: // Methods
159 // added to remove warning
160 CBenNamedObjectListElmt(pCBenNamedObjectListElmt pPrev) : CUtListElmt(pPrev)
161 { cpNamedObject = NULL; }
162 void SetNamedObject(pCBenNamedObject pObj)
164 cpNamedObject = pObj;
167 CBenNamedObjectListElmt(pCBenNamedObject pNamedObject,
168 pCBenNamedObjectListElmt pPrev) : CUtListElmt(pPrev)
169 { cpNamedObject = pNamedObject; }
170 pCBenNamedObject GetNamedObject() { return cpNamedObject; }
172 private: // Data
173 pCBenNamedObject cpNamedObject;
176 class LtcUtBenValueStream : public SvStream
178 public:
179 LtcUtBenValueStream(pCBenValue pValue);
180 virtual ~LtcUtBenValueStream();
182 public: // Overridden methods
184 /* added by */
185 CBenValue * GetValue(){ return cpValue; };
186 sal_uLong GetSize() { return m_ulValueLength; };
187 protected: // Overridden methods
189 virtual sal_uLong GetData( void* pData, sal_uLong nSize ) SAL_OVERRIDE;
190 virtual sal_uLong PutData( const void* pData, sal_uLong nSize ) SAL_OVERRIDE;
191 virtual sal_uInt64 SeekPos( sal_uInt64 nPos ) SAL_OVERRIDE;
192 virtual void SetSize( sal_uInt64 nSize ) SAL_OVERRIDE;
193 virtual void FlushData() SAL_OVERRIDE;
195 private: // Data
196 pCBenValue cpValue;
197 unsigned long cCurrentPosition;
199 sal_uLong m_ulValueLength; // Added by , sum of length of all sub-valuesegments
200 // void GetAmountLeft(sal_uLong * pAmtLeft); useless in SODC
203 class LtcBenContainer
205 public:
206 BenError Open();
207 BenError Close();
208 BenError RegisterPropertyName(const char * sPropertyName,
209 pCBenPropertyName * ppPropertyName);
210 // Pass NULL to begin iteration. Done when returns NULL.
211 // Objects are returned in order of increasing ID
212 pCBenObject GetNextObject(pCBenObject pCurrObject);
213 pCBenObject FindNextObjectWithProperty(pCBenObject pCurrObject,
214 BenObjectID PropertyID);
216 public: // Internal methods
217 LtcBenContainer(LwpSvStream * pStream);
218 ~LtcBenContainer();
220 BenError Read(BenDataPtr pBuffer, unsigned long MaxSize,
221 unsigned long * pAmtRead);
222 BenError ReadKnownSize(BenDataPtr pBuffer, unsigned long Amt);
223 BenError SeekToPosition(BenContainerPos Pos);
224 BenError SeekFromEnd(long Offset);
226 BenObjectID GetNextAvailObjectID() { return cNextAvailObjectID; }
227 void SetNextAvailObjectID(BenObjectID ID) { cNextAvailObjectID = ID; }
228 pCUtList GetObjects() { return &cObjects; }
229 pCUtList GetNamedObjects() { return &cNamedObjects; }
231 LtcUtBenValueStream * FindNextValueStreamWithPropertyName(const char * sPropertyName, LtcUtBenValueStream * pCurrentValueStream);
232 LtcUtBenValueStream * FindValueStreamWithPropertyName(const char * sPropertyName);
233 BenError CreateGraphicStream(SvStream * &pStream, const char *pObjectName);
235 BenError GetSize(sal_uLong * pLength);
236 LwpSvStream * GetStream()
238 return cpStream;
240 private: // Data
241 CUtOwningList cObjects;
242 CUtList cNamedObjects;
243 LwpSvStream * cpStream;
244 sal_uLong m_ulLength; // Added for TOCRead.cpp
245 BenObjectID cNextAvailObjectID; // for new object
248 class CBenObject : public CBenIDListElmt
250 public:
251 pCBenProperty UseProperty(BenObjectID PropertyID);
252 pCBenValue UseValue(BenObjectID PropertyID);
253 virtual bool IsNamedObject();
254 pLtcBenContainer GetContainer() { return cpContainer; }
255 BenObjectID GetObjectID() { return GetID(); }
256 public: // Internal methods
257 CBenObject(pLtcBenContainer pContainer, BenObjectID ObjectID,
258 pCBenIDListElmt pPrev) : CBenIDListElmt(ObjectID, pPrev)
259 { cpContainer = pContainer; }
260 pCUtList GetProperties() { return &cProperties; }
262 private: // Data
263 pLtcBenContainer cpContainer;
264 CUtOwningList cProperties;
267 class CBenValue : public CBenIDListElmt
269 public:
270 unsigned long GetValueSize();
271 BenError ReadValueData(BenDataPtr pBuffer,
272 unsigned long Offset, unsigned long MaxSize, unsigned long * pAmtRead);
274 pCBenProperty BEN_EXPORT GetProperty() { return cpProperty; }
276 public: // Internal methods
277 // added to remove WARNING
278 CBenValue(BenObjectID TypeID):CBenIDListElmt(TypeID)
280 cpProperty = NULL;
281 cpReferencedList = NULL;
284 void SetProperty(pCBenProperty pProperty)
286 cpProperty = pProperty;
289 CBenValue(pCBenProperty pProperty, BenObjectID TypeID) :
290 CBenIDListElmt(TypeID)
292 cpProperty = pProperty;
293 cpReferencedList = NULL;
295 BenObjectID GetTypeNameID() { return GetID(); }
296 inline pCBenValueSegment GetNextValueSegment(pCBenValueSegment
297 pCurrValueSegment);
298 inline pLtcBenContainer GetContainer();
299 pCUtList GetValueSegments() { return &cValueSegments; }
300 // Currently, no generation support
301 BenGeneration GetGeneration() { return 1; }
303 private: // Data
304 pCBenProperty cpProperty;
305 CUtOwningList cValueSegments;
306 pCBenValue cpReferencedList;
309 class CBenProperty : public CBenIDListElmt
311 public:
312 // In the Apple Bento, a property can have multiple values, each of a
313 // different type. But we never use it that way, so in this code a
314 // property has exactly one value
316 pCBenValue UseValue() { return &cValue; }
317 pCBenObject GetBenObject() { return cpObject; }
318 pLtcBenContainer GetContainer() { return GetBenObject()->GetContainer(); }
320 public: // Internal methods
321 // changed to remove WARNING here
322 CBenProperty(pCBenObject pObject, BenObjectID PropertyID,
323 BenObjectID TypeID, pCBenIDListElmt pPrevProperty) :
324 CBenIDListElmt(PropertyID, pPrevProperty), cValue(TypeID)
326 cpObject = pObject;
327 cValue.SetProperty(this);
330 BenObjectID GetPropertyNameID() { return GetID(); }
332 private: // Data
333 pCBenObject cpObject;
334 CBenValue cValue;
337 // In our implementation, reference is always just the object ID for the
338 // object referenced (but you shouldn't assume that)
339 #define BEN_REFERENCE_SIZE 4
341 class CBenReference
343 public: // Methods
344 BenByte * GetData() { return cData; }
346 private: // Data
347 BenByte cData[BEN_REFERENCE_SIZE];
350 class CBenValueSegment : public CUtListElmt
352 public: // Internal methods
353 CBenValueSegment(pCBenValue pValue, BenContainerPos Pos,
354 unsigned long Size) : CUtListElmt(pValue->GetValueSegments())
355 { cpValue = pValue; cImmediate = false; cPos = Pos;
356 cSize = Size; }
357 CBenValueSegment(pCBenValue pValue, BenConstDataPtr pImmData,
358 unsigned short Size) : CUtListElmt(pValue->GetValueSegments())
359 { cpValue = pValue; cImmediate = true;
360 UtHugeMemcpy(cImmData, pImmData, Size); cSize = Size; }
361 CBenValueSegment(BenContainerPos Pos, unsigned long Size)
362 { cpValue = NULL; cImmediate = false; cPos = Pos;
363 cSize = Size; }
364 CBenValueSegment(BenConstDataPtr pImmData, unsigned short Size)
365 { cpValue = NULL; cImmediate = true;
366 UtHugeMemcpy(cImmData, pImmData, Size); cSize = Size; }
367 bool IsLast()
369 return cpValue == NULL || cpValue->GetValueSegments()->GetLast() ==
370 this;
372 bool IsImmediate() { return cImmediate; }
373 BenContainerPos GetPosition() { return cPos; }
374 unsigned long GetSize() { return cSize; }
375 void SetSize(unsigned long Size) { cSize = Size; }
376 BenByte * GetImmediateData() { return cImmData; }
378 private: // Data
379 pCBenValue cpValue;
380 bool cImmediate;
381 union
383 BenContainerPos cPos;
384 BenByte cImmData[4];
386 unsigned long cSize;
389 inline pCBenValueSegment CBenValue::GetNextValueSegment(pCBenValueSegment
390 pCurrValueSegment)
391 { return (pCBenValueSegment) cValueSegments.GetNextOrNULL(pCurrValueSegment); }
393 inline pLtcBenContainer CBenValue::GetContainer()
394 { return GetProperty()->GetContainer(); }
396 class CBenNamedObject : public CBenObject
398 public: // Methods
399 virtual bool IsNamedObject() SAL_OVERRIDE;
400 virtual bool IsPropertyName();
401 virtual bool IsTypeName();
403 public: // Internal methods
404 CBenNamedObject(pLtcBenContainer pContainer, BenObjectID ObjectID,
405 pCBenObject pPrevObject, const char * sName,
406 pCBenNamedObjectListElmt pPrevNamedObjectListElmt);
407 const char * GetName() { return csName.data(); }
409 const char * GetNameCStr() { return csName.c_str(); }
411 void SetPosition(BenContainerPos Pos) { cPos = Pos; }
412 BenContainerPos GetPosition(void) { return cPos; }
413 size_t GetLength(void) { return csName.length()+ 1; }
414 pCBenNamedObjectListElmt GetNameListElmt() { return &cNameListElmt; }
416 private: // Data
417 std::string csName;
418 CBenNamedObjectListElmt cNameListElmt;
419 BenContainerPos cPos;
422 class CBenPropertyName : public CBenNamedObject
424 public: // Internal methods
425 CBenPropertyName(pLtcBenContainer pContainer, BenObjectID ObjectID,
426 pCBenObject pPrevObject, const char * sName,
427 pCBenNamedObjectListElmt pPrevNamedObjectListElmt) :
428 CBenNamedObject(pContainer, ObjectID, pPrevObject, sName,
429 pPrevNamedObjectListElmt) { ; }
430 virtual bool IsPropertyName() SAL_OVERRIDE;
433 class CBenTypeName : public CBenNamedObject
435 public: // Internal methods
436 CBenTypeName(pLtcBenContainer pContainer, BenObjectID ObjectID,
437 pCBenObject pPrevObject, const char * sName,
438 pCBenNamedObjectListElmt pPrevNamedObjectListElmt) :
439 CBenNamedObject(pContainer, ObjectID, pPrevObject, sName,
440 pPrevNamedObjectListElmt) { ; }
441 virtual bool IsTypeName() SAL_OVERRIDE;
444 } // end namespace OpenStormBento
445 #endif
447 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */