vcl: sfx2: LOK: Support per-view popup windows
[LibreOffice.git] / store / source / storbase.cxx
blob19cb215ef098c0171faec714e82a7a67d691d02a
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 /*========================================================================
36 * PageData::Allocator_Impl (default allocator).
38 *======================================================================*/
39 namespace store
42 class PageData::Allocator_Impl :
43 public store::OStoreObject,
44 public store::PageData::Allocator
46 public:
47 /** Construction (two phase).
49 Allocator_Impl();
51 Allocator_Impl(const Allocator_Impl&) = delete;
52 Allocator_Impl& operator=(const Allocator_Impl&) = delete;
54 storeError initialize (sal_uInt16 nPageSize);
56 protected:
57 /** Destruction.
59 virtual ~Allocator_Impl() override;
61 private:
62 /** Representation.
64 rtl_cache_type * m_page_cache;
65 sal_uInt16 m_page_size;
67 /** PageData::Allocator implementation.
69 virtual void allocate_Impl (void ** ppPage, sal_uInt16 * pnSize) override;
70 virtual void deallocate_Impl (void * pPage) override;
73 } // namespace store
75 PageData::Allocator_Impl::Allocator_Impl()
76 : m_page_cache(nullptr), m_page_size(0)
79 storeError
80 PageData::Allocator_Impl::initialize (sal_uInt16 nPageSize)
82 char name[RTL_CACHE_NAME_LENGTH + 1];
83 std::size_t size = sal::static_int_cast<std::size_t>(nPageSize);
84 (void) snprintf (name, sizeof(name), "store_page_alloc_%" SAL_PRI_SIZET "u", size);
86 m_page_cache = rtl_cache_create (name, size, 0, nullptr, nullptr, nullptr, nullptr, nullptr, 0);
87 if (!m_page_cache)
88 return store_E_OutOfMemory;
90 m_page_size = nPageSize;
91 return store_E_None;
94 PageData::Allocator_Impl::~Allocator_Impl()
96 rtl_cache_destroy(m_page_cache);
97 m_page_cache = nullptr;
100 void PageData::Allocator_Impl::allocate_Impl (void ** ppPage, sal_uInt16 * pnSize)
102 OSL_PRECOND((ppPage != nullptr) && (pnSize != nullptr), "contract violation");
103 if ((ppPage != nullptr) && (pnSize != nullptr))
105 *ppPage = rtl_cache_alloc(m_page_cache);
106 *pnSize = m_page_size;
110 void PageData::Allocator_Impl::deallocate_Impl (void * pPage)
112 OSL_PRECOND(pPage != nullptr, "contract violation");
113 rtl_cache_free(m_page_cache, pPage);
116 /*========================================================================
118 * PageData::Allocator factory.
120 *======================================================================*/
122 storeError
123 PageData::Allocator::createInstance (rtl::Reference< PageData::Allocator > & rxAllocator, sal_uInt16 nPageSize)
125 rtl::Reference< PageData::Allocator_Impl > xAllocator (new PageData::Allocator_Impl());
126 if (!xAllocator.is())
127 return store_E_OutOfMemory;
129 rxAllocator = &*xAllocator;
130 return xAllocator->initialize (nPageSize);
133 /*========================================================================
135 * OStorePageObject.
137 *======================================================================*/
139 * ~OStorePageObject.
141 OStorePageObject::~OStorePageObject()
145 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */