From ae4725e954487052c84cb5e2b94dec0b08edd120 Mon Sep 17 00:00:00 2001
From: Roberto Raggi <qtc-committer@nokia.com>
Date: Mon, 22 Dec 2008 13:09:26 +0100
Subject: [PATCH] Introduced CPlusPlus::Managed.

Managed is an helper base class that simplify the usage of memory pools.
---
 shared/cplusplus/AST.cpp        |  9 ---------
 shared/cplusplus/AST.h          |  8 ++------
 shared/cplusplus/MemoryPool.cpp | 15 +++++++++++++++
 shared/cplusplus/MemoryPool.h   | 15 +++++++++++++++
 4 files changed, 32 insertions(+), 15 deletions(-)

diff --git a/shared/cplusplus/AST.cpp b/shared/cplusplus/AST.cpp
index 248ed13a027..7774d4d71fa 100644
--- a/shared/cplusplus/AST.cpp
+++ b/shared/cplusplus/AST.cpp
@@ -381,15 +381,6 @@ UsingDirectiveAST *AST::asUsingDirective()
 WhileStatementAST *AST::asWhileStatement()
 { return dynamic_cast<WhileStatementAST *>(this); }
 
-void *AST::operator new(size_t size, MemoryPool *pool)
-{ return pool->allocate(size); }
-
-void AST::operator delete(void *)
-{ }
-
-void AST::operator delete(void *, MemoryPool *)
-{ }
-
 void AST::accept(ASTVisitor *visitor)
 {
     if (visitor->preVisit(this))
diff --git a/shared/cplusplus/AST.h b/shared/cplusplus/AST.h
index fd7cec40deb..c4b0f7fe76f 100644
--- a/shared/cplusplus/AST.h
+++ b/shared/cplusplus/AST.h
@@ -55,12 +55,12 @@
 
 #include "CPlusPlusForwardDeclarations.h"
 #include "ASTfwd.h"
-#include <new>
+#include "MemoryPool.h"
 
 CPLUSPLUS_BEGIN_HEADER
 CPLUSPLUS_BEGIN_NAMESPACE
 
-class CPLUSPLUS_EXPORT AST
+class CPLUSPLUS_EXPORT AST: public Managed
 {
     AST(const AST &other);
     void operator =(const AST &other);
@@ -74,10 +74,6 @@ public:
     static void accept(AST *ast, ASTVisitor *visitor)
     { if (ast) ast->accept(visitor); }
 
-    void *operator new(size_t size, MemoryPool *pool);
-    void operator delete(void *);
-    void operator delete(void *, MemoryPool *);
-
     virtual unsigned firstToken() const = 0;
     virtual unsigned lastToken() const = 0;
 
diff --git a/shared/cplusplus/MemoryPool.cpp b/shared/cplusplus/MemoryPool.cpp
index 639bb2c6164..a7c04691449 100644
--- a/shared/cplusplus/MemoryPool.cpp
+++ b/shared/cplusplus/MemoryPool.cpp
@@ -112,4 +112,19 @@ void *MemoryPool::allocate_helper(size_t size)
     return addr;
 }
 
+Managed::Managed()
+{ }
+
+Managed::~Managed()
+{ }
+
+void *Managed::operator new(size_t size, MemoryPool *pool)
+{ return pool->allocate(size); }
+
+void Managed::operator delete(void *)
+{ }
+
+void Managed::operator delete(void *, MemoryPool *)
+{ }
+
 CPLUSPLUS_END_NAMESPACE
diff --git a/shared/cplusplus/MemoryPool.h b/shared/cplusplus/MemoryPool.h
index 8d1f09b54e8..9647b673a6e 100644
--- a/shared/cplusplus/MemoryPool.h
+++ b/shared/cplusplus/MemoryPool.h
@@ -55,6 +55,7 @@
 
 #include "CPlusPlusForwardDeclarations.h"
 #include <cstddef>
+#include <new>
 
 CPLUSPLUS_BEGIN_HEADER
 CPLUSPLUS_BEGIN_NAMESPACE
@@ -99,6 +100,20 @@ private:
     };
 };
 
+class CPLUSPLUS_EXPORT Managed
+{
+    Managed(const Managed &other);
+    void operator = (const Managed &other);
+
+public:
+    Managed();
+    virtual ~Managed();
+
+    void *operator new(size_t size, MemoryPool *pool);
+    void operator delete(void *);
+    void operator delete(void *, MemoryPool *);
+};
+
 CPLUSPLUS_END_NAMESPACE
 CPLUSPLUS_END_HEADER
 
-- 
GitLab