From df1dc3d67d62f58f319e2d9ca1f69b2f12637004 Mon Sep 17 00:00:00 2001
From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz>
Date: Tue, 19 Jun 2018 16:17:54 +0200
Subject: [PATCH] document and tune code of objects

---
 alib2common/src/object/AnyObject.h     |  83 +++++++++++++--
 alib2common/src/object/ObjectFactory.h | 133 ++++++++++++++++++++++++-
 alib2common/src/object/Void.h          |  67 +++++++++++--
 3 files changed, 260 insertions(+), 23 deletions(-)

diff --git a/alib2common/src/object/AnyObject.h b/alib2common/src/object/AnyObject.h
index 8f30f2b1f2..80840396af 100644
--- a/alib2common/src/object/AnyObject.h
+++ b/alib2common/src/object/AnyObject.h
@@ -1,6 +1,22 @@
 /*
  * AnyObject.h
  *
+ * This file is part of Algorithms library toolkit.
+ * Copyright (C) 2017 Jan Travnicek (jan.travnicek@fit.cvut.cz)
+
+ * Algorithms library toolkit is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+
+ * Algorithms library toolkit is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with Algorithms library toolkit.  If not, see <http://www.gnu.org/licenses/>.
+ *
  *  Created on: Mar 26, 2013
  *      Author: Jan Travnicek
  */
