Branch data Line data Source code
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 BENTO_H
57 : : #define BENTO_H
58 : :
59 : : #include <string>
60 : : #include <vector>
61 : : #include "lwpsvstream.hxx"
62 : :
63 : : #define BEN_CC __stdcall
64 : : #ifdef COMP_BENTO
65 : : #define BEN_EXPORT __declspec(dllexport)
66 : : #else
67 : : #define BEN_EXPORT
68 : : #endif
69 : :
70 : : using namespace std;
71 : :
72 : : #include "ut.hxx"
73 : : #include "utlist.hxx"
74 : : #include <tools/stream.hxx> // SvStream definition
75 : : #include <sot/storage.hxx> // SotStorageStream definition, add by 10/24/2005
76 : :
77 : : namespace 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 : :
87 : : enum BenError
88 : : {
89 : : BenErr_OK = 0,
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
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
120 : : };
121 : :
122 : : UtDefClassP(LtcBenContainer);
123 : : UtDefClassP(CBenIDListElmt);
124 : : UtDefClassP(CBenObject);
125 : : UtDefClassP(CBenProperty);
126 : : UtDefClassP(CBenReference);
127 : : UtDefClassP(CBenValue);
128 : : UtDefClassP(CBenValueSegment);
129 : : UtDefClassP(CBenNamedObjectListElmt);
130 : : UtDefClassP(CBenNamedObject);
131 : : UtDefClassP(CBenPropertyName);
132 : : UtDefClassP(CBenTypeName);
133 : :
134 : : typedef unsigned char BenByte;
135 : : typedef unsigned short BenWord;
136 : : typedef unsigned long BenDWord;
137 : : typedef void * BenDataPtr;
138 : : typedef const void * BenConstDataPtr;
139 : :
140 : : typedef unsigned long BenContainerPos;
141 : : typedef unsigned long BenObjectID;
142 : : typedef unsigned long BenGeneration;
143 : :
144 : : sal_uLong BenOpenContainer(LwpSvStream * pStream, pLtcBenContainer * ppContainer);
145 : :
146 [ - + ]: 1650 : class CBenIDListElmt : public CUtListElmt
147 : : {
148 : : public: // Internal methods
149 : 1131 : CBenIDListElmt(BenObjectID ID, pCBenIDListElmt pPrev) : CUtListElmt(pPrev)
150 : 1131 : { cID = ID; }
151 : 519 : CBenIDListElmt(BenObjectID ID) { cID = ID; }
152 : 1776 : BenObjectID GetID() { return cID; }
153 : :
154 : : private: // Data
155 : : BenObjectID cID;
156 : : };
157 : :
158 [ - + ]: 186 : class CBenNamedObjectListElmt : public CUtListElmt
159 : : {
160 : : public: // Methods
161 : : // added to remove warning
162 : 186 : CBenNamedObjectListElmt(pCBenNamedObjectListElmt pPrev) : CUtListElmt(pPrev)
163 : 186 : { cpNamedObject = NULL; }
164 : 186 : void SetNamedObject(pCBenNamedObject pObj)
165 : : {
166 : 186 : cpNamedObject = pObj;
167 : 186 : }
168 : :
169 : : CBenNamedObjectListElmt(pCBenNamedObject pNamedObject,
170 : : pCBenNamedObjectListElmt pPrev) : CUtListElmt(pPrev)
171 : : { cpNamedObject = pNamedObject; }
172 : 825 : pCBenNamedObject GetNamedObject() { return cpNamedObject; }
173 : :
174 : : private: // Data
175 : : pCBenNamedObject cpNamedObject;
176 : : };
177 : :
178 : : class LtcUtBenValueStream : public SvStream
179 : : {
180 : : public:
181 : : LtcUtBenValueStream(pCBenValue pValue);
182 : : ~LtcUtBenValueStream();
183 : :
184 : : public: // Overridden methods
185 : :
186 : : /* added by */
187 : 0 : CBenValue * GetValue(){ return cpValue; };
188 : 0 : sal_uLong GetSize() { return m_ulValueLength; };
189 : : protected: // Overridden methods
190 : :
191 : : virtual sal_uLong GetData( void* pData, sal_uLong nSize );
192 : : virtual sal_uLong PutData( const void* pData, sal_uLong nSize );
193 : : virtual sal_uLong SeekPos( sal_uLong nPos );
194 : : virtual void SetSize( sal_uLong nSize );
195 : : virtual void FlushData();
196 : :
197 : : private: // Data
198 : : pCBenValue cpValue;
199 : : unsigned long cCurrentPosition;
200 : :
201 : : sal_uLong m_ulValueLength; // Added by , sum of length of all sub-valuesegments
202 : : // void GetAmountLeft(sal_uLong * pAmtLeft); useless in SODC
203 : : };
204 : :
205 : : class LtcBenContainer
206 : : {
207 : : public:
208 : : BenError Open();
209 : : BenError Close();
210 : : BenError RegisterPropertyName(const char * sPropertyName,
211 : : pCBenPropertyName * ppPropertyName);
212 : : // Pass NULL to begin iteration. Done when returns NULL.
213 : : // Objects are returned in order of increasing ID
214 : : pCBenObject GetNextObject(pCBenObject pCurrObject);
215 : : pCBenObject FindNextObjectWithProperty(pCBenObject pCurrObject,
216 : : BenObjectID PropertyID);
217 : :
218 : : public: // Internal methods
219 : : LtcBenContainer(LwpSvStream * pStream);
220 : : ~LtcBenContainer();
221 : :
222 : : BenError Read(BenDataPtr pBuffer, unsigned long MaxSize,
223 : : unsigned long * pAmtRead);
224 : : BenError ReadKnownSize(BenDataPtr pBuffer, unsigned long Amt);
225 : : BenError SeekToPosition(BenContainerPos Pos);
226 : : BenError SeekFromEnd(long Offset);
227 : :
228 : : BenObjectID GetNextAvailObjectID() { return cNextAvailObjectID; }
229 : 12 : void SetNextAvailObjectID(BenObjectID ID) { cNextAvailObjectID = ID; }
230 : 588 : pCUtList GetObjects() { return &cObjects; }
231 : 162 : pCUtList GetNamedObjects() { return &cNamedObjects; }
232 : :
233 : : LtcUtBenValueStream * FindNextValueStreamWithPropertyName(const char * sPropertyName, LtcUtBenValueStream * pCurrentValueStream);
234 : : LtcUtBenValueStream * FindValueStreamWithPropertyName(const char * sPropertyName);
235 : : BenError CreateGraphicStream(SvStream * &pStream, const char *pObjectName);
236 : :
237 : : BenError GetSize(sal_uLong * pLength);
238 : : LwpSvStream * GetStream()
239 : : {
240 : : return cpStream;
241 : : };
242 : : private: // Data
243 : : CUtOwningList cObjects;
244 : : CUtList cNamedObjects;
245 : : LwpSvStream * cpStream;
246 : : sal_uLong m_ulLength; // Added for TOCRead.cpp
247 : : BenObjectID cNextAvailObjectID; // for new object
248 : : };
249 : :
250 [ + - ][ - + ]: 1038 : class CBenObject : public CBenIDListElmt
251 : : {
252 : : public:
253 : : pCBenProperty UseProperty(BenObjectID PropertyID);
254 : : pCBenValue UseValue(BenObjectID PropertyID);
255 : : virtual UtBool IsNamedObject();
256 : 0 : pLtcBenContainer GetContainer() { return cpContainer; }
257 : : BenObjectID GetObjectID() { return GetID(); }
258 : : public: // Internal methods
259 : 612 : CBenObject(pLtcBenContainer pContainer, BenObjectID ObjectID,
260 [ + - ]: 612 : pCBenIDListElmt pPrev) : CBenIDListElmt(ObjectID, pPrev)
261 : 612 : { cpContainer = pContainer; }
262 : 519 : pCUtList GetProperties() { return &cProperties; }
263 : :
264 : : private: // Data
265 : : pLtcBenContainer cpContainer;
266 : : CUtOwningList cProperties;
267 : : };
268 : :
269 [ + - ][ - + ]: 519 : class CBenValue : public CBenIDListElmt
270 : : {
271 : : public:
272 : : unsigned long GetValueSize();
273 : : BenError ReadValueData(BenDataPtr pBuffer,
274 : : unsigned long Offset, unsigned long MaxSize, unsigned long * pAmtRead);
275 : :
276 : 0 : pCBenProperty BEN_EXPORT GetProperty() { return cpProperty; }
277 : :
278 : : public: // Internal methods
279 : : // added to remove WARNING
280 [ + - ]: 519 : CBenValue(BenObjectID TypeID):CBenIDListElmt(TypeID)
281 : : {
282 : 519 : cpProperty = NULL;
283 : 519 : cpReferencedList = NULL;
284 : 519 : }
285 : :
286 : 519 : void SetProperty(pCBenProperty pProperty)
287 : : {
288 : 519 : cpProperty = pProperty;
289 : 519 : }
290 : :
291 : : CBenValue(pCBenProperty pProperty, BenObjectID TypeID) :
292 : : CBenIDListElmt(TypeID)
293 : : {
294 : : cpProperty = pProperty;
295 : : cpReferencedList = NULL;
296 : : }
297 : : BenObjectID GetTypeNameID() { return GetID(); }
298 : : inline pCBenValueSegment GetNextValueSegment(pCBenValueSegment
299 : : pCurrValueSegment);
300 : : inline pLtcBenContainer GetContainer();
301 : 519 : pCUtList GetValueSegments() { return &cValueSegments; }
302 : : // Currently, no generation support
303 : : BenGeneration GetGeneration() { return 1; }
304 : :
305 : : private: // Data
306 : : pCBenProperty cpProperty;
307 : : CUtOwningList cValueSegments;
308 : : pCBenValue cpReferencedList;
309 : : unsigned long cReferencedObjectsSize;
310 : : };
311 : :
312 [ + - ][ - + ]: 1038 : class CBenProperty : public CBenIDListElmt
313 : : {
314 : : public:
315 : : // In the Apple Bento, a property can have multiple values, each of a
316 : : // different type. But we never use it that way, so in this code a
317 : : // property has exactly one value
318 : :
319 : 519 : pCBenValue UseValue() { return &cValue; }
320 : 0 : pCBenObject GetBenObject() { return cpObject; }
321 : 0 : pLtcBenContainer GetContainer() { return GetBenObject()->GetContainer(); }
322 : :
323 : : public: // Internal methods
324 : : // changed to remove WARNING here
325 : 519 : CBenProperty(pCBenObject pObject, BenObjectID PropertyID,
326 : : BenObjectID TypeID, pCBenIDListElmt pPrevProperty) :
327 [ + - ]: 519 : CBenIDListElmt(PropertyID, pPrevProperty), cValue(TypeID)
328 : : {
329 : 519 : cpObject = pObject;
330 : 519 : cValue.SetProperty(this);
331 : 519 : }
332 : :
333 : : BenObjectID GetPropertyNameID() { return GetID(); }
334 : :
335 : : private: // Data
336 : : pCBenObject cpObject;
337 : : CBenValue cValue;
338 : : };
339 : :
340 : : // In our implementation, reference is always just the object ID for the
341 : : // object referenced (but you shouldn't assume that)
342 : : #define BEN_REFERENCE_SIZE 4
343 : :
344 : : class CBenReference
345 : : {
346 : : public: // Methods
347 : : BenByte * GetData() { return cData; }
348 : :
349 : : private: // Data
350 : : BenByte cData[BEN_REFERENCE_SIZE];
351 : : };
352 : :
353 [ - + ]: 1038 : class CBenValueSegment : public CUtListElmt
354 : : {
355 : : public: // Internal methods
356 : 519 : CBenValueSegment(pCBenValue pValue, BenContainerPos Pos,
357 : 519 : unsigned long Size) : CUtListElmt(pValue->GetValueSegments())
358 : 519 : { cpValue = pValue; cImmediate = UT_FALSE; cPos = Pos;
359 : 519 : cSize = Size; }
360 : 0 : CBenValueSegment(pCBenValue pValue, BenConstDataPtr pImmData,
361 : 0 : unsigned short Size) : CUtListElmt(pValue->GetValueSegments())
362 : 0 : { cpValue = pValue; cImmediate = UT_TRUE;
363 : 0 : UtHugeMemcpy(cImmData, pImmData, Size); cSize = Size; }
364 : : CBenValueSegment(BenContainerPos Pos, unsigned long Size)
365 : : { cpValue = NULL; cImmediate = UT_FALSE; cPos = Pos;
366 : : cSize = Size; }
367 : : CBenValueSegment(BenConstDataPtr pImmData, unsigned short Size)
368 : : { cpValue = NULL; cImmediate = UT_TRUE;
369 : : UtHugeMemcpy(cImmData, pImmData, Size); cSize = Size; }
370 : : UtBool IsLast()
371 : : {
372 : : return cpValue == NULL || cpValue->GetValueSegments()->GetLast() ==
373 : : this;
374 : : }
375 : 0 : UtBool IsImmediate() { return cImmediate; }
376 : 0 : BenContainerPos GetPosition() { return cPos; }
377 : 0 : unsigned long GetSize() { return cSize; }
378 : : void SetSize(unsigned long Size) { cSize = Size; }
379 : 0 : BenByte * GetImmediateData() { return cImmData; }
380 : :
381 : : private: // Data
382 : : pCBenValue cpValue;
383 : : UtBool cImmediate;
384 : : union
385 : : {
386 : : BenContainerPos cPos;
387 : : BenByte cImmData[4];
388 : : };
389 : : unsigned long cSize;
390 : : };
391 : :
392 : 0 : inline pCBenValueSegment CBenValue::GetNextValueSegment(pCBenValueSegment
393 : : pCurrValueSegment)
394 : 0 : { return (pCBenValueSegment) cValueSegments.GetNextOrNULL(pCurrValueSegment); }
395 : :
396 : 0 : inline pLtcBenContainer CBenValue::GetContainer()
397 : 0 : { return GetProperty()->GetContainer(); }
398 : :
399 [ + - # # ]: 186 : class CBenNamedObject : public CBenObject
[ - + ]
400 : : {
401 : : public: // Methods
402 : : virtual UtBool IsNamedObject();
403 : : virtual UtBool IsPropertyName();
404 : : virtual UtBool IsTypeName();
405 : :
406 : : public: // Internal methods
407 : : CBenNamedObject(pLtcBenContainer pContainer, BenObjectID ObjectID,
408 : : pCBenObject pPrevObject, const char * sName,
409 : : pCBenNamedObjectListElmt pPrevNamedObjectListElmt);
410 : : const char * GetName() { return csName.data(); }
411 : :
412 : :
413 : 825 : const char * GetNameCStr() { return csName.c_str(); }
414 : :
415 : :
416 : : void SetPosition(BenContainerPos Pos) { cPos = Pos; }
417 : : BenContainerPos GetPosition(void) { return cPos; }
418 : : size_t GetLength(void) { return csName.length()+ 1; }
419 : : pCBenNamedObjectListElmt GetNameListElmt() { return &cNameListElmt; }
420 : :
421 : : private: // Data
422 : : string csName;
423 : : CBenNamedObjectListElmt cNameListElmt;
424 : : BenContainerPos cPos;
425 : : };
426 : :
427 [ - + ]: 312 : class CBenPropertyName : public CBenNamedObject
428 : : {
429 : : public: // Internal methods
430 : 156 : CBenPropertyName(pLtcBenContainer pContainer, BenObjectID ObjectID,
431 : : pCBenObject pPrevObject, const char * sName,
432 : : pCBenNamedObjectListElmt pPrevNamedObjectListElmt) :
433 : : CBenNamedObject(pContainer, ObjectID, pPrevObject, sName,
434 : 156 : pPrevNamedObjectListElmt) { ; }
435 : : virtual UtBool IsPropertyName();
436 : : };
437 : :
438 [ - + ]: 60 : class CBenTypeName : public CBenNamedObject
439 : : {
440 : : public: // Internal methods
441 : 30 : CBenTypeName(pLtcBenContainer pContainer, BenObjectID ObjectID,
442 : : pCBenObject pPrevObject, const char * sName,
443 : : pCBenNamedObjectListElmt pPrevNamedObjectListElmt) :
444 : : CBenNamedObject(pContainer, ObjectID, pPrevObject, sName,
445 : 30 : pPrevNamedObjectListElmt) { ; }
446 : : virtual UtBool IsTypeName();
447 : : };
448 : :
449 : :
450 : : } // end namespace OpenStormBento
451 : : #endif
452 : :
453 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|