fw4spl
BufferAllocationPolicy.hpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2015.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #ifndef __FWMEMORY_BUFFERALLOCATIONPOLICY_HPP__
8 #define __FWMEMORY_BUFFERALLOCATIONPOLICY_HPP__
9 
10 #include <fwCore/base.hpp>
11 
12 #include "fwMemory/exception/Memory.hpp"
13 #include "fwMemory/config.hpp"
14 
15 namespace fwMemory
16 {
17 
18 class FWMEMORY_CLASS_API BufferAllocationPolicy
19 {
20 public:
21  typedef SPTR (BufferAllocationPolicy) sptr;
22  typedef size_t SizeType;
23  typedef void* BufferType;
24 
25  FWMEMORY_API virtual void allocate(BufferType &buffer, SizeType size) = 0;
26  FWMEMORY_API virtual void reallocate(BufferType &buffer, SizeType size) = 0;
27  FWMEMORY_API virtual void destroy(BufferType &buffer) = 0;
28 
29  FWMEMORY_API virtual ~BufferAllocationPolicy()
30  {
31  }
32 };
33 
34 
35 class FWMEMORY_CLASS_API BufferMallocPolicy : public BufferAllocationPolicy
36 {
37 public:
38  FWMEMORY_API void allocate(BufferType &buffer,
39  BufferAllocationPolicy::SizeType size);
40  FWMEMORY_API void reallocate(BufferType &buffer,
41  BufferAllocationPolicy::SizeType size);
42  FWMEMORY_API void destroy(BufferType &buffer);
43 
44  FWMEMORY_API static BufferAllocationPolicy::sptr New();
45 };
46 
47 
48 class FWMEMORY_CLASS_API BufferNewPolicy : public BufferAllocationPolicy
49 {
50 public:
51  FWMEMORY_API void allocate(BufferType &buffer,
52  BufferAllocationPolicy::SizeType size);
53  FWMEMORY_API void reallocate(BufferType &buffer,
54  BufferAllocationPolicy::SizeType size);
55  FWMEMORY_API void destroy(BufferType &buffer);
56 
57  FWMEMORY_API static BufferAllocationPolicy::sptr New();
58 };
59 
60 class FWMEMORY_CLASS_API BufferNoAllocPolicy : public BufferAllocationPolicy
61 {
62 public:
63  FWMEMORY_API void allocate(BufferType &buffer,
64  BufferAllocationPolicy::SizeType size);
65  FWMEMORY_API void reallocate(BufferType &buffer,
66  BufferAllocationPolicy::SizeType size);
67  FWMEMORY_API void destroy(BufferType &buffer);
68 
69  FWMEMORY_API static BufferAllocationPolicy::sptr New();
70 };
71 
72 
73 }
74 
75 #endif /* __FWMEMORY_BUFFERALLOCATIONPOLICY_HPP__ */
#define SPTR(_cls_)
The namespace fwMemory contains tools to manage memory. Use for dump.
Definition: SReader.hpp:20