@@ -15,37 +31,84 @@
 namespace object {
 
 /**
- * Represents void.
+ * \brief
+ * Represents an adaptor of any type to a class in type hierarchy of objects in the algorithms library.
+ *
+ * \tparam T the type of the wrapped object.
  */
 template < class T >
 class AnyObject final : public ObjectBase {
+	/**
+	 * \brief
+	 * The wrapped object.
+	 */
 	T m_data;
 public:
 	/**
-	 * Creates a blank symbol.
-	 * @param symbol name of the symbol
+	 * \brief
+	 * Constructor of the class based on the value of the wrapped object.
+	 *
+	 * \param data the object to be wrapped
 	 */
 	explicit AnyObject ( const T & data );
+
+	/**
+	 * \brief
+	 * Constructor of the class based on the value of the wrapped object.
+	 *
+	 * \param data the object to be wrapped
+	 */
 	explicit AnyObject ( T && data );
 
-	virtual ObjectBase * clone ( ) const &;
-	virtual ObjectBase * clone ( ) &&;
+	/**
+	 * @copydoc ObjectBase::clone ( ) const &
+	 */
+	virtual ObjectBase * clone ( ) const & override;
 
+	/**
+	 * @copydoc ObjectBase::clone ( ) &&
+	 */
+	virtual ObjectBase * clone ( ) && override;
+
+	/**
+	 * Getter of the wrapped object
+	 *
+	 * \return reference to the wrapped object.
+	 */
 	const T & getData ( ) const;
 
-	virtual int compare ( const ObjectBase & other ) const {
+	/**
+	 * @copydoc base::CommonBase < ObjectBase >::compare ( const ObjectBase & ) const
+	 */
+	virtual int compare ( const ObjectBase & other ) const override {
 		if ( ext::type_index ( typeid ( * this ) ) == ext::type_index ( typeid ( other ) ) ) return this->compare ( ( decltype ( * this ) )other );
 
 		return ext::type_index ( typeid ( * this ) ) - ext::type_index ( typeid ( other ) );
 	}
 
-	virtual int compare ( const AnyObject & other ) const;
+	/**
+	 * The actual compare method
+	 *
+	 * \param other the other instance
+	 *
+	 * \returns the actual relation between two by type same containers
+	 */
+	int compare ( const AnyObject & other ) const;
 
-	virtual void operator >>( std::ostream & out ) const;
+	/**
+	 * @copydoc base::CommonBase < ObjectBase >::operator >> ( std::ostream & ) const
+	 */
+	virtual void operator >>( std::ostream & out ) const override;
 
-	virtual explicit operator std::string ( ) const;
+	/**
+	 * @copydoc base::CommonBase < ObjectBase >::operator std::string ( ) const
+	 */
+	virtual explicit operator std::string ( ) const override;
 
-	virtual ObjectBase * inc ( ) &&;
+	/**
+	 * @copydoc object::ObjectBase::inc ( ) &&
+	 */
+	virtual ObjectBase * inc ( ) && override;
 };
 
 template < class T >
diff --git a/alib2common/src/object/ObjectFactory.h b/alib2common/src/object/ObjectFactory.h
index 749a83dc85..08447e4b11 100644
--- a/alib2common/src/object/ObjectFactory.h
+++ b/alib2common/src/object/ObjectFactory.h
@@ -1,6 +1,22 @@
 /*
  * ObjectFactory.h
  *
+ * This file is part of Algorithms library toolkit.
+ * Copyright (C) 2017 Jan Travnicek (jan.travnicek@fit.cvut.cz)
+
+ * Algorithms library toolkit is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+
+ * Algorithms library toolkit is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with Algorithms library toolkit.  If not, see <http://www.gnu.org/licenses/>.
+ *
  *  Created on: Mar 16, 2018
  *      Author: Jan Travnicek
  */
@@ -11,46 +27,157 @@
 #include "Object.h"
 #include <alib/variant>
 #include <object/AnyObject.h>
+#include <object/Void.h>
 
 namespace object {
 
+/**
+ * \brief
+ * Class representing uniqfied object construction.
+ *
+ * \details
+ * The class provides a static make method that is overloaded for some primitive types, variant, etc...
+ */
 class ObjectFactory {
+	/**
+	 * \brief
+	 * Variant access method to create object from variant containing void.
+	 */
+	template < class Variant, class Type, typename std::enable_if < std::is_same < Type, void >::value, Type * >::type * = nullptr >
+	static Object bypassVariant ( Variant && ) {
+		return Object ( Void { } );
+	}
+
+	/**
+	 * \brief
+	 * Variant access method to create object from variant containing something else than void.
+	 */
+	template < class Variant, class Type, typename std::enable_if < ! std::is_same < Type, void >::value, Type * >::type * = nullptr >
+	static Object bypassVariant ( Variant && data ) {
+		return make ( std::move ( data.template get < Type > ( ) ) );
+	}
+
+	/**
+	 * \brief
+	 * Helper method to detect variant content and call make method on the object from inside of the variant.
+	 */
 	template < class Variant, class Type, class ... Types >
 	static Object processVariant ( Variant && data ) {
 		if ( data.template is < Type > ( ) ) {
-			return make ( std::move ( data.template get < Type > ( ) ) );
+			return bypassVariant < Variant, Type > ( std::move ( data ) );
 		} else {
 			return processVariant < Variant, Types ... > ( std::move ( data ) );
 		}
 	}
 
+	/**
+	 * \brief
+	 * Root case of the variant traversing recursion.
+	 */
 	template < class Variant >
 	static Object processVariant ( Variant && ) {
 		throw std::logic_error ( "Variant state error" );
 	}
 
 public:
+	/**
+	 * \brief
+	 * Specialisation of the make method for booleans.
+	 */
 	static Object make ( bool boolean );
+
+	/**
+	 * \brief
+	 * Specialisation of the make method for charactes.
+	 */
 	static Object make ( char character );
+
+	/**
+	 * \brief
+	 * Specialisation of the make method for doubles.
+	 */
 	static Object make ( double number );
+
+	/**
+	 * \brief
+	 * Specialisation of the make method for integers.
+	 */
 	static Object make ( int number );
+
+	/**
+	 * \brief
+	 * Specialisation of the make method for strings.
+	 */
 	static Object make ( std::string string );
+
+	/**
+	 * \brief
+	 * Specialisation of the make method for c-strings.
+	 */
 	static Object make ( const char * string );
+
+	/**
+	 * \brief
+	 * Specialisation of the make method for unsigneds.
+	 */
 	static Object make ( unsigned number );
 
-	static Object make ( Object other ) {
+	/**
+	 * \brief
+	 * Specialisation of the make method for rvalue referenced objects.
+	 */
+	static Object && make ( Object && other ) {
+		return std::move ( other );
+	}
+
+	/**
+	 * \brief
+	 * Specialisation of the make method for lvalue referenced objects.
+	 */
+	static Object & make ( Object & other ) {
 		return other;
 	}
 
+	/**
+	 * \brief
+	 * Specialisation of the make method for constant lvalue referenced objects.
+	 */
+	static const Object & make ( const Object & other ) {
+		return other;
+	}
+
+	/**
+	 * \brief
+	 * Specialisation of the make method for objects that are not from the object hierarchy of Algorithms library
+	 */
 	template < class Type, typename std::enable_if < ! std::is_convertible < Type *, object::ObjectBase * >::value, Type >::type * = nullptr >
 	static Object make ( Type && data ) {
-		return Object ( object::AnyObject < Type > ( std::move ( data ) ) );
+		return Object ( object::AnyObject < Type > ( std::forward < Type > ( data ) ) );
 	}
 
+	/**
+	 * \brief
+	 * Specialisation of the make method for objects that are from the object hierarchy of Algorithms library
+	 */
 	static Object make ( object::ObjectBase && data ) {
 		return Object ( std::move ( data ) );
 	}
 
+	/**
+	 * \brief
+	 * Specialisation of the make method for objects that are from the object hierarchy of Algorithms library
+	 */
+	static Object make ( const object::ObjectBase & data ) {
+		return Object ( data );
+	}
+
+	/**
+	 * \brief
+	 * Specialisation of the make method for variants.
+	 *
+	 * \details
+	 * The resulting object is not constructed from the variant itself but from the value stored inside. If the value stored inside the variant is variant again, the process is repeated.
+	 */
 	template < class ... Types >
 	static Object make ( ext::variant < Types ... > && data ) {
 		return processVariant < ext::variant < Types ... >, Types ... > ( std::move ( data ) );
diff --git a/alib2common/src/object/Void.h b/alib2common/src/object/Void.h
index 563320a0b1..bc51b47c5a 100644
--- a/alib2common/src/object/Void.h
+++ b/alib2common/src/object/Void.h
@@ -1,6 +1,22 @@
 /*
  * Void.h
  *
+ * This file is part of Algorithms library toolkit.
+ * Copyright (C) 2017 Jan Travnicek (jan.travnicek@fit.cvut.cz)
+
+ * Algorithms library toolkit is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+
+ * Algorithms library toolkit is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with Algorithms library toolkit.  If not, see <http://www.gnu.org/licenses/>.
+ *
  *  Created on: Mar 26, 2013
  *      Author: Jan Travnicek
  */
@@ -13,34 +29,65 @@
 namespace object {
 
 /**
- * Represents void.
+ * \brief
+ * Represents void object.
  */
 class Void final : public ObjectBase {
 public:
 	/**
-	 * Creates a blank symbol.
-	 * @param symbol name of the symbol
+	 * \brief
+	 * Creates a new instance of void object
 	 */
 	explicit Void ( );
 
-	virtual ObjectBase * clone ( ) const &;
-	virtual ObjectBase * clone ( ) &&;
+	/**
+	 * @copydoc object::ObjectBase::clone ( ) const &
+	 */
+	virtual ObjectBase * clone ( ) const & override;
 
-	virtual int compare ( const ObjectBase & other ) const {
+	/**
+	 * @copydoc object::ObjectBase::clone ( ) &&
+	 */
+	virtual ObjectBase * clone ( ) && override;
+
+	/**
+	 * @copydoc base::CommonBase < ObjectBase >::compare ( const ObjectBase & ) const
+	 */
+	virtual int compare ( const ObjectBase & other ) const override {
 		if ( ext::type_index ( typeid ( * this ) ) == ext::type_index ( typeid ( other ) ) ) return this->compare ( ( decltype ( * this ) )other );
 
 		return ext::type_index ( typeid ( * this ) ) - ext::type_index ( typeid ( other ) );
 	}
 
-	virtual int compare ( const Void & other ) const;
+	/**
+	 * The actual compare method
+	 *
+	 * \param other the other instance
+	 *
+	 * \returns the actual relation between two by type same objects
+	 */
+	int compare ( const Void & other ) const;
 
-	virtual void operator >>( std::ostream & out ) const;
+	/**
+	 * @copydoc base::CommonBase < ObjectBase >::operator >> ( std::ostream & ) const
+	 */
+	virtual void operator >>( std::ostream & out ) const override;
 
-	virtual explicit operator std::string ( ) const;
+	/**
+	 * @copydoc base::CommonBase < ObjectBase >::operator std::string ( ) const
+	 */
+	virtual explicit operator std::string ( ) const override;
 
+	/**
+	 * \brief
+	 * Singleton instance of the void object.
+	 */
 	static Void VOID;
 
-	virtual ObjectBase * inc ( ) &&;
+	/**
+	 * @copydoc object::ObjectBase::inc ( ) &&
+	 */
+	virtual ObjectBase * inc ( ) && override;
 };
 
 } /* namespace object */
-- 
GitLab