From 85168cc7d7df6ef16cdd93c7a2cda8651647581b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Radovan=20=C4=8Cerven=C3=BD?= <radovan.cerveny@gmail.com>
Date: Thu, 11 Feb 2016 15:39:49 +0100
Subject: [PATCH] separated stealth allocator and dependent types into a
 dedicated folder

---
 .../src/allocator/StealthAllocator.hpp        | 33 +++++++++++++++++++
 alib2measure/src/allocator/StealthTypes.cpp   | 16 +++++++++
 alib2measure/src/allocator/StealthTypes.hpp   | 28 ++++++++++++++++
 .../src/measurements/MeasurementTypes.cpp     |  8 -----
 .../src/measurements/MeasurementTypes.hpp     | 30 +----------------
 5 files changed, 78 insertions(+), 37 deletions(-)
 create mode 100644 alib2measure/src/allocator/StealthAllocator.hpp
 create mode 100644 alib2measure/src/allocator/StealthTypes.cpp
 create mode 100644 alib2measure/src/allocator/StealthTypes.hpp

diff --git a/alib2measure/src/allocator/StealthAllocator.hpp b/alib2measure/src/allocator/StealthAllocator.hpp
new file mode 100644
index 0000000000..c44d6f9f06
--- /dev/null
+++ b/alib2measure/src/allocator/StealthAllocator.hpp
@@ -0,0 +1,33 @@
+/*
+ * Author: Radovan Cerveny
+ */
+
+#ifndef STEALTH_ALLOCATOR_HPP_
+#define STEALTH_ALLOCATOR_HPP_
+
+#include <memory>
+
+namespace measurements {
+
+template < typename T >
+class stealth_allocator : public std::allocator < T > {
+public:
+	using pointer = T *;
+	using size_type = size_t;
+
+	pointer allocate ( size_type n ) {
+		return static_cast < pointer > ( operator new( n * sizeof ( T ), false ) );
+	}
+
+	void deallocate ( pointer ptr, size_type ) {
+		operator delete( ptr, false );
+	}
+
+	template < typename U >
+	struct rebind { using other = stealth_allocator < U >; };
+
+};
+
+}
+
+#endif /* STEALTH_ALLOCATOR_HPP_ */
diff --git a/alib2measure/src/allocator/StealthTypes.cpp b/alib2measure/src/allocator/StealthTypes.cpp
new file mode 100644
index 0000000000..07d00967e3
--- /dev/null
+++ b/alib2measure/src/allocator/StealthTypes.cpp
@@ -0,0 +1,16 @@
+/*
+ * Author: Radovan Cerveny
+ */
+#include "StealthTypes.hpp"
+
+namespace measurements {
+
+std::string to_string ( const stealth_string & ss ) {
+	return ss.c_str ( );
+}
+
+std::string to_string ( stealth_string & ss ) {
+	return ss.c_str ( );
+}
+
+}
diff --git a/alib2measure/src/allocator/StealthTypes.hpp b/alib2measure/src/allocator/StealthTypes.hpp
new file mode 100644
index 0000000000..c389401fae
--- /dev/null
+++ b/alib2measure/src/allocator/StealthTypes.hpp
@@ -0,0 +1,28 @@
+/*
+ * Author: Radovan Cerveny
+ */
+
+#ifndef STEALTH_TYPES_HPP_
+#define STEALTH_TYPES_HPP_
+
+#include <string>
+#include <vector>
+#include <map>
+#include "StealthAllocator.hpp"
+
+namespace measurements {
+
+using stealth_string = std::basic_string < char, std::char_traits < char >, stealth_allocator < char > >;
+
+std::string to_string ( const stealth_string & );
+std::string to_string ( stealth_string & );
+
+template < typename T >
+using stealth_vector = std::vector < T, stealth_allocator < T > >;
+
+template < class Key, class T, class Compare = std::less < Key > >
+using stealth_map = std::map < Key, T, Compare, stealth_allocator < std::pair < const Key, T > > >;
+
+}
+
+#endif /* STEALTH_TYPES_HPP_ */
diff --git a/alib2measure/src/measurements/MeasurementTypes.cpp b/alib2measure/src/measurements/MeasurementTypes.cpp
index ed97f8ae78..47f29c9038 100644
--- a/alib2measure/src/measurements/MeasurementTypes.cpp
+++ b/alib2measure/src/measurements/MeasurementTypes.cpp
@@ -34,12 +34,4 @@ std::ostream & operator <<( std::ostream & os, Type t ) {
 	return os;
 }
 
-std::string to_string ( const stealth_string & ss ) {
-	return ss.c_str ( );
-}
-
-std::string to_string ( stealth_string & ss ) {
-	return ss.c_str ( );
-}
-
 }
diff --git a/alib2measure/src/measurements/MeasurementTypes.hpp b/alib2measure/src/measurements/MeasurementTypes.hpp
index b1338a7824..38e3ed64e2 100644
--- a/alib2measure/src/measurements/MeasurementTypes.hpp
+++ b/alib2measure/src/measurements/MeasurementTypes.hpp
@@ -9,6 +9,7 @@
 #include <vector>
 #include <map>
 #include "MeasurementNew.hpp"
+#include "../allocator/StealthTypes.hpp"
 
 namespace measurements {
 
@@ -19,35 +20,6 @@ enum class Type : unsigned {
 std::string to_string ( Type );
 std::ostream & operator <<( std::ostream &, Type );
 
-template < typename T >
-class stealth_allocator : public std::allocator < T > {
-public:
-	using pointer = T *;
-	using size_type = size_t;
-
-	pointer allocate ( size_type n ) {
-		return static_cast < pointer > ( operator new( n * sizeof ( T ), false ) );
-	}
-
-	void deallocate ( pointer ptr, size_type ) {
-		operator delete( ptr, false );
-	}
-
-	template < typename U >
-	struct rebind { using other = stealth_allocator < U >; };
-
-};
-
-using stealth_string = std::basic_string < char, std::char_traits < char >, stealth_allocator < char > >;
-
-std::string to_string ( const stealth_string & );
-std::string to_string ( stealth_string & );
-
-template < typename T >
-using stealth_vector = std::vector < T, stealth_allocator < T > >;
-
-template < class Key, class T, class Compare = std::less < Key > >
-using stealth_map = std::map < Key, T, Compare, stealth_allocator < std::pair < const Key, T > > >;
 }
 
 #endif /* MEASUREMENT_TYPES_HPP_ */
-- 
GitLab