From d9a9b038e653fdcfe78807bae3a18efebd088252 Mon Sep 17 00:00:00 2001
From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz>
Date: Mon, 21 Aug 2017 09:12:29 +0200
Subject: [PATCH] split ValueOperations and ValueProviders

---
 .../abstraction/ValueOperationAbstraction.hpp | 72 +-------------
 alib2common/src/abstraction/ValueProvider.hpp | 97 +++++++++++++++++++
 2 files changed, 98 insertions(+), 71 deletions(-)
 create mode 100644 alib2common/src/abstraction/ValueProvider.hpp

diff --git a/alib2common/src/abstraction/ValueOperationAbstraction.hpp b/alib2common/src/abstraction/ValueOperationAbstraction.hpp
index 8e1a605921..1b947fb649 100644
--- a/alib2common/src/abstraction/ValueOperationAbstraction.hpp
+++ b/alib2common/src/abstraction/ValueOperationAbstraction.hpp
@@ -14,80 +14,10 @@
 #include <typeindex>
 #include <variant>
 #include <abstraction/Registry.h>
+#include <abstraction/ValueProvider.hpp>
 
 namespace abstraction {
 
-template < class Type >
-class ValueProvider {
-	bool m_move;
-
-protected:
-	virtual Type & getData ( ) const = 0;
-
-public:
-	typedef Type return_type;
-
-	ValueProvider ( ) : m_move ( false ) {
-	}
-
-	void setMove ( bool move ) {
-		m_move = move;
-	}
-
-	Type getValue ( ) const {
-		if ( m_move )
-			return std::move ( getData ( ) );
-		else
-			return getData ( );
-	}
-
-	virtual bool eval ( ) = 0;
-
-	virtual bool isReady ( ) const = 0;
-};
-
-template < class Type >
-class ValueProvider < Type & > {
-protected:
-	virtual Type & getData ( ) const = 0;
-
-public:
-	typedef Type return_type;
-
-	Type & getValueReference ( ) const {
-		return getData ( );
-	}
-
-	Type & getValue ( ) const {
-		return getData ( );
-	}
-
-	virtual bool eval ( ) = 0;
-
-	virtual bool isReady ( ) const = 0;
-};
-
-template < class Type >
-class ValueProvider < const Type & > {
-protected:
-	virtual const Type & getConstData ( ) const = 0;
-
-public:
-	typedef Type return_type;
-
-	const Type & getConstValueReference ( ) const {
-		return getConstData ( );
-	}
-
-	const Type & getValue ( ) const{
-		return getConstData ( );
-	}
-
-	virtual bool eval ( ) = 0;
-
-	virtual bool isReady ( ) const = 0;
-};
-
 template < class ReturnType >
 class ValueOperationAbstraction : public OperationAbstraction, public ValueProvider < ReturnType >, public ValueProvider < ReturnType & >, public ValueProvider < const ReturnType & > {
 protected:
diff --git a/alib2common/src/abstraction/ValueProvider.hpp b/alib2common/src/abstraction/ValueProvider.hpp
new file mode 100644
index 0000000000..92dd206d0b
--- /dev/null
+++ b/alib2common/src/abstraction/ValueProvider.hpp
@@ -0,0 +1,97 @@
+/*
+ * ValueProvider.hpp
+ *
+ *  Created on: 11. 7. 2017
+ *	  Author: Jan Travnicek
+ */
+
+#ifndef _VALUE_PROVIDER_HPP_
+#define _VALUE_PROVIDER_HPP_
+
+#include <exception/CommonException.h>
+#include <utility>
+
+namespace abstraction {
+
+template < class Type >
+class ValueProvider {
+	bool m_move;
+
+protected:
+	virtual Type & getData ( ) const = 0;
+
+public:
+	typedef Type return_type;
+
+	ValueProvider ( ) : m_move ( false ) {
+	}
+
+	void setMove ( bool move ) {
+		m_move = move;
+	}
+
+	Type getValue ( ) const {
+		if ( m_move )
+			return std::move ( getData ( ) );
+		else
+			return getData ( );
+	}
+
+	virtual bool eval ( ) = 0;
+
+	virtual bool isReady ( ) const = 0;
+};
+
+template < class Type >
+class ValueProvider < Type & > {
+protected:
+	virtual Type & getData ( ) const = 0;
+
+public:
+	typedef Type return_type;
+
+	void setMove ( bool ) {
+		throw exception::CommonException ( "Reference cannot be moved." );
+	}
+
+	Type & getValueReference ( ) const {
+		return getData ( );
+	}
+
+	Type & getValue ( ) const {
+		return getData ( );
+	}
+
+	virtual bool eval ( ) = 0;
+
+	virtual bool isReady ( ) const = 0;
+};
+
+template < class Type >
+class ValueProvider < const Type & > {
+protected:
+	virtual const Type & getConstData ( ) const = 0;
+
+public:
+	typedef Type return_type;
+
+	void setMove ( bool ) {
+		throw exception::CommonException ( "Const reference cannot be moved." );
+	}
+
+	const Type & getConstValueReference ( ) const {
+		return getConstData ( );
+	}
+
+	const Type & getValue ( ) const{
+		return getConstData ( );
+	}
+
+	virtual bool eval ( ) = 0;
+
+	virtual bool isReady ( ) const = 0;
+};
+
+} /* namespace abstraction */
+
+#endif /* _VALUE_PROVIDER_HPP_ */
-- 
GitLab