From d7a8b2e6404178421e2b907b63be0ef7d5764377 Mon Sep 17 00:00:00 2001
From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz>
Date: Tue, 27 Dec 2016 14:59:04 +0100
Subject: [PATCH] component element naming in error report

---
 alib2common/src/core/components.hpp | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/alib2common/src/core/components.hpp b/alib2common/src/core/components.hpp
index 395ac54f38..1dca989670 100644
--- a/alib2common/src/core/components.hpp
+++ b/alib2common/src/core/components.hpp
@@ -12,6 +12,7 @@
 #include <algorithm>
 #include <utility>
 #include <tuple>
+#include <typeinfo>
 #include "../exception/CommonException.h"
 
 namespace std {
@@ -72,8 +73,11 @@ class Component {
 	void checkAdd ( const DataType & symbol ) {
 		ComponentConstraint < Derived, DataType, SetType >::valid ( static_cast < const Derived & > ( * this ), symbol );
 
-		if ( !ComponentConstraint < Derived, DataType, SetType >::available ( static_cast < const Derived & > ( * this ), symbol ) )
-			throw::exception::CommonException ( "Symbol " + std::to_string ( symbol ) + " is not available." );
+		if ( !ComponentConstraint < Derived, DataType, SetType >::available ( static_cast < const Derived & > ( * this ), symbol ) ) {
+			std::string elementTypeName ( std::type_name < SetType * > ( ) );
+			elementTypeName.back ( ) = ' ';
+			throw::exception::CommonException ( elementTypeName + "element " + std::to_string ( symbol ) + " is not available." );
+		}
 	}
 
 	/**
@@ -81,8 +85,11 @@ class Component {
 	 * @throws CommonException if symbol cannot be removed.
 	 */
 	void checkRemove ( const DataType & symbol ) {
-		if ( ComponentConstraint < Derived, DataType, SetType >::used ( static_cast < const Derived & > ( * this ), symbol ) )
-			throw::exception::CommonException ( "Symbol " + std::to_string ( symbol ) + " is used." );
+		if ( ComponentConstraint < Derived, DataType, SetType >::used ( static_cast < const Derived & > ( * this ), symbol ) ) {
+			std::string elementTypeName ( std::type_name < SetType * > ( ) );
+			elementTypeName.back ( ) = ' ';
+			throw::exception::CommonException ( elementTypeName + "element " + std::to_string ( symbol ) + " is used." );
+		}
 	}
 
 protected:
@@ -231,8 +238,11 @@ class Element {
 	void checkSet ( const DataType & symbol ) {
 		ElementConstraint < Derived, DataType, ElementType >::valid ( static_cast < const Derived & > ( * this ), symbol );
 
-		if ( !ElementConstraint < Derived, DataType, ElementType >::available ( static_cast < const Derived & > ( * this ), symbol ) )
-			throw::exception::CommonException ( "Symbol " + std::to_string ( symbol ) + " is not available." );
+		if ( !ElementConstraint < Derived, DataType, ElementType >::available ( static_cast < const Derived & > ( * this ), symbol ) ) {
+			std::string elementTypeName ( std::type_name < ElementType * > ( ) );
+			elementTypeName.back ( ) = ' ';
+			throw::exception::CommonException ( elementTypeName + std::to_string ( symbol ) + " is not available." );
+		}
 	}
 
 protected:
-- 
GitLab