Debian Codegraph @

Source/Utilities/Memory/CObjectParameterizingAllocator.h

raw
1 /*
2 * Copyright (C) 2013-2015, 2019 by the Konclude Developer Team.
3 *
4 * This file is part of the reasoning system Konclude.
5 * For details and support, see <http://konclude.com/>.
6 *
7 * Konclude is free software: you can redistribute it and/or modify
8 * it under the terms of version 3 of the GNU Lesser General Public
9 * License (LGPLv3) as published by the Free Software Foundation.
10 *
11 * Konclude is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU (Lesser) General Public License for more details.
15 *
16 * You should have received a copy of the GNU (Lesser) General Public
17 * License along with Konclude. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21 #ifndef KONCLUDE_UTILITIES_MEMORY_COBJECTPARAMETERIZINGALLOCATOR_H
22 #define KONCLUDE_UTILITIES_MEMORY_COBJECTPARAMETERIZINGALLOCATOR_H
23
24 // Library includes
25
26
27 // Namespace includes
28 #include "MemorySettings.h"
29 #include "CMemoryAllocationManager.h"
30 #include "CObjectAllocator.h"
31
32 // Other includes
33
34
35 // Logger includes
36 #include "Logger/CLogger.h"
37
38 using namespace std;
39
40 namespace Konclude {
41
42 namespace Utilities {
43
44 namespace Memory {
45
46
47 /*!
48 *
49 * \class CObjectParameterizingAllocator
50 * \author Andreas Steigmiller
51 * \version 0.1
52 * \brief TODO
53 *
54 */
55 template<class T, class P>
56 class CObjectParameterizingAllocator : public CObjectAllocator<T> {
57 // public methods
58 public:
59 //! Constructor
60 CObjectParameterizingAllocator() {
61 }
62
63 //! Destructor
64 virtual ~CObjectParameterizingAllocator() {
65 }
66
67 static inline T* allocateAndConstructAndParameterize(CMemoryAllocationManager* memoryAllocatorManager, P parameter) {
68 T* object = 0;
69 if (memoryAllocatorManager) {
70 void* memAddr = memoryAllocatorManager->allocate(sizeof(T));
71 object = (T*)memAddr;
72 new (object) T(parameter);
73 } else {
74 object = new T(parameter);
75 }
76 return object;
77 }
78
79 // protected methods
80 protected:
81
82 // protected variables
83 protected:
84
85 // private methods
86 private:
87
88 // private variables
89 private:
90 };
91
92
93
94 template<class T>
95 inline void COPADestroyAndRelease(T* object, CMemoryAllocationManager* memoryAllocatorManager) {
96 COADestroyAndRelease(object,memoryAllocatorManager);
97 }
98
99
100
101
102 }; // end namespace Memory
103
104 }; // end namespace Utilities
105
106 }; // end namespace Konclude
107
108 #include "CObjectParameterizingAllocator.cpp"
109
110 #endif // KONCLUDE_UTILITIES_MEMORY_COBJECTPARAMETERIZINGALLOCATOR_H