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 ************************************************************************/
61 #include "lwpsvstream.hxx"
63 #define BEN_CC __stdcall
65 #define BEN_EXPORT __declspec(dllexport)
74 #include <tools/stream.hxx> // SvStream definition
75 #include <sot/storage.hxx> // SotStorageStream definition, add by 10/24/2005
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 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
);
134 typedef unsigned char BenByte
;
135 typedef unsigned short BenWord
;
136 typedef unsigned long BenDWord
;
137 typedef void * BenDataPtr
;
138 typedef const void * BenConstDataPtr
;
140 typedef unsigned long BenContainerPos
;
141 typedef unsigned long BenObjectID
;
142 typedef unsigned long BenGeneration
;
144 sal_uLong
BenOpenContainer(LwpSvStream
* pStream
, pLtcBenContainer
* ppContainer
);
146 class CBenIDListElmt
: public CUtListElmt
148 public: // Internal methods
149 CBenIDListElmt(BenObjectID ID
, pCBenIDListElmt pPrev
) : CUtListElmt(pPrev
)
151 CBenIDListElmt(BenObjectID ID
) { cID
= ID
; }
152 BenObjectID
GetID() { return cID
; }
158 class CBenNamedObjectListElmt
: public CUtListElmt
161 // added to remove warning
162 CBenNamedObjectListElmt(pCBenNamedObjectListElmt pPrev
) : CUtListElmt(pPrev
)
163 { cpNamedObject
= NULL
; }
164 void SetNamedObject(pCBenNamedObject pObj
)
166 cpNamedObject
= pObj
;
169 CBenNamedObjectListElmt(pCBenNamedObject pNamedObject
,
170 pCBenNamedObjectListElmt pPrev
) : CUtListElmt(pPrev
)
171 { cpNamedObject
= pNamedObject
; }
172 pCBenNamedObject
GetNamedObject() { return cpNamedObject
; }
175 pCBenNamedObject cpNamedObject
;
178 class LtcUtBenValueStream
: public SvStream
181 LtcUtBenValueStream(pCBenValue pValue
);
182 ~LtcUtBenValueStream();
184 public: // Overridden methods
187 CBenValue
* GetValue(){ return cpValue
; };
188 sal_uLong
GetSize() { return m_ulValueLength
; };
189 protected: // Overridden methods
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();
199 unsigned long cCurrentPosition
;
201 sal_uLong m_ulValueLength
; // Added by , sum of length of all sub-valuesegments
202 // void GetAmountLeft(sal_uLong * pAmtLeft); useless in SODC
205 class LtcBenContainer
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
);
218 public: // Internal methods
219 LtcBenContainer(LwpSvStream
* pStream
);
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
);
228 BenObjectID
GetNextAvailObjectID() { return cNextAvailObjectID
; }
229 void SetNextAvailObjectID(BenObjectID ID
) { cNextAvailObjectID
= ID
; }
230 pCUtList
GetObjects() { return &cObjects
; }
231 pCUtList
GetNamedObjects() { return &cNamedObjects
; }
233 LtcUtBenValueStream
* FindNextValueStreamWithPropertyName(const char * sPropertyName
, LtcUtBenValueStream
* pCurrentValueStream
);
234 LtcUtBenValueStream
* FindValueStreamWithPropertyName(const char * sPropertyName
);
235 BenError
CreateGraphicStream(SvStream
* &pStream
, const char *pObjectName
);
237 BenError
GetSize(sal_uLong
* pLength
);
238 LwpSvStream
* GetStream()
243 CUtOwningList cObjects
;
244 CUtList cNamedObjects
;
245 LwpSvStream
* cpStream
;
246 sal_uLong m_ulLength
; // Added for TOCRead.cpp
247 BenObjectID cNextAvailObjectID
; // for new object
250 class CBenObject
: public CBenIDListElmt
253 pCBenProperty
UseProperty(BenObjectID PropertyID
);
254 pCBenValue
UseValue(BenObjectID PropertyID
);
255 virtual UtBool
IsNamedObject();
256 pLtcBenContainer
GetContainer() { return cpContainer
; }
257 BenObjectID
GetObjectID() { return GetID(); }
258 public: // Internal methods
259 CBenObject(pLtcBenContainer pContainer
, BenObjectID ObjectID
,
260 pCBenIDListElmt pPrev
) : CBenIDListElmt(ObjectID
, pPrev
)
261 { cpContainer
= pContainer
; }
262 pCUtList
GetProperties() { return &cProperties
; }
265 pLtcBenContainer cpContainer
;
266 CUtOwningList cProperties
;
269 class CBenValue
: public CBenIDListElmt
272 unsigned long GetValueSize();
273 BenError
ReadValueData(BenDataPtr pBuffer
,
274 unsigned long Offset
, unsigned long MaxSize
, unsigned long * pAmtRead
);
276 pCBenProperty BEN_EXPORT
GetProperty() { return cpProperty
; }
278 public: // Internal methods
279 // added to remove WARNING
280 CBenValue(BenObjectID TypeID
):CBenIDListElmt(TypeID
)
283 cpReferencedList
= NULL
;
286 void SetProperty(pCBenProperty pProperty
)
288 cpProperty
= pProperty
;
291 CBenValue(pCBenProperty pProperty
, BenObjectID TypeID
) :
292 CBenIDListElmt(TypeID
)
294 cpProperty
= pProperty
;
295 cpReferencedList
= NULL
;
297 BenObjectID
GetTypeNameID() { return GetID(); }
298 inline pCBenValueSegment
GetNextValueSegment(pCBenValueSegment
300 inline pLtcBenContainer
GetContainer();
301 pCUtList
GetValueSegments() { return &cValueSegments
; }
302 // Currently, no generation support
303 BenGeneration
GetGeneration() { return 1; }
306 pCBenProperty cpProperty
;
307 CUtOwningList cValueSegments
;
308 pCBenValue cpReferencedList
;
311 class CBenProperty
: public CBenIDListElmt
314 // In the Apple Bento, a property can have multiple values, each of a
315 // different type. But we never use it that way, so in this code a
316 // property has exactly one value
318 pCBenValue
UseValue() { return &cValue
; }
319 pCBenObject
GetBenObject() { return cpObject
; }
320 pLtcBenContainer
GetContainer() { return GetBenObject()->GetContainer(); }
322 public: // Internal methods
323 // changed to remove WARNING here
324 CBenProperty(pCBenObject pObject
, BenObjectID PropertyID
,
325 BenObjectID TypeID
, pCBenIDListElmt pPrevProperty
) :
326 CBenIDListElmt(PropertyID
, pPrevProperty
), cValue(TypeID
)
329 cValue
.SetProperty(this);
332 BenObjectID
GetPropertyNameID() { return GetID(); }
335 pCBenObject cpObject
;
339 // In our implementation, reference is always just the object ID for the
340 // object referenced (but you shouldn't assume that)
341 #define BEN_REFERENCE_SIZE 4
346 BenByte
* GetData() { return cData
; }
349 BenByte cData
[BEN_REFERENCE_SIZE
];
352 class CBenValueSegment
: public CUtListElmt
354 public: // Internal methods
355 CBenValueSegment(pCBenValue pValue
, BenContainerPos Pos
,
356 unsigned long Size
) : CUtListElmt(pValue
->GetValueSegments())
357 { cpValue
= pValue
; cImmediate
= UT_FALSE
; cPos
= Pos
;
359 CBenValueSegment(pCBenValue pValue
, BenConstDataPtr pImmData
,
360 unsigned short Size
) : CUtListElmt(pValue
->GetValueSegments())
361 { cpValue
= pValue
; cImmediate
= UT_TRUE
;
362 UtHugeMemcpy(cImmData
, pImmData
, Size
); cSize
= Size
; }
363 CBenValueSegment(BenContainerPos Pos
, unsigned long Size
)
364 { cpValue
= NULL
; cImmediate
= UT_FALSE
; cPos
= Pos
;
366 CBenValueSegment(BenConstDataPtr pImmData
, unsigned short Size
)
367 { cpValue
= NULL
; cImmediate
= UT_TRUE
;
368 UtHugeMemcpy(cImmData
, pImmData
, Size
); cSize
= Size
; }
371 return cpValue
== NULL
|| cpValue
->GetValueSegments()->GetLast() ==
374 UtBool
IsImmediate() { return cImmediate
; }
375 BenContainerPos
GetPosition() { return cPos
; }
376 unsigned long GetSize() { return cSize
; }
377 void SetSize(unsigned long Size
) { cSize
= Size
; }
378 BenByte
* GetImmediateData() { return cImmData
; }
385 BenContainerPos cPos
;
391 inline pCBenValueSegment
CBenValue::GetNextValueSegment(pCBenValueSegment
393 { return (pCBenValueSegment
) cValueSegments
.GetNextOrNULL(pCurrValueSegment
); }
395 inline pLtcBenContainer
CBenValue::GetContainer()
396 { return GetProperty()->GetContainer(); }
398 class CBenNamedObject
: public CBenObject
401 virtual UtBool
IsNamedObject();
402 virtual UtBool
IsPropertyName();
403 virtual UtBool
IsTypeName();
405 public: // Internal methods
406 CBenNamedObject(pLtcBenContainer pContainer
, BenObjectID ObjectID
,
407 pCBenObject pPrevObject
, const char * sName
,
408 pCBenNamedObjectListElmt pPrevNamedObjectListElmt
);
409 const char * GetName() { return csName
.data(); }
412 const char * GetNameCStr() { return csName
.c_str(); }
415 void SetPosition(BenContainerPos Pos
) { cPos
= Pos
; }
416 BenContainerPos
GetPosition(void) { return cPos
; }
417 size_t GetLength(void) { return csName
.length()+ 1; }
418 pCBenNamedObjectListElmt
GetNameListElmt() { return &cNameListElmt
; }
422 CBenNamedObjectListElmt cNameListElmt
;
423 BenContainerPos cPos
;
426 class CBenPropertyName
: public CBenNamedObject
428 public: // Internal methods
429 CBenPropertyName(pLtcBenContainer pContainer
, BenObjectID ObjectID
,
430 pCBenObject pPrevObject
, const char * sName
,
431 pCBenNamedObjectListElmt pPrevNamedObjectListElmt
) :
432 CBenNamedObject(pContainer
, ObjectID
, pPrevObject
, sName
,
433 pPrevNamedObjectListElmt
) { ; }
434 virtual UtBool
IsPropertyName();
437 class CBenTypeName
: public CBenNamedObject
439 public: // Internal methods
440 CBenTypeName(pLtcBenContainer pContainer
, BenObjectID ObjectID
,
441 pCBenObject pPrevObject
, const char * sName
,
442 pCBenNamedObjectListElmt pPrevNamedObjectListElmt
) :
443 CBenNamedObject(pContainer
, ObjectID
, pPrevObject
, sName
,
444 pPrevNamedObjectListElmt
) { ; }
445 virtual UtBool
IsTypeName();
449 } // end namespace OpenStormBento
452 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */