merge the formfield patch from ooo-build
[ooovba.git] / store / source / storbase.cxx
blob747b70df393ad4bd11d1c5ded523eca81aaaa6f7
1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
5 * $RCSfile: storbase.cxx,v $
7 * $Revision: 1.12.8.4 $
9 * last change: $Author: mhu $ $Date: 2008/10/31 18:28:18 $
11 * The Contents of this file are made available subject to
12 * the terms of GNU Lesser General Public License Version 2.1.
15 * GNU Lesser General Public License Version 2.1
16 * =============================================
17 * Copyright 2005 by Sun Microsystems, Inc.
18 * 901 San Antonio Road, Palo Alto, CA 94303, USA
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License version 2.1, as published by the Free Software Foundation.
24 * This library is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * Lesser General Public License for more details.
29 * You should have received a copy of the GNU Lesser General Public
30 * License along with this library; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32 * MA 02111-1307 USA
34 ************************************************************************/
36 // MARKER(update_precomp.py): autogen include statement, do not remove
37 #include "precompiled_store.hxx"
39 #include "storbase.hxx"
41 #include "sal/types.h"
42 #include "rtl/alloc.h"
43 #include "rtl/ref.hxx"
44 #include "osl/diagnose.h"
46 #include "store/types.h"
47 #include "object.hxx"
49 #ifndef INCLUDED_STDIO_H
50 #include <stdio.h>
51 #define INCLUDED_STDIO_H
52 #endif
54 using namespace store;
56 /*========================================================================
58 * SharedCount::Allocator.
60 *======================================================================*/
61 SharedCount::Allocator &
62 SharedCount::Allocator::get()
64 static Allocator g_aSharedCountAllocator;
65 return g_aSharedCountAllocator;
68 SharedCount::Allocator::Allocator()
70 m_cache = rtl_cache_create (
71 "store_shared_count_cache",
72 sizeof(long),
73 0, // objalign
74 0, // constructor
75 0, // destructor
76 0, // reclaim
77 0, // userarg
78 0, // default source
79 0 // flags
83 SharedCount::Allocator::~Allocator()
85 rtl_cache_destroy (m_cache), m_cache = 0;
88 /*========================================================================
90 * PageData::Allocator_Impl (default allocator).
92 *======================================================================*/
93 namespace store
96 class PageData::Allocator_Impl :
97 public store::OStoreObject,
98 public store::PageData::Allocator
100 public:
101 /** Construction (two phase).
103 Allocator_Impl();
105 storeError initialize (sal_uInt16 nPageSize);
107 /** Delegate multiple inherited rtl::IReference.
109 virtual oslInterlockedCount SAL_CALL acquire()
111 return OStoreObject::acquire();
113 virtual oslInterlockedCount SAL_CALL release()
115 return OStoreObject::release();
118 protected:
119 /** Destruction.
121 virtual ~Allocator_Impl();
123 private:
124 /** Representation.
126 rtl_cache_type * m_page_cache;
127 sal_uInt16 m_page_size;
129 /** PageData::Allocator implementation.
131 virtual void allocate_Impl (void ** ppPage, sal_uInt16 * pnSize);
132 virtual void deallocate_Impl (void * pPage);
134 /** Not implemented.
136 Allocator_Impl (Allocator_Impl const &);
137 Allocator_Impl & operator= (Allocator_Impl const &);
140 } // namespace store
142 PageData::Allocator_Impl::Allocator_Impl()
143 : m_page_cache(0), m_page_size(0)
146 storeError
147 PageData::Allocator_Impl::initialize (sal_uInt16 nPageSize)
149 char name[RTL_CACHE_NAME_LENGTH + 1];
150 sal_Size size = sal::static_int_cast< sal_Size >(nPageSize);
151 (void) snprintf (name, sizeof(name), "store_page_alloc_%lu", size);
153 m_page_cache = rtl_cache_create (name, size, 0, 0, 0, 0, 0, 0, 0);
154 if (!m_page_cache)
155 return store_E_OutOfMemory;
157 m_page_size = nPageSize;
158 return store_E_None;
161 PageData::Allocator_Impl::~Allocator_Impl()
163 rtl_cache_destroy(m_page_cache), m_page_cache = 0;
166 void PageData::Allocator_Impl::allocate_Impl (void ** ppPage, sal_uInt16 * pnSize)
168 OSL_PRECOND((ppPage != 0) && (pnSize != 0), "contract violation");
169 *ppPage = rtl_cache_alloc(m_page_cache), *pnSize = m_page_size;
172 void PageData::Allocator_Impl::deallocate_Impl (void * pPage)
174 OSL_PRECOND(pPage != 0, "contract violation");
175 rtl_cache_free(m_page_cache, pPage);
178 /*========================================================================
180 * PageData::Allocator factory.
182 *======================================================================*/
184 storeError
185 PageData::Allocator::createInstance (rtl::Reference< PageData::Allocator > & rxAllocator, sal_uInt16 nPageSize)
187 rtl::Reference< PageData::Allocator_Impl > xAllocator (new PageData::Allocator_Impl());
188 if (!xAllocator.is())
189 return store_E_OutOfMemory;
191 rxAllocator = &*xAllocator;
192 return xAllocator->initialize (nPageSize);
195 /*========================================================================
197 * OStorePageObject.
199 *======================================================================*/
201 * ~OStorePageObject.
203 OStorePageObject::~OStorePageObject (void)