xref: /aoo4110/main/svl/source/inc/poolio.hxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #include <svl/brdcst.hxx>
24 #include <boost/shared_ptr.hpp>
25 #include <deque>
26 
27 #ifndef DELETEZ
28 #define DELETEZ(pPtr) { delete pPtr; pPtr = 0; }
29 #endif
30 
31 
32 struct SfxPoolVersion_Impl
33 {
34 	sal_uInt16			_nVer;
35 	sal_uInt16			_nStart, _nEnd;
36 	sal_uInt16* 		_pMap;
37 
SfxPoolVersion_ImplSfxPoolVersion_Impl38 					SfxPoolVersion_Impl( sal_uInt16 nVer, sal_uInt16 nStart, sal_uInt16 nEnd,
39 										 sal_uInt16 *pMap )
40 					:	_nVer( nVer ),
41 						_nStart( nStart ),
42 						_nEnd( nEnd ),
43 						_pMap( pMap )
44 					{}
SfxPoolVersion_ImplSfxPoolVersion_Impl45 					SfxPoolVersion_Impl( const SfxPoolVersion_Impl &rOrig )
46 					:	_nVer( rOrig._nVer ),
47 						_nStart( rOrig._nStart ),
48 						_nEnd( rOrig._nEnd ),
49 						_pMap( rOrig._pMap )
50 					{}
51 };
52 
53 typedef std::deque<SfxPoolItem*> SfxPoolItemArrayBase_Impl;
54 
55 typedef boost::shared_ptr< SfxPoolVersion_Impl > SfxPoolVersion_ImplPtr;
56 typedef std::deque< SfxPoolVersion_ImplPtr > SfxPoolVersionArr_Impl;
57 
58 struct SfxPoolItemArray_Impl: public SfxPoolItemArrayBase_Impl
59 {
60 	size_t	nFirstFree;
61 
SfxPoolItemArray_ImplSfxPoolItemArray_Impl62 	SfxPoolItemArray_Impl ()
63 		: nFirstFree( 0 )
64 	{}
65 };
66 
67 class SfxStyleSheetIterator;
68 
69 struct SfxItemPool_Impl
70 {
71 	SfxBroadcaster					aBC;
72 	SfxPoolItemArray_Impl**			ppPoolItems;
73 	SfxPoolVersionArr_Impl			aVersions;
74 	sal_uInt16							nVersion;
75 	sal_uInt16							nLoadingVersion;
76 	sal_uInt16							nInitRefCount; // 1, beim Laden ggf. 2
77 	sal_uInt16							nVerStart, nVerEnd; // WhichRange in Versions
78 	sal_uInt16							nStoringStart, nStoringEnd; // zu speichernder Range
79 	sal_uInt8							nMajorVer, nMinorVer; // Pool selbst
80 	SfxMapUnit                      eDefMetric;
81 	FASTBOOL						bInSetItem;
82 	FASTBOOL						bStreaming; // in Load() bzw. Store()
83 
SfxItemPool_ImplSfxItemPool_Impl84 	SfxItemPool_Impl( sal_uInt16 nStart, sal_uInt16 nEnd )
85 		: ppPoolItems (new SfxPoolItemArray_Impl*[ nEnd - nStart + 1])
86         , nLoadingVersion(0)
87         , nInitRefCount(0)
88         , nVerStart(0)
89         , nVerEnd(0)
90         , nStoringStart(0)
91         , nStoringEnd(0)
92         , nMajorVer(0)
93         , nMinorVer(0)
94         , bInSetItem(false)
95         , bStreaming(false)
96 	{
97 		memset( ppPoolItems, 0, sizeof( SfxPoolItemArray_Impl* ) * ( nEnd - nStart + 1) );
98 	}
99 
~SfxItemPool_ImplSfxItemPool_Impl100 	~SfxItemPool_Impl()
101 	{
102 		delete[] ppPoolItems;
103 	}
104 
DeleteItemsSfxItemPool_Impl105 	void DeleteItems()
106 	{
107 		delete[] ppPoolItems;
108 		ppPoolItems = 0;
109 	}
110 };
111 
112 // -----------------------------------------------------------------------
113 
114 // IBM-C-Set mag keine doppelten Defines
115 #ifdef DBG
116 #  undef DBG
117 #endif
118 
119 #if defined(DBG_UTIL) && defined(MSC)
120 #define SFX_TRACE(s,p) \
121 		{ \
122 			ByteString aPtr(RTL_CONSTASCII_STRINGPARAM("0x0000:0x0000")); \
123 			_snprintf(const_cast< sal_Char *>(aPtr.GetBuffer()), aPtr.Len(), \
124 					   "%lp", p ); \
125 			aPtr.Insert(s, 0); \
126 			DbgTrace( aPtr.GetBuffer() ); \
127 		}
128 #define DBG(x) x
129 #else
130 #define SFX_TRACE(s,p)
131 #define DBG(x)
132 #endif
133 
134 #define CHECK_FILEFORMAT( rStream, nTag ) \
135 	{   sal_uInt16 nFileTag; \
136 		rStream >> nFileTag; \
137 		if ( nTag != nFileTag ) \
138         { \
139             DBG_ERROR( #nTag ); /*! s.u. */ \
140 			/*! error-code setzen und auswerten! */ \
141 			(rStream).SetError(SVSTREAM_FILEFORMAT_ERROR); \
142 			pImp->bStreaming = sal_False; \
143             return rStream; \
144         } \
145     }
146 
147 #define CHECK_FILEFORMAT_RELEASE( rStream, nTag, pPointer ) \
148    {   sal_uInt16 nFileTag; \
149        rStream >> nFileTag; \
150        if ( nTag != nFileTag ) \
151         { \
152             DBG_ERROR( #nTag ); /*! s.u. */ \
153            /*! error-code setzen und auswerten! */ \
154            (rStream).SetError(SVSTREAM_FILEFORMAT_ERROR); \
155            pImp->bStreaming = sal_False; \
156            delete pPointer; \
157             return rStream; \
158         } \
159     }
160 
161 #define CHECK_FILEFORMAT2( rStream, nTag1, nTag2 ) \
162 	{   sal_uInt16 nFileTag; \
163 		rStream >> nFileTag; \
164 		if ( nTag1 != nFileTag && nTag2 != nFileTag ) \
165         { \
166             DBG_ERROR( #nTag1 ); /*! s.u. */ \
167 			/*! error-code setzen und auswerten! */ \
168 			(rStream).SetError(SVSTREAM_FILEFORMAT_ERROR); \
169 			pImp->bStreaming = sal_False; \
170             return rStream; \
171         } \
172     }
173 
174 #define SFX_ITEMPOOL_VER_MAJOR      	sal_uInt8(2)
175 #define SFX_ITEMPOOL_VER_MINOR      	sal_uInt8(0)
176 
177 #define SFX_ITEMPOOL_TAG_STARTPOOL_4	sal_uInt16(0x1111)
178 #define SFX_ITEMPOOL_TAG_STARTPOOL_5	sal_uInt16(0xBBBB)
179 #define SFX_ITEMPOOL_TAG_ITEMPOOL 		sal_uInt16(0xAAAA)
180 #define SFX_ITEMPOOL_TAG_ITEMS			sal_uInt16(0x2222)
181 #define SFX_ITEMPOOL_TAG_ITEM			sal_uInt16(0x7777)
182 #define SFX_ITEMPOOL_TAG_SIZES			sal_uInt16(0x3333)
183 #define SFX_ITEMPOOL_TAG_DEFAULTS		sal_uInt16(0x4444)
184 #define SFX_ITEMPOOL_TAG_VERSIONMAP 	sal_uInt16(0x5555)
185 #define SFX_ITEMPOOL_TAG_HEADER 		sal_uInt16(0x6666)
186 #define SFX_ITEMPOOL_TAG_ENDPOOL		sal_uInt16(0xEEEE)
187 #define SFX_ITEMPOOL_TAG_TRICK4OLD  	sal_uInt16(0xFFFF)
188 
189 #define SFX_ITEMPOOL_REC				sal_uInt8(0x01)
190 #define SFX_ITEMPOOL_REC_HEADER 	    sal_uInt8(0x10)
191 #define SFX_ITEMPOOL_REC_VERSIONMAP 	sal_uInt16(0x0020)
192 #define SFX_ITEMPOOL_REC_WHICHIDS   	sal_uInt16(0x0030)
193 #define SFX_ITEMPOOL_REC_ITEMS  		sal_uInt16(0x0040)
194 #define SFX_ITEMPOOL_REC_DEFAULTS		sal_uInt16(0x0050)
195 
196 #define SFX_ITEMSET_REC					sal_uInt8(0x02)
197 
198 #define SFX_STYLES_REC                  sal_uInt8(0x03)
199 #define SFX_STYLES_REC_HEADER		sal_uInt16(0x0010)
200 #define SFX_STYLES_REC_STYLES		sal_uInt16(0x0020)
201 
202 //========================================================================
203 
GetIndex_Impl(sal_uInt16 nWhich) const204 inline sal_uInt16 SfxItemPool::GetIndex_Impl(sal_uInt16 nWhich) const
205 {
206 	DBG_CHKTHIS(SfxItemPool, 0);
207 	DBG_ASSERT(nWhich >= nStart && nWhich <= nEnd, "Which-Id nicht im Pool-Bereich");
208 	return nWhich - nStart;
209 }
210 
211