1*1a5fa39bSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*1a5fa39bSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*1a5fa39bSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*1a5fa39bSAndrew Rist * distributed with this work for additional information
6*1a5fa39bSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*1a5fa39bSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*1a5fa39bSAndrew Rist * "License"); you may not use this file except in compliance
9*1a5fa39bSAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11*1a5fa39bSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13*1a5fa39bSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*1a5fa39bSAndrew Rist * software distributed under the License is distributed on an
15*1a5fa39bSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*1a5fa39bSAndrew Rist * KIND, either express or implied. See the License for the
17*1a5fa39bSAndrew Rist * specific language governing permissions and limitations
18*1a5fa39bSAndrew Rist * under the License.
19cdf0e10cSrcweir *
20*1a5fa39bSAndrew Rist *************************************************************/
21*1a5fa39bSAndrew Rist
22*1a5fa39bSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir #ifndef _STORE_STORBASE_HXX_
25cdf0e10cSrcweir #define _STORE_STORBASE_HXX_ "$Revision: 1.10.8.4 $"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include "sal/types.h"
28cdf0e10cSrcweir
29cdf0e10cSrcweir #include "rtl/alloc.h"
30cdf0e10cSrcweir #include "rtl/crc.h"
31cdf0e10cSrcweir #include "rtl/ref.hxx"
32cdf0e10cSrcweir
33cdf0e10cSrcweir #include "osl/diagnose.h"
34cdf0e10cSrcweir #include "osl/endian.h"
35cdf0e10cSrcweir
36cdf0e10cSrcweir #include "store/types.h"
37cdf0e10cSrcweir
38cdf0e10cSrcweir #ifndef INCLUDED_STDDEF_H
39cdf0e10cSrcweir #include <stddef.h>
40cdf0e10cSrcweir #define INCLUDED_STDDEF_H
41cdf0e10cSrcweir #endif
42cdf0e10cSrcweir
43cdf0e10cSrcweir #ifndef INCLUDED_STRING_H
44cdf0e10cSrcweir #include <string.h>
45cdf0e10cSrcweir #define INCLUDED_STRING_H
46cdf0e10cSrcweir #endif
47cdf0e10cSrcweir
48cdf0e10cSrcweir /*========================================================================
49cdf0e10cSrcweir *
50cdf0e10cSrcweir * store common internals.
51cdf0e10cSrcweir *
52cdf0e10cSrcweir *======================================================================*/
53cdf0e10cSrcweir
54cdf0e10cSrcweir #ifndef STORE_IMPL_ISP2
55cdf0e10cSrcweir #define STORE_IMPL_ISP2(value) (((value) & ((value) - 1)) == 0)
56cdf0e10cSrcweir #endif
57cdf0e10cSrcweir
58cdf0e10cSrcweir #ifndef STORE_IMPL_CONCAT
59cdf0e10cSrcweir #define STORE_IMPL_CONCAT(x, y) STORE_IMPL_CONCAT2(x,y)
60cdf0e10cSrcweir #define STORE_IMPL_CONCAT2(x, y) x##y
61cdf0e10cSrcweir #endif
62cdf0e10cSrcweir
63cdf0e10cSrcweir #ifndef STORE_STATIC_ASSERT /* Compile time assertion */
64cdf0e10cSrcweir namespace store
65cdf0e10cSrcweir {
66cdf0e10cSrcweir template< bool x > struct STATIC_ASSERTION_FAILURE;
67cdf0e10cSrcweir template<> struct STATIC_ASSERTION_FAILURE< true > { enum { value = 1 }; };
68cdf0e10cSrcweir
69cdf0e10cSrcweir template< int x > struct static_assert_test{};
70cdf0e10cSrcweir } // namespace store
71cdf0e10cSrcweir
72cdf0e10cSrcweir #define STORE_STATIC_ASSERT(pred) \
73cdf0e10cSrcweir typedef \
74cdf0e10cSrcweir store::static_assert_test< sizeof( store::STATIC_ASSERTION_FAILURE< (bool)(pred) > ) > \
75cdf0e10cSrcweir STORE_IMPL_CONCAT(static_assert_typedef_, __LINE__)
76cdf0e10cSrcweir
77cdf0e10cSrcweir #endif /* !STORE_STATIC_ASSERT */
78cdf0e10cSrcweir
79cdf0e10cSrcweir namespace store
80cdf0e10cSrcweir {
81cdf0e10cSrcweir
82cdf0e10cSrcweir #ifdef htons
83cdf0e10cSrcweir #undef htons
84cdf0e10cSrcweir #endif
85cdf0e10cSrcweir #ifdef ntohs
86cdf0e10cSrcweir #undef ntohs
87cdf0e10cSrcweir #endif
88cdf0e10cSrcweir
89cdf0e10cSrcweir #ifdef htonl
90cdf0e10cSrcweir #undef htonl
91cdf0e10cSrcweir #endif
92cdf0e10cSrcweir #ifdef ntohl
93cdf0e10cSrcweir #undef ntohl
94cdf0e10cSrcweir #endif
95cdf0e10cSrcweir
96cdf0e10cSrcweir #ifdef OSL_BIGENDIAN
htons(sal_uInt16 h)97cdf0e10cSrcweir inline sal_uInt16 htons (sal_uInt16 h) { return OSL_SWAPWORD(h); }
ntohs(sal_uInt16 n)98cdf0e10cSrcweir inline sal_uInt16 ntohs (sal_uInt16 n) { return OSL_SWAPWORD(n); }
99cdf0e10cSrcweir
htonl(sal_uInt32 h)100cdf0e10cSrcweir inline sal_uInt32 htonl (sal_uInt32 h) { return OSL_SWAPDWORD(h); }
ntohl(sal_uInt32 n)101cdf0e10cSrcweir inline sal_uInt32 ntohl (sal_uInt32 n) { return OSL_SWAPDWORD(n); }
102cdf0e10cSrcweir #else
103cdf0e10cSrcweir inline sal_uInt16 htons (sal_uInt16 h) { return (h); }
104cdf0e10cSrcweir inline sal_uInt16 ntohs (sal_uInt16 n) { return (n); }
105cdf0e10cSrcweir
106cdf0e10cSrcweir inline sal_uInt32 htonl (sal_uInt32 h) { return (h); }
107cdf0e10cSrcweir inline sal_uInt32 ntohl (sal_uInt32 n) { return (n); }
108cdf0e10cSrcweir #endif /* OSL_BIGENDIAN */
109cdf0e10cSrcweir
110cdf0e10cSrcweir /** swap.
111cdf0e10cSrcweir */
swap(T & lhs,T & rhs)112cdf0e10cSrcweir template< typename T > void swap (T & lhs, T & rhs)
113cdf0e10cSrcweir {
114cdf0e10cSrcweir T tmp = lhs; lhs = rhs; rhs = tmp;
115cdf0e10cSrcweir }
116cdf0e10cSrcweir
117cdf0e10cSrcweir /*========================================================================
118cdf0e10cSrcweir *
119cdf0e10cSrcweir * SharedCount.
120cdf0e10cSrcweir *
121cdf0e10cSrcweir *======================================================================*/
122cdf0e10cSrcweir class SharedCount
123cdf0e10cSrcweir {
124cdf0e10cSrcweir long * m_pCount;
125cdf0e10cSrcweir
126cdf0e10cSrcweir class Allocator
127cdf0e10cSrcweir {
128cdf0e10cSrcweir rtl_cache_type * m_cache;
129cdf0e10cSrcweir
130cdf0e10cSrcweir public:
131cdf0e10cSrcweir static Allocator & get();
132cdf0e10cSrcweir
alloc()133cdf0e10cSrcweir long * alloc()
134cdf0e10cSrcweir {
135cdf0e10cSrcweir return static_cast<long*>(rtl_cache_alloc (m_cache));
136cdf0e10cSrcweir }
free(long * pCount)137cdf0e10cSrcweir void free (long * pCount)
138cdf0e10cSrcweir {
139cdf0e10cSrcweir rtl_cache_free (m_cache, pCount);
140cdf0e10cSrcweir }
141cdf0e10cSrcweir
142cdf0e10cSrcweir protected:
143cdf0e10cSrcweir Allocator();
144cdf0e10cSrcweir ~Allocator();
145cdf0e10cSrcweir };
146cdf0e10cSrcweir
147cdf0e10cSrcweir public:
SharedCount()148cdf0e10cSrcweir SharedCount()
149cdf0e10cSrcweir : m_pCount(Allocator::get().alloc())
150cdf0e10cSrcweir {
151cdf0e10cSrcweir if (m_pCount != 0) (*m_pCount) = 1;
152cdf0e10cSrcweir }
153cdf0e10cSrcweir
~SharedCount()154cdf0e10cSrcweir ~SharedCount()
155cdf0e10cSrcweir {
156cdf0e10cSrcweir if (m_pCount != 0)
157cdf0e10cSrcweir {
158cdf0e10cSrcweir long new_count = --(*m_pCount);
159cdf0e10cSrcweir if (new_count == 0)
160cdf0e10cSrcweir Allocator::get().free(m_pCount);
161cdf0e10cSrcweir }
162cdf0e10cSrcweir }
163cdf0e10cSrcweir
swap(SharedCount & rhs)164cdf0e10cSrcweir void swap (SharedCount & rhs) // nothrow
165cdf0e10cSrcweir {
166cdf0e10cSrcweir store::swap(m_pCount, rhs.m_pCount);
167cdf0e10cSrcweir }
168cdf0e10cSrcweir
SharedCount(SharedCount const & rhs)169cdf0e10cSrcweir SharedCount (SharedCount const & rhs) // nothrow
170cdf0e10cSrcweir : m_pCount (rhs.m_pCount)
171cdf0e10cSrcweir {
172cdf0e10cSrcweir if (m_pCount != 0) ++(*m_pCount);
173cdf0e10cSrcweir }
operator =(SharedCount const & rhs)174cdf0e10cSrcweir SharedCount & operator= (SharedCount const & rhs) // nothrow
175cdf0e10cSrcweir {
176cdf0e10cSrcweir SharedCount tmp(rhs);
177cdf0e10cSrcweir swap(tmp);
178cdf0e10cSrcweir return *this;
179cdf0e10cSrcweir }
180cdf0e10cSrcweir
operator ==(long count) const181cdf0e10cSrcweir bool operator== (long count) const
182cdf0e10cSrcweir {
183cdf0e10cSrcweir return (m_pCount != 0) ? *m_pCount == count : false;
184cdf0e10cSrcweir }
185cdf0e10cSrcweir };
186cdf0e10cSrcweir
187cdf0e10cSrcweir /*========================================================================
188cdf0e10cSrcweir *
189cdf0e10cSrcweir * OStorePageGuard.
190cdf0e10cSrcweir *
191cdf0e10cSrcweir *======================================================================*/
192cdf0e10cSrcweir struct OStorePageGuard
193cdf0e10cSrcweir {
194cdf0e10cSrcweir /** Representation.
195cdf0e10cSrcweir */
196cdf0e10cSrcweir sal_uInt32 m_nMagic;
197cdf0e10cSrcweir sal_uInt32 m_nCRC32;
198cdf0e10cSrcweir
199cdf0e10cSrcweir /** Construction.
200cdf0e10cSrcweir */
OStorePageGuardstore::OStorePageGuard201cdf0e10cSrcweir explicit OStorePageGuard (sal_uInt32 nMagic = 0, sal_uInt32 nCRC32 = 0)
202cdf0e10cSrcweir : m_nMagic (store::htonl(nMagic)),
203cdf0e10cSrcweir m_nCRC32 (store::htonl(nCRC32))
204cdf0e10cSrcweir {}
205cdf0e10cSrcweir
swapstore::OStorePageGuard206cdf0e10cSrcweir void swap (OStorePageGuard & rhs)
207cdf0e10cSrcweir {
208cdf0e10cSrcweir store::swap(m_nMagic, rhs.m_nMagic);
209cdf0e10cSrcweir store::swap(m_nCRC32, rhs.m_nCRC32);
210cdf0e10cSrcweir }
211cdf0e10cSrcweir
OStorePageGuardstore::OStorePageGuard212cdf0e10cSrcweir OStorePageGuard (OStorePageGuard const & rhs)
213cdf0e10cSrcweir : m_nMagic (rhs.m_nMagic),
214cdf0e10cSrcweir m_nCRC32 (rhs.m_nCRC32)
215cdf0e10cSrcweir {}
216cdf0e10cSrcweir
operator =store::OStorePageGuard217cdf0e10cSrcweir OStorePageGuard& operator= (const OStorePageGuard& rhs)
218cdf0e10cSrcweir {
219cdf0e10cSrcweir m_nMagic = rhs.m_nMagic;
220cdf0e10cSrcweir m_nCRC32 = rhs.m_nCRC32;
221cdf0e10cSrcweir return *this;
222cdf0e10cSrcweir }
223cdf0e10cSrcweir
224cdf0e10cSrcweir /** Comparison.
225cdf0e10cSrcweir */
operator ==store::OStorePageGuard226cdf0e10cSrcweir bool operator== (const OStorePageGuard& rhs) const
227cdf0e10cSrcweir {
228cdf0e10cSrcweir return ((m_nMagic == rhs.m_nMagic) &&
229cdf0e10cSrcweir (m_nCRC32 == rhs.m_nCRC32) );
230cdf0e10cSrcweir }
231cdf0e10cSrcweir };
232cdf0e10cSrcweir
233cdf0e10cSrcweir /*========================================================================
234cdf0e10cSrcweir *
235cdf0e10cSrcweir * OStorePageDescriptor.
236cdf0e10cSrcweir *
237cdf0e10cSrcweir *======================================================================*/
238cdf0e10cSrcweir #define STORE_PAGE_NULL ((sal_uInt32)(~0))
239cdf0e10cSrcweir
240cdf0e10cSrcweir struct OStorePageDescriptor
241cdf0e10cSrcweir {
242cdf0e10cSrcweir /** Representation.
243cdf0e10cSrcweir */
244cdf0e10cSrcweir sal_uInt32 m_nAddr;
245cdf0e10cSrcweir sal_uInt16 m_nSize;
246cdf0e10cSrcweir sal_uInt16 m_nUsed;
247cdf0e10cSrcweir
248cdf0e10cSrcweir /** Construction.
249cdf0e10cSrcweir */
OStorePageDescriptorstore::OStorePageDescriptor250cdf0e10cSrcweir explicit OStorePageDescriptor (
251cdf0e10cSrcweir sal_uInt32 nAddr = STORE_PAGE_NULL,
252cdf0e10cSrcweir sal_uInt16 nSize = 0,
253cdf0e10cSrcweir sal_uInt16 nUsed = 0)
254cdf0e10cSrcweir : m_nAddr (store::htonl(nAddr)),
255cdf0e10cSrcweir m_nSize (store::htons(nSize)),
256cdf0e10cSrcweir m_nUsed (store::htons(nUsed))
257cdf0e10cSrcweir {}
258cdf0e10cSrcweir
swapstore::OStorePageDescriptor259cdf0e10cSrcweir void swap (OStorePageDescriptor & rhs)
260cdf0e10cSrcweir {
261cdf0e10cSrcweir store::swap(m_nAddr, rhs.m_nAddr);
262cdf0e10cSrcweir store::swap(m_nSize, rhs.m_nSize);
263cdf0e10cSrcweir store::swap(m_nUsed, rhs.m_nUsed);
264cdf0e10cSrcweir }
265cdf0e10cSrcweir
OStorePageDescriptorstore::OStorePageDescriptor266cdf0e10cSrcweir OStorePageDescriptor (const OStorePageDescriptor & rhs)
267cdf0e10cSrcweir : m_nAddr (rhs.m_nAddr),
268cdf0e10cSrcweir m_nSize (rhs.m_nSize),
269cdf0e10cSrcweir m_nUsed (rhs.m_nUsed)
270cdf0e10cSrcweir {}
271cdf0e10cSrcweir
operator =store::OStorePageDescriptor272cdf0e10cSrcweir OStorePageDescriptor & operator= (const OStorePageDescriptor & rhs)
273cdf0e10cSrcweir {
274cdf0e10cSrcweir m_nAddr = rhs.m_nAddr;
275cdf0e10cSrcweir m_nSize = rhs.m_nSize;
276cdf0e10cSrcweir m_nUsed = rhs.m_nUsed;
277cdf0e10cSrcweir return *this;
278cdf0e10cSrcweir }
279cdf0e10cSrcweir
280cdf0e10cSrcweir /** Comparison.
281cdf0e10cSrcweir */
operator ==store::OStorePageDescriptor282cdf0e10cSrcweir bool operator== (const OStorePageDescriptor & rhs) const
283cdf0e10cSrcweir {
284cdf0e10cSrcweir return ((m_nAddr == rhs.m_nAddr) &&
285cdf0e10cSrcweir (m_nSize == rhs.m_nSize) );
286cdf0e10cSrcweir }
287cdf0e10cSrcweir
operator <=store::OStorePageDescriptor288cdf0e10cSrcweir bool operator<= (const OStorePageDescriptor & rhs) const
289cdf0e10cSrcweir {
290cdf0e10cSrcweir return ((m_nAddr == rhs.m_nAddr ) &&
291cdf0e10cSrcweir (store::ntohs(m_nSize) <= store::ntohs(rhs.m_nSize)) );
292cdf0e10cSrcweir }
293cdf0e10cSrcweir
operator <store::OStorePageDescriptor294cdf0e10cSrcweir bool operator< (const OStorePageDescriptor & rhs) const
295cdf0e10cSrcweir {
296cdf0e10cSrcweir if (m_nAddr == rhs.m_nAddr)
297cdf0e10cSrcweir return (store::ntohs(m_nSize) < store::ntohs(rhs.m_nSize));
298cdf0e10cSrcweir else
299cdf0e10cSrcweir return (store::ntohl(m_nAddr) < store::ntohl(rhs.m_nAddr));
300cdf0e10cSrcweir }
301cdf0e10cSrcweir };
302cdf0e10cSrcweir
303cdf0e10cSrcweir /*========================================================================
304cdf0e10cSrcweir *
305cdf0e10cSrcweir * OStorePageKey.
306cdf0e10cSrcweir *
307cdf0e10cSrcweir *======================================================================*/
308cdf0e10cSrcweir struct OStorePageKey
309cdf0e10cSrcweir {
310cdf0e10cSrcweir /** Representation.
311cdf0e10cSrcweir */
312cdf0e10cSrcweir sal_uInt32 m_nLow;
313cdf0e10cSrcweir sal_uInt32 m_nHigh;
314cdf0e10cSrcweir
315cdf0e10cSrcweir /** Construction.
316cdf0e10cSrcweir */
OStorePageKeystore::OStorePageKey317cdf0e10cSrcweir explicit OStorePageKey (sal_uInt32 nLow = 0, sal_uInt32 nHigh = 0)
318cdf0e10cSrcweir : m_nLow (store::htonl(nLow)),
319cdf0e10cSrcweir m_nHigh (store::htonl(nHigh))
320cdf0e10cSrcweir {}
321cdf0e10cSrcweir
swapstore::OStorePageKey322cdf0e10cSrcweir void swap (OStorePageKey & rhs)
323cdf0e10cSrcweir {
324cdf0e10cSrcweir store::swap(m_nLow, rhs.m_nLow);
325cdf0e10cSrcweir store::swap(m_nHigh, rhs.m_nHigh);
326cdf0e10cSrcweir }
327cdf0e10cSrcweir
OStorePageKeystore::OStorePageKey328cdf0e10cSrcweir OStorePageKey (const OStorePageKey & rhs)
329cdf0e10cSrcweir : m_nLow (rhs.m_nLow), m_nHigh (rhs.m_nHigh)
330cdf0e10cSrcweir {}
331cdf0e10cSrcweir
operator =store::OStorePageKey332cdf0e10cSrcweir OStorePageKey & operator= (const OStorePageKey & rhs)
333cdf0e10cSrcweir {
334cdf0e10cSrcweir m_nLow = rhs.m_nLow;
335cdf0e10cSrcweir m_nHigh = rhs.m_nHigh;
336cdf0e10cSrcweir return *this;
337cdf0e10cSrcweir }
338cdf0e10cSrcweir
339cdf0e10cSrcweir /** Comparison.
340cdf0e10cSrcweir */
operator ==store::OStorePageKey341cdf0e10cSrcweir bool operator== (const OStorePageKey & rhs) const
342cdf0e10cSrcweir {
343cdf0e10cSrcweir return ((m_nLow == rhs.m_nLow ) &&
344cdf0e10cSrcweir (m_nHigh == rhs.m_nHigh) );
345cdf0e10cSrcweir }
346cdf0e10cSrcweir
operator <store::OStorePageKey347cdf0e10cSrcweir bool operator< (const OStorePageKey & rhs) const
348cdf0e10cSrcweir {
349cdf0e10cSrcweir if (m_nHigh == rhs.m_nHigh)
350cdf0e10cSrcweir return (store::ntohl(m_nLow) < store::ntohl(rhs.m_nLow));
351cdf0e10cSrcweir else
352cdf0e10cSrcweir return (store::ntohl(m_nHigh) < store::ntohl(rhs.m_nHigh));
353cdf0e10cSrcweir }
354cdf0e10cSrcweir };
355cdf0e10cSrcweir
356cdf0e10cSrcweir /*========================================================================
357cdf0e10cSrcweir *
358cdf0e10cSrcweir * OStorePageLink.
359cdf0e10cSrcweir *
360cdf0e10cSrcweir *======================================================================*/
361cdf0e10cSrcweir struct OStorePageLink
362cdf0e10cSrcweir {
363cdf0e10cSrcweir /** Representation.
364cdf0e10cSrcweir */
365cdf0e10cSrcweir sal_uInt32 m_nAddr;
366cdf0e10cSrcweir
367cdf0e10cSrcweir /** Construction.
368cdf0e10cSrcweir */
OStorePageLinkstore::OStorePageLink369cdf0e10cSrcweir explicit OStorePageLink (sal_uInt32 nAddr = STORE_PAGE_NULL)
370cdf0e10cSrcweir : m_nAddr (store::htonl(nAddr))
371cdf0e10cSrcweir {}
372cdf0e10cSrcweir
swapstore::OStorePageLink373cdf0e10cSrcweir void swap (OStorePageLink & rhs)
374cdf0e10cSrcweir {
375cdf0e10cSrcweir store::swap(m_nAddr, rhs.m_nAddr);
376cdf0e10cSrcweir }
377cdf0e10cSrcweir
OStorePageLinkstore::OStorePageLink378cdf0e10cSrcweir OStorePageLink (const OStorePageLink & rhs)
379cdf0e10cSrcweir : m_nAddr (rhs.m_nAddr)
380cdf0e10cSrcweir {}
381cdf0e10cSrcweir
operator =store::OStorePageLink382cdf0e10cSrcweir OStorePageLink & operator= (const OStorePageLink & rhs)
383cdf0e10cSrcweir {
384cdf0e10cSrcweir m_nAddr = rhs.m_nAddr;
385cdf0e10cSrcweir return *this;
386cdf0e10cSrcweir }
387cdf0e10cSrcweir
operator =store::OStorePageLink388cdf0e10cSrcweir OStorePageLink & operator= (sal_uInt32 nAddr)
389cdf0e10cSrcweir {
390cdf0e10cSrcweir m_nAddr = store::htonl(nAddr);
391cdf0e10cSrcweir return *this;
392cdf0e10cSrcweir }
393cdf0e10cSrcweir
394cdf0e10cSrcweir /** Comparison.
395cdf0e10cSrcweir */
operator ==store::OStorePageLink396cdf0e10cSrcweir bool operator== (const OStorePageLink & rhs) const
397cdf0e10cSrcweir {
398cdf0e10cSrcweir return (m_nAddr == rhs.m_nAddr);
399cdf0e10cSrcweir }
400cdf0e10cSrcweir
operator <store::OStorePageLink401cdf0e10cSrcweir bool operator< (const OStorePageLink& rhs) const
402cdf0e10cSrcweir {
403cdf0e10cSrcweir return (store::ntohl(m_nAddr) < store::ntohl(rhs.m_nAddr));
404cdf0e10cSrcweir }
405cdf0e10cSrcweir
406cdf0e10cSrcweir /** Operation.
407cdf0e10cSrcweir */
locationstore::OStorePageLink408cdf0e10cSrcweir sal_uInt32 location() const
409cdf0e10cSrcweir {
410cdf0e10cSrcweir return store::ntohl(m_nAddr);
411cdf0e10cSrcweir }
412cdf0e10cSrcweir
linkstore::OStorePageLink413cdf0e10cSrcweir void link (OStorePageLink & rPred)
414cdf0e10cSrcweir {
415cdf0e10cSrcweir // @@@ swap (rPred); @@@
416cdf0e10cSrcweir OStorePageLink tmp (rPred);
417cdf0e10cSrcweir rPred = *this;
418cdf0e10cSrcweir *this = tmp;
419cdf0e10cSrcweir }
420cdf0e10cSrcweir
unlinkstore::OStorePageLink421cdf0e10cSrcweir void unlink (OStorePageLink& rPred)
422cdf0e10cSrcweir {
423cdf0e10cSrcweir rPred = *this;
424cdf0e10cSrcweir *this = OStorePageLink();
425cdf0e10cSrcweir }
426cdf0e10cSrcweir };
427cdf0e10cSrcweir
428cdf0e10cSrcweir /*========================================================================
429cdf0e10cSrcweir *
430cdf0e10cSrcweir * PageData.
431cdf0e10cSrcweir *
432cdf0e10cSrcweir *======================================================================*/
433cdf0e10cSrcweir typedef struct PageData OStorePageData; // backward compat.
434cdf0e10cSrcweir struct PageData
435cdf0e10cSrcweir {
436cdf0e10cSrcweir typedef OStorePageGuard G;
437cdf0e10cSrcweir typedef OStorePageDescriptor D;
438cdf0e10cSrcweir typedef OStorePageLink L;
439cdf0e10cSrcweir
440cdf0e10cSrcweir /** Representation.
441cdf0e10cSrcweir */
442cdf0e10cSrcweir G m_aGuard;
443cdf0e10cSrcweir D m_aDescr;
444cdf0e10cSrcweir L m_aMarked;
445cdf0e10cSrcweir L m_aUnused;
446cdf0e10cSrcweir
447cdf0e10cSrcweir /** theSize.
448cdf0e10cSrcweir */
449cdf0e10cSrcweir static const size_t theSize = sizeof(G) + sizeof(D) + 2 * sizeof(L);
450cdf0e10cSrcweir static const sal_uInt16 thePageSize = theSize;
451cdf0e10cSrcweir STORE_STATIC_ASSERT(STORE_MINIMUM_PAGESIZE >= thePageSize);
452cdf0e10cSrcweir
453cdf0e10cSrcweir /** location.
454cdf0e10cSrcweir */
locationstore::PageData455cdf0e10cSrcweir sal_uInt32 location() const
456cdf0e10cSrcweir {
457cdf0e10cSrcweir return store::ntohl(m_aDescr.m_nAddr);
458cdf0e10cSrcweir }
locationstore::PageData459cdf0e10cSrcweir void location (sal_uInt32 nAddr)
460cdf0e10cSrcweir {
461cdf0e10cSrcweir m_aDescr.m_nAddr = store::htonl(nAddr);
462cdf0e10cSrcweir }
463cdf0e10cSrcweir
464cdf0e10cSrcweir /** size.
465cdf0e10cSrcweir */
sizestore::PageData466cdf0e10cSrcweir sal_uInt16 size() const
467cdf0e10cSrcweir {
468cdf0e10cSrcweir return store::ntohs(m_aDescr.m_nSize);
469cdf0e10cSrcweir }
470cdf0e10cSrcweir
471cdf0e10cSrcweir /** type.
472cdf0e10cSrcweir */
typestore::PageData473cdf0e10cSrcweir sal_uInt32 type() const
474cdf0e10cSrcweir {
475cdf0e10cSrcweir return store::ntohl(m_aGuard.m_nMagic);
476cdf0e10cSrcweir }
477cdf0e10cSrcweir
478cdf0e10cSrcweir /** Allocation.
479cdf0e10cSrcweir */
480cdf0e10cSrcweir class Allocator_Impl;
481cdf0e10cSrcweir class Allocator : public rtl::IReference
482cdf0e10cSrcweir {
483cdf0e10cSrcweir public:
construct()484cdf0e10cSrcweir template< class T > T * construct()
485cdf0e10cSrcweir {
486cdf0e10cSrcweir void * page = 0; sal_uInt16 size = 0;
487cdf0e10cSrcweir if (allocate (&page, &size))
488cdf0e10cSrcweir {
489cdf0e10cSrcweir return new(page) T(size);
490cdf0e10cSrcweir }
491cdf0e10cSrcweir return 0;
492cdf0e10cSrcweir }
493cdf0e10cSrcweir
allocate(void ** ppPage,sal_uInt16 * pnSize)494cdf0e10cSrcweir bool allocate (void ** ppPage, sal_uInt16 * pnSize)
495cdf0e10cSrcweir {
496cdf0e10cSrcweir allocate_Impl (ppPage, pnSize);
497cdf0e10cSrcweir return ((*ppPage != 0) && (*pnSize != 0));
498cdf0e10cSrcweir }
499cdf0e10cSrcweir
deallocate(void * pPage)500cdf0e10cSrcweir void deallocate (void * pPage)
501cdf0e10cSrcweir {
502cdf0e10cSrcweir if (pPage != 0)
503cdf0e10cSrcweir deallocate_Impl (pPage);
504cdf0e10cSrcweir }
505cdf0e10cSrcweir
506cdf0e10cSrcweir static storeError createInstance (
507cdf0e10cSrcweir rtl::Reference< PageData::Allocator > & rxAllocator, sal_uInt16 nPageSize);
508cdf0e10cSrcweir
509cdf0e10cSrcweir private:
510cdf0e10cSrcweir /** Implementation (abstract).
511cdf0e10cSrcweir */
512cdf0e10cSrcweir virtual void allocate_Impl (void ** ppPage, sal_uInt16 * pnSize) = 0;
513cdf0e10cSrcweir virtual void deallocate_Impl (void * pPage) = 0;
514cdf0e10cSrcweir };
515cdf0e10cSrcweir
operator newstore::PageData516cdf0e10cSrcweir static void* operator new (size_t, void * p) { return p; }
operator deletestore::PageData517cdf0e10cSrcweir static void operator delete (void * , void *) {}
518cdf0e10cSrcweir
519cdf0e10cSrcweir /** Construction.
520cdf0e10cSrcweir */
PageDatastore::PageData521cdf0e10cSrcweir explicit PageData (sal_uInt16 nPageSize = thePageSize)
522cdf0e10cSrcweir : m_aGuard(),
523cdf0e10cSrcweir m_aDescr(STORE_PAGE_NULL, nPageSize, thePageSize),
524cdf0e10cSrcweir m_aMarked(),
525cdf0e10cSrcweir m_aUnused()
526cdf0e10cSrcweir {}
527cdf0e10cSrcweir
swapstore::PageData528cdf0e10cSrcweir void swap (PageData & rhs) // nothrow
529cdf0e10cSrcweir {
530cdf0e10cSrcweir m_aGuard.swap(rhs.m_aGuard);
531cdf0e10cSrcweir m_aDescr.swap(rhs.m_aDescr);
532cdf0e10cSrcweir m_aMarked.swap(rhs.m_aMarked);
533cdf0e10cSrcweir m_aUnused.swap(rhs.m_aUnused);
534cdf0e10cSrcweir }
535cdf0e10cSrcweir
PageDatastore::PageData536cdf0e10cSrcweir PageData (PageData const & rhs) // nothrow
537cdf0e10cSrcweir : m_aGuard (rhs.m_aGuard),
538cdf0e10cSrcweir m_aDescr (rhs.m_aDescr),
539cdf0e10cSrcweir m_aMarked(rhs.m_aMarked),
540cdf0e10cSrcweir m_aUnused(rhs.m_aUnused)
541cdf0e10cSrcweir {}
542cdf0e10cSrcweir
operator =store::PageData543cdf0e10cSrcweir PageData & operator= (PageData const & rhs) // nothrow
544cdf0e10cSrcweir {
545cdf0e10cSrcweir PageData tmp (rhs);
546cdf0e10cSrcweir swap (tmp);
547cdf0e10cSrcweir return *this;
548cdf0e10cSrcweir }
549cdf0e10cSrcweir
550cdf0e10cSrcweir /** guard (external representation).
551cdf0e10cSrcweir */
guardstore::PageData552cdf0e10cSrcweir void guard (sal_uInt32 nAddr)
553cdf0e10cSrcweir {
554cdf0e10cSrcweir sal_uInt32 nCRC32 = 0;
555cdf0e10cSrcweir nCRC32 = rtl_crc32 (nCRC32, &m_aGuard.m_nMagic, sizeof(sal_uInt32));
556cdf0e10cSrcweir m_aDescr.m_nAddr = store::htonl(nAddr);
557cdf0e10cSrcweir nCRC32 = rtl_crc32 (nCRC32, &m_aDescr, theSize - sizeof(G));
558cdf0e10cSrcweir m_aGuard.m_nCRC32 = store::htonl(nCRC32);
559cdf0e10cSrcweir }
560cdf0e10cSrcweir
561cdf0e10cSrcweir /** verify (external representation).
562cdf0e10cSrcweir */
verifystore::PageData563cdf0e10cSrcweir storeError verify (sal_uInt32 nAddr) const
564cdf0e10cSrcweir {
565cdf0e10cSrcweir sal_uInt32 nCRC32 = 0;
566cdf0e10cSrcweir nCRC32 = rtl_crc32 (nCRC32, &m_aGuard.m_nMagic, sizeof(sal_uInt32));
567cdf0e10cSrcweir nCRC32 = rtl_crc32 (nCRC32, &m_aDescr, theSize - sizeof(G));
568cdf0e10cSrcweir if (m_aGuard.m_nCRC32 != store::htonl(nCRC32))
569cdf0e10cSrcweir return store_E_InvalidChecksum;
570cdf0e10cSrcweir if (m_aDescr.m_nAddr != store::htonl(nAddr))
571cdf0e10cSrcweir return store_E_InvalidAccess;
572cdf0e10cSrcweir return store_E_None;
573cdf0e10cSrcweir }
574cdf0e10cSrcweir
verifyVersionstore::PageData575cdf0e10cSrcweir storeError verifyVersion (sal_uInt32 nMagic) const
576cdf0e10cSrcweir {
577cdf0e10cSrcweir if (m_aGuard.m_nMagic != store::htonl(nMagic))
578cdf0e10cSrcweir return store_E_WrongVersion;
579cdf0e10cSrcweir else
580cdf0e10cSrcweir return store_E_None;
581cdf0e10cSrcweir }
582cdf0e10cSrcweir };
583cdf0e10cSrcweir
584cdf0e10cSrcweir /*========================================================================
585cdf0e10cSrcweir *
586cdf0e10cSrcweir * PageHolder.
587cdf0e10cSrcweir *
588cdf0e10cSrcweir *======================================================================*/
589cdf0e10cSrcweir class PageHolder
590cdf0e10cSrcweir {
591cdf0e10cSrcweir SharedCount m_refcount;
592cdf0e10cSrcweir PageData * m_pagedata;
593cdf0e10cSrcweir
594cdf0e10cSrcweir typedef rtl::Reference< PageData::Allocator > allocator_type;
595cdf0e10cSrcweir allocator_type m_allocator;
596cdf0e10cSrcweir
597cdf0e10cSrcweir public:
PageHolder(PageData * pagedata=0,allocator_type const & allocator=allocator_type ())598cdf0e10cSrcweir explicit PageHolder (PageData * pagedata = 0, allocator_type const & allocator = allocator_type())
599cdf0e10cSrcweir : m_refcount (),
600cdf0e10cSrcweir m_pagedata (pagedata),
601cdf0e10cSrcweir m_allocator(allocator)
602cdf0e10cSrcweir {
603cdf0e10cSrcweir OSL_ENSURE((m_pagedata == 0) || m_allocator.is(), "store::PageHolder::ctor(): pagedata w/o allocator.");
604cdf0e10cSrcweir }
605cdf0e10cSrcweir
~PageHolder()606cdf0e10cSrcweir ~PageHolder()
607cdf0e10cSrcweir {
608cdf0e10cSrcweir if ((m_refcount == 1) && (m_pagedata != 0))
609cdf0e10cSrcweir {
610cdf0e10cSrcweir // free pagedata.
611cdf0e10cSrcweir OSL_ENSURE(m_allocator.is(), "store::PageHolder::dtor(): pagedata w/o allocator.");
612cdf0e10cSrcweir m_allocator->deallocate (m_pagedata);
613cdf0e10cSrcweir }
614cdf0e10cSrcweir }
615cdf0e10cSrcweir
swap(PageHolder & rhs)616cdf0e10cSrcweir void swap (PageHolder & rhs) // nothrow
617cdf0e10cSrcweir {
618cdf0e10cSrcweir m_refcount.swap(rhs.m_refcount);
619cdf0e10cSrcweir store::swap(m_pagedata, rhs.m_pagedata);
620cdf0e10cSrcweir store::swap(m_allocator, rhs.m_allocator);
621cdf0e10cSrcweir }
622cdf0e10cSrcweir
PageHolder(PageHolder const & rhs)623cdf0e10cSrcweir PageHolder (PageHolder const & rhs) // nothrow
624cdf0e10cSrcweir : m_refcount (rhs.m_refcount),
625cdf0e10cSrcweir m_pagedata (rhs.m_pagedata),
626cdf0e10cSrcweir m_allocator(rhs.m_allocator)
627cdf0e10cSrcweir {}
628cdf0e10cSrcweir
operator =(PageHolder const & rhs)629cdf0e10cSrcweir PageHolder & operator= (PageHolder const & rhs) // nothrow
630cdf0e10cSrcweir {
631cdf0e10cSrcweir PageHolder tmp (rhs);
632cdf0e10cSrcweir swap(tmp);
633cdf0e10cSrcweir return *this;
634cdf0e10cSrcweir }
635cdf0e10cSrcweir
get()636cdf0e10cSrcweir PageData * get() { return m_pagedata; }
get() const637cdf0e10cSrcweir PageData const * get() const { return m_pagedata; }
638cdf0e10cSrcweir
operator ->()639cdf0e10cSrcweir PageData * operator->()
640cdf0e10cSrcweir {
641cdf0e10cSrcweir OSL_PRECOND(m_pagedata != 0, "store::PageHolder::operator->(): Null pointer");
642cdf0e10cSrcweir return m_pagedata;
643cdf0e10cSrcweir }
operator ->() const644cdf0e10cSrcweir PageData const * operator->() const
645cdf0e10cSrcweir {
646cdf0e10cSrcweir OSL_PRECOND(m_pagedata != 0, "store::PageHolder::operator->(): Null pointer");
647cdf0e10cSrcweir return m_pagedata;
648cdf0e10cSrcweir }
649cdf0e10cSrcweir
operator *()650cdf0e10cSrcweir PageData & operator*()
651cdf0e10cSrcweir {
652cdf0e10cSrcweir OSL_PRECOND(m_pagedata != 0, "store::PageHolder::operator*(): Null pointer");
653cdf0e10cSrcweir return *m_pagedata;
654cdf0e10cSrcweir }
operator *() const655cdf0e10cSrcweir PageData const & operator*() const
656cdf0e10cSrcweir {
657cdf0e10cSrcweir OSL_PRECOND(m_pagedata != 0, "store::PageHolder::operator*(): Null pointer");
658cdf0e10cSrcweir return *m_pagedata;
659cdf0e10cSrcweir }
660cdf0e10cSrcweir };
661cdf0e10cSrcweir
662cdf0e10cSrcweir /*========================================================================
663cdf0e10cSrcweir *
664cdf0e10cSrcweir * PageHolderObject.
665cdf0e10cSrcweir *
666cdf0e10cSrcweir *======================================================================*/
667cdf0e10cSrcweir template< class T >
668cdf0e10cSrcweir class PageHolderObject
669cdf0e10cSrcweir {
670cdf0e10cSrcweir /** Representation.
671cdf0e10cSrcweir */
672cdf0e10cSrcweir PageHolder m_xPage;
673cdf0e10cSrcweir
674cdf0e10cSrcweir /** Checked cast.
675cdf0e10cSrcweir */
676cdf0e10cSrcweir template< class U >
isA(PageData const * p)677cdf0e10cSrcweir static bool isA (PageData const * p)
678cdf0e10cSrcweir {
679cdf0e10cSrcweir return ((p != 0) && (p->type() == U::theTypeId));
680cdf0e10cSrcweir }
681cdf0e10cSrcweir
682cdf0e10cSrcweir template< class U >
dynamic_page_cast(PageData * p)683cdf0e10cSrcweir static U * dynamic_page_cast (PageData * p)
684cdf0e10cSrcweir {
685cdf0e10cSrcweir return isA<U>(p) ? static_cast<U*>(p) : 0;
686cdf0e10cSrcweir }
687cdf0e10cSrcweir
688cdf0e10cSrcweir template< class U >
dynamic_page_cast(PageData const * p)689cdf0e10cSrcweir static U const * dynamic_page_cast (PageData const * p)
690cdf0e10cSrcweir {
691cdf0e10cSrcweir return isA<U>(p) ? static_cast<U const *>(p) : 0;
692cdf0e10cSrcweir }
693cdf0e10cSrcweir
694cdf0e10cSrcweir public:
construct(rtl::Reference<PageData::Allocator> const & rxAllocator)695cdf0e10cSrcweir bool construct (rtl::Reference< PageData::Allocator > const & rxAllocator)
696cdf0e10cSrcweir {
697cdf0e10cSrcweir if ((m_xPage.get() == 0) && rxAllocator.is())
698cdf0e10cSrcweir {
699cdf0e10cSrcweir PageHolder tmp (rxAllocator->construct<T>(), rxAllocator);
700cdf0e10cSrcweir m_xPage.swap (tmp);
701cdf0e10cSrcweir }
702cdf0e10cSrcweir return (m_xPage.get() != 0);
703cdf0e10cSrcweir }
704cdf0e10cSrcweir
createInstance(rtl::Reference<PageData::Allocator> const & rxAllocator)705cdf0e10cSrcweir static PageHolderObject<T> createInstance (rtl::Reference< PageData::Allocator > const & rxAllocator)
706cdf0e10cSrcweir {
707cdf0e10cSrcweir PageHolderObject<T> tmp;
708cdf0e10cSrcweir (void) tmp.construct (rxAllocator);
709cdf0e10cSrcweir return tmp;
710cdf0e10cSrcweir }
711cdf0e10cSrcweir
PageHolderObject(PageHolder const & rxPage=PageHolder ())712cdf0e10cSrcweir explicit PageHolderObject (PageHolder const & rxPage = PageHolder())
713cdf0e10cSrcweir : m_xPage (rxPage)
714cdf0e10cSrcweir {}
715cdf0e10cSrcweir
swap(PageHolderObject<T> & rhs)716cdf0e10cSrcweir void swap (PageHolderObject<T> & rhs)
717cdf0e10cSrcweir {
718cdf0e10cSrcweir m_xPage.swap (rhs.m_xPage);
719cdf0e10cSrcweir }
720cdf0e10cSrcweir
PageHolderObject(PageHolderObject<T> const & rhs)721cdf0e10cSrcweir PageHolderObject (PageHolderObject<T> const & rhs)
722cdf0e10cSrcweir : m_xPage (rhs.m_xPage)
723cdf0e10cSrcweir {}
724cdf0e10cSrcweir
operator =(PageHolderObject<T> const & rhs)725cdf0e10cSrcweir PageHolderObject<T> & operator= (PageHolderObject<T> const & rhs)
726cdf0e10cSrcweir {
727cdf0e10cSrcweir PageHolderObject<T> tmp (rhs);
728cdf0e10cSrcweir this->swap (tmp);
729cdf0e10cSrcweir return *this;
730cdf0e10cSrcweir }
731cdf0e10cSrcweir
is() const732cdf0e10cSrcweir bool is() const
733cdf0e10cSrcweir {
734cdf0e10cSrcweir return (m_xPage.get() != 0);
735cdf0e10cSrcweir }
736cdf0e10cSrcweir
737cdf0e10cSrcweir #if 1 /* EXP */
get()738cdf0e10cSrcweir PageHolder & get() { return m_xPage; }
get() const739cdf0e10cSrcweir PageHolder const & get() const { return m_xPage; }
740cdf0e10cSrcweir #endif /* EXP */
741cdf0e10cSrcweir
operator ->()742cdf0e10cSrcweir T * operator->()
743cdf0e10cSrcweir {
744cdf0e10cSrcweir T * pImpl = dynamic_page_cast<T>(m_xPage.get());
745cdf0e10cSrcweir OSL_PRECOND(pImpl != 0, "store::PageHolder<T>::operator*(): Null pointer");
746cdf0e10cSrcweir return pImpl;
747cdf0e10cSrcweir }
operator ->() const748cdf0e10cSrcweir T const * operator->() const
749cdf0e10cSrcweir {
750cdf0e10cSrcweir T const * pImpl = dynamic_page_cast<T>(m_xPage.get());
751cdf0e10cSrcweir OSL_PRECOND(pImpl != 0, "store::PageHolder<T>::operator*(): Null pointer");
752cdf0e10cSrcweir return pImpl;
753cdf0e10cSrcweir }
754cdf0e10cSrcweir
operator *()755cdf0e10cSrcweir T & operator*()
756cdf0e10cSrcweir {
757cdf0e10cSrcweir T * pImpl = dynamic_page_cast<T>(m_xPage.get());
758cdf0e10cSrcweir OSL_PRECOND(pImpl != 0, "store::PageHolder<T>::operator*(): Null pointer");
759cdf0e10cSrcweir return (*pImpl);
760cdf0e10cSrcweir }
operator *() const761cdf0e10cSrcweir T const & operator*() const
762cdf0e10cSrcweir {
763cdf0e10cSrcweir T const * pImpl = dynamic_page_cast<T>(m_xPage.get());
764cdf0e10cSrcweir OSL_PRECOND(pImpl != 0, "store::PageHolder<T>::operator*(): Null pointer");
765cdf0e10cSrcweir return (*pImpl);
766cdf0e10cSrcweir }
767cdf0e10cSrcweir
guard(PageHolder & rxPage,sal_uInt32 nAddr)768cdf0e10cSrcweir static storeError guard (PageHolder & rxPage, sal_uInt32 nAddr)
769cdf0e10cSrcweir {
770cdf0e10cSrcweir PageData * pHead = rxPage.get();
771cdf0e10cSrcweir if (!pHead)
772cdf0e10cSrcweir return store_E_InvalidAccess;
773cdf0e10cSrcweir pHead->guard(nAddr);
774cdf0e10cSrcweir
775cdf0e10cSrcweir T * pImpl = dynamic_page_cast<T>(pHead);
776cdf0e10cSrcweir OSL_PRECOND(pImpl != 0, "store::PageHolder<T>::guard(): Null pointer");
777cdf0e10cSrcweir pImpl->guard();
778cdf0e10cSrcweir
779cdf0e10cSrcweir return store_E_None;
780cdf0e10cSrcweir }
verify(PageHolder const & rxPage,sal_uInt32 nAddr)781cdf0e10cSrcweir static storeError verify (PageHolder const & rxPage, sal_uInt32 nAddr)
782cdf0e10cSrcweir {
783cdf0e10cSrcweir PageData const * pHead = rxPage.get();
784cdf0e10cSrcweir if (!pHead)
785cdf0e10cSrcweir return store_E_InvalidAccess;
786cdf0e10cSrcweir
787cdf0e10cSrcweir storeError eErrCode = pHead->verify(nAddr);
788cdf0e10cSrcweir if (eErrCode != store_E_None)
789cdf0e10cSrcweir return eErrCode;
790cdf0e10cSrcweir
791cdf0e10cSrcweir T const * pImpl = dynamic_page_cast<T>(pHead);
792cdf0e10cSrcweir if (!pImpl)
793cdf0e10cSrcweir return store_E_WrongVersion;
794cdf0e10cSrcweir
795cdf0e10cSrcweir return pImpl->verify();
796cdf0e10cSrcweir }
797cdf0e10cSrcweir };
798cdf0e10cSrcweir
799cdf0e10cSrcweir /*========================================================================
800cdf0e10cSrcweir *
801cdf0e10cSrcweir * PageObject.
802cdf0e10cSrcweir *
803cdf0e10cSrcweir *======================================================================*/
804cdf0e10cSrcweir #if 1 /* EXP */
805cdf0e10cSrcweir class PageObject
806cdf0e10cSrcweir {
807cdf0e10cSrcweir public:
PageObject(PageHolder const & rxPage=PageHolder ())808cdf0e10cSrcweir explicit PageObject (PageHolder const & rxPage = PageHolder())
809cdf0e10cSrcweir : m_xPage (rxPage), m_bDirty (false)
810cdf0e10cSrcweir {}
811cdf0e10cSrcweir
~PageObject()812cdf0e10cSrcweir virtual ~PageObject()
813cdf0e10cSrcweir {}
814cdf0e10cSrcweir
get()815cdf0e10cSrcweir PageHolder & get() { return m_xPage; }
get() const816cdf0e10cSrcweir PageHolder const & get() const { return m_xPage; }
817cdf0e10cSrcweir
clean()818cdf0e10cSrcweir void clean() { m_bDirty = false; }
touch()819cdf0e10cSrcweir void touch() { m_bDirty = true; }
820cdf0e10cSrcweir
location() const821cdf0e10cSrcweir sal_uInt32 location() const
822cdf0e10cSrcweir {
823cdf0e10cSrcweir PageData const * pagedata = m_xPage.get();
824cdf0e10cSrcweir return (pagedata != 0) ? pagedata->location() : STORE_PAGE_NULL;
825cdf0e10cSrcweir }
location(sal_uInt32 nAddr)826cdf0e10cSrcweir void location (sal_uInt32 nAddr)
827cdf0e10cSrcweir {
828cdf0e10cSrcweir PageData * pagedata = m_xPage.get();
829cdf0e10cSrcweir if (pagedata != 0)
830cdf0e10cSrcweir pagedata->location (nAddr);
831cdf0e10cSrcweir }
832cdf0e10cSrcweir
833cdf0e10cSrcweir protected:
834cdf0e10cSrcweir PageHolder m_xPage;
835cdf0e10cSrcweir bool m_bDirty;
836cdf0e10cSrcweir
837cdf0e10cSrcweir virtual storeError guard (sal_uInt32 nAddr) = 0;
838cdf0e10cSrcweir virtual storeError verify (sal_uInt32 nAddr) const = 0;
839cdf0e10cSrcweir };
840cdf0e10cSrcweir #endif /* EXP */
841cdf0e10cSrcweir
842cdf0e10cSrcweir class OStorePageBIOS;
843cdf0e10cSrcweir
844cdf0e10cSrcweir class OStorePageObject
845cdf0e10cSrcweir {
846cdf0e10cSrcweir typedef OStorePageData page;
847cdf0e10cSrcweir
848cdf0e10cSrcweir public:
849cdf0e10cSrcweir /** Allocation.
850cdf0e10cSrcweir */
operator new(size_t n)851cdf0e10cSrcweir static void * operator new (size_t n) SAL_THROW(())
852cdf0e10cSrcweir {
853cdf0e10cSrcweir return rtl_allocateMemory (sal_uInt32(n));
854cdf0e10cSrcweir }
operator delete(void * p,size_t)855cdf0e10cSrcweir static void operator delete (void * p, size_t) SAL_THROW(())
856cdf0e10cSrcweir {
857cdf0e10cSrcweir rtl_freeMemory (p);
858cdf0e10cSrcweir }
859cdf0e10cSrcweir
860cdf0e10cSrcweir /** State.
861cdf0e10cSrcweir */
862cdf0e10cSrcweir inline bool dirty (void) const;
863cdf0e10cSrcweir inline void clean (void);
864cdf0e10cSrcweir inline void touch (void);
865cdf0e10cSrcweir
866cdf0e10cSrcweir /** Location.
867cdf0e10cSrcweir */
868cdf0e10cSrcweir inline sal_uInt32 location (void) const;
869cdf0e10cSrcweir inline void location (sal_uInt32 nAddr);
870cdf0e10cSrcweir
871cdf0e10cSrcweir protected:
872cdf0e10cSrcweir /** Representation.
873cdf0e10cSrcweir */
874cdf0e10cSrcweir PageHolder m_xPage;
875cdf0e10cSrcweir bool m_bDirty;
876cdf0e10cSrcweir
877cdf0e10cSrcweir /** Construction.
878cdf0e10cSrcweir */
OStorePageObject(PageHolder const & rxPage=PageHolder ())879cdf0e10cSrcweir explicit OStorePageObject (PageHolder const & rxPage = PageHolder())
880cdf0e10cSrcweir : m_xPage (rxPage), m_bDirty (false)
881cdf0e10cSrcweir {}
882cdf0e10cSrcweir
883cdf0e10cSrcweir /** Destruction.
884cdf0e10cSrcweir */
885cdf0e10cSrcweir virtual ~OStorePageObject (void);
886cdf0e10cSrcweir
887cdf0e10cSrcweir public:
888cdf0e10cSrcweir template< class U >
makeHolder() const889cdf0e10cSrcweir PageHolderObject<U> makeHolder() const
890cdf0e10cSrcweir {
891cdf0e10cSrcweir return PageHolderObject<U>(m_xPage);
892cdf0e10cSrcweir }
893cdf0e10cSrcweir
894cdf0e10cSrcweir template< class U >
construct(rtl::Reference<PageData::Allocator> const & rxAllocator)895cdf0e10cSrcweir storeError construct (rtl::Reference< PageData::Allocator > const & rxAllocator)
896cdf0e10cSrcweir {
897cdf0e10cSrcweir if (!rxAllocator.is())
898cdf0e10cSrcweir return store_E_InvalidAccess;
899cdf0e10cSrcweir
900cdf0e10cSrcweir PageHolder tmp (rxAllocator->construct<U>(), rxAllocator);
901cdf0e10cSrcweir if (!tmp.get())
902cdf0e10cSrcweir return store_E_OutOfMemory;
903cdf0e10cSrcweir
904cdf0e10cSrcweir m_xPage.swap (tmp);
905cdf0e10cSrcweir return store_E_None;
906cdf0e10cSrcweir }
907cdf0e10cSrcweir
908cdf0e10cSrcweir
get()909cdf0e10cSrcweir PageHolder & get() { return m_xPage; }
get() const910cdf0e10cSrcweir PageHolder const & get() const { return m_xPage; }
911cdf0e10cSrcweir
912cdf0e10cSrcweir virtual storeError guard (sal_uInt32 nAddr) = 0;
913cdf0e10cSrcweir virtual storeError verify (sal_uInt32 nAddr) const = 0;
914cdf0e10cSrcweir };
915cdf0e10cSrcweir
dirty(void) const916cdf0e10cSrcweir inline bool OStorePageObject::dirty (void) const
917cdf0e10cSrcweir {
918cdf0e10cSrcweir return m_bDirty;
919cdf0e10cSrcweir }
920cdf0e10cSrcweir
clean(void)921cdf0e10cSrcweir inline void OStorePageObject::clean (void)
922cdf0e10cSrcweir {
923cdf0e10cSrcweir m_bDirty = false;
924cdf0e10cSrcweir }
925cdf0e10cSrcweir
touch(void)926cdf0e10cSrcweir inline void OStorePageObject::touch (void)
927cdf0e10cSrcweir {
928cdf0e10cSrcweir m_bDirty = true;
929cdf0e10cSrcweir }
930cdf0e10cSrcweir
location(void) const931cdf0e10cSrcweir inline sal_uInt32 OStorePageObject::location (void) const
932cdf0e10cSrcweir {
933cdf0e10cSrcweir return m_xPage->location();
934cdf0e10cSrcweir }
935cdf0e10cSrcweir
location(sal_uInt32 nAddr)936cdf0e10cSrcweir inline void OStorePageObject::location (sal_uInt32 nAddr)
937cdf0e10cSrcweir {
938cdf0e10cSrcweir m_xPage->location(nAddr);
939cdf0e10cSrcweir touch();
940cdf0e10cSrcweir }
941cdf0e10cSrcweir
942cdf0e10cSrcweir /*========================================================================
943cdf0e10cSrcweir *
944cdf0e10cSrcweir * The End.
945cdf0e10cSrcweir *
946cdf0e10cSrcweir *======================================================================*/
947cdf0e10cSrcweir
948cdf0e10cSrcweir } // namespace store
949cdf0e10cSrcweir
950cdf0e10cSrcweir #endif /* !_STORE_STORBASE_HXX_ */
951