Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / include / tools / mempool.hxx
bloba3b13f228ca1300069923ae5d6c92ec24de055c6
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 .
19 #ifndef INCLUDED_TOOLS_MEMPOOL_HXX
20 #define INCLUDED_TOOLS_MEMPOOL_HXX
22 #include <sal/config.h>
24 #include <sal/macros.h>
25 #include <tools/toolsdllapi.h>
27 struct FixedMemPool_Impl;
29 class SAL_WARN_UNUSED TOOLS_DLLPUBLIC FixedMemPool
31 FixedMemPool_Impl * m_pImpl;
32 char const * m_pTypeName;
34 public:
35 FixedMemPool( char const * pTypeName,
36 sal_uInt16 nTypeSize );
37 ~FixedMemPool();
39 void* Alloc();
40 void Free( void* p );
43 #define DECL_FIXEDMEMPOOL_NEW_DECL() \
44 static void * operator new( size_t n )
46 #define IMPL_FIXEDMEMPOOL_NEW_BODY( Class, aPool ) \
47 { \
48 if ( n == sizeof( Class ) ) \
49 return (aPool).Alloc(); \
50 else \
51 return ::operator new(n); \
54 #define DECL_FIXEDMEMPOOL_DEL_DECL() \
55 static void operator delete( void * p, size_t n )
57 #define IMPL_FIXEDMEMPOOL_DEL_BODY( Class, aPool ) \
58 { \
59 if ( n == sizeof( Class ) ) \
60 (aPool).Free(p); \
61 else \
62 ::operator delete(p); \
65 #define DECL_FIXEDMEMPOOL_NEWDEL( Class ) \
66 private: \
67 static FixedMemPool aPool; \
68 public: \
69 DECL_FIXEDMEMPOOL_NEW_DECL() \
70 IMPL_FIXEDMEMPOOL_NEW_BODY( Class, aPool ) \
71 DECL_FIXEDMEMPOOL_DEL_DECL() \
72 IMPL_FIXEDMEMPOOL_DEL_BODY( Class, aPool )
74 #define IMPL_FIXEDMEMPOOL_NEWDEL( Class ) \
75 FixedMemPool Class::aPool( SAL_STRINGIFY( Class ), sizeof( Class ) );
77 #define DECL_FIXEDMEMPOOL_NEWDEL_DLL( Class ) \
78 private: \
79 static FixedMemPool aPool; \
80 public: \
81 DECL_FIXEDMEMPOOL_NEW_DECL(); \
82 DECL_FIXEDMEMPOOL_DEL_DECL();
84 #define IMPL_FIXEDMEMPOOL_NEWDEL_DLL( Class ) \
85 FixedMemPool Class::aPool( SAL_STRINGIFY( Class ), sizeof( Class ) ); \
86 void * Class::operator new( size_t n ) \
87 IMPL_FIXEDMEMPOOL_NEW_BODY( Class, aPool ) \
88 void Class::operator delete( void * p, size_t n ) \
89 IMPL_FIXEDMEMPOOL_DEL_BODY( Class, aPool )
91 #endif
93 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */