tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / store / source / storbase.cxx
blob013862e681d383ab5ea5204f4fa04f492c272590
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "storbase.hxx"
22 #include <sal/types.h>
23 #include <rtl/alloc.h>
24 #include <rtl/ref.hxx>
25 #include <osl/diagnose.h>
27 #include <store/types.h>
28 #include "object.hxx"
30 #include <stdio.h>
32 using namespace store;
34 // PageData::Allocator_Impl (default allocator).
36 namespace store
39 class PageData::Allocator_Impl :
40 public store::OStoreObject,
41 public store::PageData::Allocator
43 public:
44 /** Construction (two phase).
46 Allocator_Impl();
48 Allocator_Impl(const Allocator_Impl&) = delete;
49 Allocator_Impl& operator=(const Allocator_Impl&) = delete;
51 storeError initialize (sal_uInt16 nPageSize);
53 protected:
54 virtual ~Allocator_Impl() override;
56 private:
57 rtl_cache_type * m_page_cache;
58 sal_uInt16 m_page_size;
60 /** PageData::Allocator implementation.
62 virtual void allocate_Impl (void ** ppPage, sal_uInt16 * pnSize) override;
63 virtual void deallocate_Impl (void * pPage) override;
66 } // namespace store
68 PageData::Allocator_Impl::Allocator_Impl()
69 : m_page_cache(nullptr), m_page_size(0)
72 storeError
73 PageData::Allocator_Impl::initialize (sal_uInt16 nPageSize)
75 char name[RTL_CACHE_NAME_LENGTH + 1];
76 std::size_t size = sal::static_int_cast<std::size_t>(nPageSize);
77 (void) snprintf (name, sizeof(name), "store_page_alloc_%" SAL_PRI_SIZET "u", size);
79 m_page_cache = rtl_cache_create (name, size, 0, nullptr, nullptr, nullptr, nullptr, nullptr, 0);
80 if (!m_page_cache)
81 return store_E_OutOfMemory;
83 m_page_size = nPageSize;
84 return store_E_None;
87 PageData::Allocator_Impl::~Allocator_Impl()
89 rtl_cache_destroy(m_page_cache);
90 m_page_cache = nullptr;
93 void PageData::Allocator_Impl::allocate_Impl (void ** ppPage, sal_uInt16 * pnSize)
95 OSL_PRECOND((ppPage != nullptr) && (pnSize != nullptr), "contract violation");
96 if ((ppPage != nullptr) && (pnSize != nullptr))
98 *ppPage = rtl_cache_alloc(m_page_cache);
99 *pnSize = m_page_size;
103 void PageData::Allocator_Impl::deallocate_Impl (void * pPage)
105 OSL_PRECOND(pPage != nullptr, "contract violation");
106 rtl_cache_free(m_page_cache, pPage);
109 storeError
110 PageData::Allocator::createInstance (rtl::Reference< PageData::Allocator > & rxAllocator, sal_uInt16 nPageSize)
112 rtl::Reference< PageData::Allocator_Impl > xAllocator (new PageData::Allocator_Impl());
113 rxAllocator = &*xAllocator;
114 return xAllocator->initialize (nPageSize);
117 OStorePageObject::~OStorePageObject()
121 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */