1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 TOOLS_DLLPUBLIC FixedMemPool
31 FixedMemPool_Impl
* m_pImpl
;
32 char const * m_pTypeName
;
35 FixedMemPool( char const * pTypeName
,
36 sal_uInt16 nTypeSize
);
43 #define DECL_FIXEDMEMPOOL_NEW_DECL() \
44 static void * operator new( size_t n )
46 #define DECL_FIXEDMEMPOOL_NEW_IMPL( Class ) \
47 void * Class::operator new( size_t n )
49 #define IMPL_FIXEDMEMPOOL_NEW_BODY( Class, aPool ) \
51 if ( n == sizeof( Class ) ) \
52 return (aPool).Alloc(); \
54 return ::operator new(n); \
57 #define DECL_FIXEDMEMPOOL_NEW_INLINE( Class, aPool ) \
58 DECL_FIXEDMEMPOOL_NEW_DECL() \
59 IMPL_FIXEDMEMPOOL_NEW_BODY( Class, aPool )
61 #define DECL_FIXEDMEMPOOL_DEL_DECL() \
62 static void operator delete( void * p, size_t n )
64 #define DECL_FIXEDMEMPOOL_DEL_IMPL( Class ) \
65 void Class::operator delete( void * p, size_t n )
67 #define IMPL_FIXEDMEMPOOL_DEL_BODY( Class, aPool ) \
69 if ( n == sizeof( Class ) ) \
72 ::operator delete(p); \
75 #define DECL_FIXEDMEMPOOL_DEL_INLINE( Class, aPool ) \
76 DECL_FIXEDMEMPOOL_DEL_DECL() \
77 IMPL_FIXEDMEMPOOL_DEL_BODY( Class, aPool )
79 #define DECL_FIXEDMEMPOOL_NEWDEL( Class ) \
81 static FixedMemPool aPool; \
83 DECL_FIXEDMEMPOOL_NEW_INLINE( Class, aPool ) \
84 DECL_FIXEDMEMPOOL_DEL_INLINE( Class, aPool )
86 #define IMPL_FIXEDMEMPOOL_NEWDEL( Class ) \
87 FixedMemPool Class::aPool( SAL_STRINGIFY( Class ), sizeof( Class ) );
89 #define DECL_FIXEDMEMPOOL_NEWDEL_DLL( Class ) \
91 static FixedMemPool aPool; \
93 DECL_FIXEDMEMPOOL_NEW_DECL(); \
94 DECL_FIXEDMEMPOOL_DEL_DECL();
96 #define IMPL_FIXEDMEMPOOL_NEWDEL_DLL( Class ) \
97 FixedMemPool Class::aPool( SAL_STRINGIFY( Class ), sizeof( Class ) ); \
98 DECL_FIXEDMEMPOOL_NEW_IMPL( Class ) \
99 IMPL_FIXEDMEMPOOL_NEW_BODY( Class, aPool ) \
100 DECL_FIXEDMEMPOOL_DEL_IMPL( Class ) \
101 IMPL_FIXEDMEMPOOL_DEL_BODY( Class, aPool )
105 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */