From 4281f04b6b9b71b332e85d59c99b4ae7f035ef55 Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Thu, 25 Feb 2016 10:18:50 +0100 Subject: [PATCH] start splitting data classes and common classes --- .../common => alib2common/src/aux}/macros.h | 0 .../src/base/CommonBase.hpp | 14 +++---- .../src/base/WrapperBase.hpp | 38 +++++++++---------- .../src => alib2common/src/cast}/CastApi.hpp | 4 +- .../src/core}/multipleDispatch.hpp | 2 +- .../src/core}/visitor.hpp | 0 .../src/object/Object.cpp | 5 ++- .../src/object/Object.h | 7 +--- .../src/object/ObjectBase.h | 17 ++++----- .../src/object/Void.cpp | 7 ++-- {alib2data => alib2common}/src/object/Void.h | 2 +- .../test-src/core}/DispatchTest.cpp | 6 +-- .../test-src/core}/DispatchTest.h | 0 .../test-src/core}/VisitorTest.cpp | 6 +-- .../test-src/core}/VisitorTest.h | 0 alib2data/src/object/ObjectClasses.h | 13 ------- alib2data/src/object/ObjectFeatures.h | 24 ------------ alib2data/src/object/WrapperBase.h | 19 ---------- 18 files changed, 53 insertions(+), 111 deletions(-) rename {alib2data/src/common => alib2common/src/aux}/macros.h (100%) rename alib2data/src/common/base.hpp => alib2common/src/base/CommonBase.hpp (86%) rename alib2data/src/common/wrapper.hpp => alib2common/src/base/WrapperBase.hpp (57%) rename {alib2data/src => alib2common/src/cast}/CastApi.hpp (98%) rename {alib2data/src/common => alib2common/src/core}/multipleDispatch.hpp (99%) rename {alib2data/src/common => alib2common/src/core}/visitor.hpp (100%) rename {alib2data => alib2common}/src/object/Object.cpp (67%) rename {alib2data => alib2common}/src/object/Object.h (73%) rename {alib2data => alib2common}/src/object/ObjectBase.h (53%) rename {alib2data => alib2common}/src/object/Void.cpp (87%) rename {alib2data => alib2common}/src/object/Void.h (98%) rename {alib2data/test-src/common => alib2common/test-src/core}/DispatchTest.cpp (97%) rename {alib2data/test-src/common => alib2common/test-src/core}/DispatchTest.h (100%) rename {alib2data/test-src/common => alib2common/test-src/core}/VisitorTest.cpp (97%) rename {alib2data/test-src/common => alib2common/test-src/core}/VisitorTest.h (100%) delete mode 100644 alib2data/src/object/ObjectClasses.h delete mode 100644 alib2data/src/object/ObjectFeatures.h delete mode 100644 alib2data/src/object/WrapperBase.h diff --git a/alib2data/src/common/macros.h b/alib2common/src/aux/macros.h similarity index 100% rename from alib2data/src/common/macros.h rename to alib2common/src/aux/macros.h diff --git a/alib2data/src/common/base.hpp b/alib2common/src/base/CommonBase.hpp similarity index 86% rename from alib2data/src/common/base.hpp rename to alib2common/src/base/CommonBase.hpp index 2208457c70..fe14a12b33 100644 --- a/alib2data/src/common/base.hpp +++ b/alib2common/src/base/CommonBase.hpp @@ -1,12 +1,12 @@ /* - * Base.h + * CommonBase.h * * Created on: Apr 05, 2014 * Author: Jan Travnicek */ -#ifndef BASE_H_ -#define BASE_H_ +#ifndef COMMON_BASE_H_ +#define COMMON_BASE_H_ #include <typeinfo> #include <typeindex> @@ -15,10 +15,10 @@ namespace alib { -template < typename T > -class base { +template< typename T > +class CommonBase { public: - virtual ~base ( ) noexcept { } + virtual ~CommonBase ( ) noexcept { } virtual T * clone ( ) const = 0; @@ -62,4 +62,4 @@ public: } /* namespace alib */ -#endif /* BASE_H_ */ +#endif /* COMMON_BASE_H_ */ diff --git a/alib2data/src/common/wrapper.hpp b/alib2common/src/base/WrapperBase.hpp similarity index 57% rename from alib2data/src/common/wrapper.hpp rename to alib2common/src/base/WrapperBase.hpp index bc3be6c6db..1a655b9f19 100644 --- a/alib2data/src/common/wrapper.hpp +++ b/alib2common/src/base/WrapperBase.hpp @@ -1,12 +1,12 @@ /* - * wrapper.h + * WrapperBase.h * * Created on: Apr 10, 2013 * Author: Jan Travnicek */ -#ifndef WRAPPER_H_ -#define WRAPPER_H_ +#ifndef WRAPPER_BASE_H_ +#define WRAPPER_BASE_H_ #include <ostream> #include <memory> @@ -14,12 +14,12 @@ namespace alib { template < typename T > -class wrapper { +class WrapperBase { protected: std::cow_shared_ptr < T > data; private: - void unify ( wrapper & other ) { + void unify ( WrapperBase & other ) { if ( this->data.getUseCount ( ) > other.data.getUseCount ( ) ) other.data = this->data; else @@ -27,16 +27,16 @@ private: } public: - explicit wrapper ( T * data ) : data ( data ) { + explicit WrapperBase ( T * data ) : data ( data ) { } - explicit wrapper ( const T & data ) : data ( data.clone ( ) ) { + explicit WrapperBase ( const T & data ) : data ( data.clone ( ) ) { } - explicit wrapper ( T && data ) : data ( std::move ( data ).plunder ( ) ) { + explicit WrapperBase ( T && data ) : data ( std::move ( data ).plunder ( ) ) { } - virtual ~wrapper ( ) noexcept { + virtual ~WrapperBase ( ) noexcept { } const T & getData ( ) const { @@ -59,41 +59,41 @@ public: this->data = std::cow_shared_ptr < T > ( std::move ( data ).plunder ( ) ); } - bool operator >=( const wrapper & other ) const { + bool operator >=( const WrapperBase & other ) const { return this->compare ( other ) >= 0; } - bool operator <=( const wrapper & other ) const { + bool operator <=( const WrapperBase & other ) const { return this->compare ( other ) <= 0; } - bool operator >( const wrapper & other ) const { + bool operator >( const WrapperBase & other ) const { return this->compare ( other ) > 0; } - bool operator <( const wrapper & other ) const { + bool operator <( const WrapperBase & other ) const { return this->compare ( other ) < 0; } - bool operator !=( const wrapper & other ) const { + bool operator !=( const WrapperBase & other ) const { return this->compare ( other ) != 0; } - bool operator ==( const wrapper & other ) const { + bool operator ==( const WrapperBase & other ) const { return this->compare ( other ) == 0; } - int compare ( const wrapper & other ) const { + int compare ( const WrapperBase & other ) const { if ( this->data.get ( ) == other.data.get ( ) ) return 0; int res = ( * this->data ).compare ( * other.data ); - if ( res == 0 ) const_cast < wrapper * > ( this )->unify ( const_cast < wrapper & > ( other ) ); + if ( res == 0 ) const_cast < WrapperBase * > ( this )->unify ( const_cast < WrapperBase & > ( other ) ); return res; } - friend std::ostream & operator <<( std::ostream & os, const wrapper & instance ) { + friend std::ostream & operator <<( std::ostream & os, const WrapperBase & instance ) { os << * ( instance.data ); return os; } @@ -105,4 +105,4 @@ public: } /* namespace alib */ -#endif /* WRAPPER_H_ */ +#endif /* WRAPPER_BASE_H_ */ diff --git a/alib2data/src/CastApi.hpp b/alib2common/src/cast/CastApi.hpp similarity index 98% rename from alib2data/src/CastApi.hpp rename to alib2common/src/cast/CastApi.hpp index 8ef174d98b..aa20ddda6f 100644 --- a/alib2data/src/CastApi.hpp +++ b/alib2common/src/cast/CastApi.hpp @@ -12,8 +12,8 @@ #include <map> #include <string> -#include "object/ObjectBase.h" -#include "object/Object.h" +#include "../object/ObjectBase.h" +#include "../object/Object.h" namespace alib { diff --git a/alib2data/src/common/multipleDispatch.hpp b/alib2common/src/core/multipleDispatch.hpp similarity index 99% rename from alib2data/src/common/multipleDispatch.hpp rename to alib2common/src/core/multipleDispatch.hpp index a283962525..23edf7be7c 100644 --- a/alib2data/src/common/multipleDispatch.hpp +++ b/alib2common/src/core/multipleDispatch.hpp @@ -13,7 +13,7 @@ #include <map> #include <iostream> -#include "../CastApi.hpp" +#include "../cast/CastApi.hpp" namespace std { diff --git a/alib2data/src/common/visitor.hpp b/alib2common/src/core/visitor.hpp similarity index 100% rename from alib2data/src/common/visitor.hpp rename to alib2common/src/core/visitor.hpp diff --git a/alib2data/src/object/Object.cpp b/alib2common/src/object/Object.cpp similarity index 67% rename from alib2data/src/object/Object.cpp rename to alib2common/src/object/Object.cpp index e67f323e48..98aa407e10 100644 --- a/alib2data/src/object/Object.cpp +++ b/alib2common/src/object/Object.cpp @@ -6,7 +6,7 @@ */ #include "Object.h" -#include "../XmlApi.hpp" +// #include "../XmlApi.hpp" namespace alib { @@ -16,5 +16,6 @@ const std::string Object::XML_TAG_NAME_REF = "ObjectRef"; namespace alib { -auto ObjectDeleter = xmlApi < alib::Object >::InputContextDeleter ( ); +// TODO +// auto ObjectDeleter = xmlApi < alib::Object >::InputContextDeleter ( ); } diff --git a/alib2data/src/object/Object.h b/alib2common/src/object/Object.h similarity index 73% rename from alib2data/src/object/Object.h rename to alib2common/src/object/Object.h index 19b4f0937a..c561016253 100644 --- a/alib2data/src/object/Object.h +++ b/alib2common/src/object/Object.h @@ -8,18 +8,15 @@ #ifndef OBJECT_H_ #define OBJECT_H_ -#include "../object/WrapperBase.h" +#include "../base/WrapperBase.hpp" #include "ObjectBase.h" -#include "../common/wrapper.hpp" namespace alib { /** * Wrapper around object. */ -class Object : public alib::wrapper < ObjectBase >, public alib::WrapperBase { - using alib::wrapper < ObjectBase >::wrapper; - +class Object : public alib::WrapperBase < ObjectBase > { public: const static std::string XML_TAG_NAME_REF; }; diff --git a/alib2data/src/object/ObjectBase.h b/alib2common/src/object/ObjectBase.h similarity index 53% rename from alib2data/src/object/ObjectBase.h rename to alib2common/src/object/ObjectBase.h index 7c8e7b03c8..1aa39606cf 100644 --- a/alib2data/src/object/ObjectBase.h +++ b/alib2common/src/object/ObjectBase.h @@ -8,21 +8,19 @@ #ifndef OBJECT_BASE_H_ #define OBJECT_BASE_H_ -#include <compare> -#include <memory> -#include <deque> -#include "../common/base.hpp" -#include <sax/Token.h> +#include "../base/CommonBase.hpp" namespace alib { -class ObjectBase : public alib::base<ObjectBase>, public std::cow_shared_ptr_base { +/** + * Represents generic object. + */ +class ObjectBase : public alib::CommonBase<ObjectBase> { public: - virtual void compose(std::deque<sax::Token>& out) const = 0; + virtual ObjectBase* clone() const = 0; + virtual ObjectBase* plunder() && = 0; }; -// ---------------------------------------------------------------------------------------------------------------------- - } /* namespace alib */ namespace std { @@ -37,3 +35,4 @@ struct compare<alib::ObjectBase> { } /* namespace std */ #endif /* OBJECT_BASE_H_ */ + diff --git a/alib2data/src/object/Void.cpp b/alib2common/src/object/Void.cpp similarity index 87% rename from alib2data/src/object/Void.cpp rename to alib2common/src/object/Void.cpp index 9b1b77d06d..596f1c0cd4 100644 --- a/alib2data/src/object/Void.cpp +++ b/alib2common/src/object/Void.cpp @@ -6,9 +6,9 @@ */ #include "Void.h" -#include <sax/FromXMLParserHelper.h> +#include "../sax/FromXMLParserHelper.h" #include "Object.h" -#include "../XmlApi.hpp" +// #include "../XmlApi.hpp" namespace alib { @@ -55,7 +55,8 @@ void Void::compose(std::deque<sax::Token>& out) const { namespace alib { -auto voidParserRegister = xmlApi<alib::Object>::ParserRegister<alib::Void>(); +// TODO +// auto voidParserRegister = xmlApi<alib::Object>::ParserRegister<alib::Void>(); } /* namespace alib */ diff --git a/alib2data/src/object/Void.h b/alib2common/src/object/Void.h similarity index 98% rename from alib2data/src/object/Void.h rename to alib2common/src/object/Void.h index e417188a8f..a8f5f64ddb 100644 --- a/alib2data/src/object/Void.h +++ b/alib2common/src/object/Void.h @@ -10,7 +10,7 @@ #include "ObjectBase.h" #include <deque> -#include <sax/Token.h> +#include "../sax/Token.h" namespace alib { diff --git a/alib2data/test-src/common/DispatchTest.cpp b/alib2common/test-src/core/DispatchTest.cpp similarity index 97% rename from alib2data/test-src/common/DispatchTest.cpp rename to alib2common/test-src/core/DispatchTest.cpp index 443c9b0ad6..0de0412ca1 100644 --- a/alib2data/test-src/common/DispatchTest.cpp +++ b/alib2common/test-src/core/DispatchTest.cpp @@ -1,6 +1,6 @@ #include "DispatchTest.h" -#include "common/multipleDispatch.hpp" -#include "common/base.hpp" +#include "core/multipleDispatch.hpp" +#include "base/CommonBase.hpp" #include <set> #include <string> @@ -15,7 +15,7 @@ void DispatchTest::tearDown ( ) { namespace dispatch { -class TmpBase : public alib::base < TmpBase > { +class TmpBase : public alib::CommonBase < TmpBase > { }; class Tmp1 : public TmpBase { diff --git a/alib2data/test-src/common/DispatchTest.h b/alib2common/test-src/core/DispatchTest.h similarity index 100% rename from alib2data/test-src/common/DispatchTest.h rename to alib2common/test-src/core/DispatchTest.h diff --git a/alib2data/test-src/common/VisitorTest.cpp b/alib2common/test-src/core/VisitorTest.cpp similarity index 97% rename from alib2data/test-src/common/VisitorTest.cpp rename to alib2common/test-src/core/VisitorTest.cpp index 603ae63d6c..dcc79c0172 100644 --- a/alib2data/test-src/common/VisitorTest.cpp +++ b/alib2common/test-src/core/VisitorTest.cpp @@ -1,6 +1,6 @@ #include "VisitorTest.h" -#include "common/visitor.hpp" -#include "common/base.hpp" +#include "core/visitor.hpp" +#include "base/CommonBase.hpp" #include <set> #include <string> @@ -23,7 +23,7 @@ class TmpBase; typedef std::acceptor_base < TmpBase, Tmp1, Tmp2, Tmp3 > VisitableTmpBase; -class TmpBase : public alib::base < TmpBase >, public VisitableTmpBase { +class TmpBase : public alib::CommonBase < TmpBase >, public VisitableTmpBase { }; class Tmp1 : public std::acceptor < Tmp1, VisitableTmpBase, TmpBase > { diff --git a/alib2data/test-src/common/VisitorTest.h b/alib2common/test-src/core/VisitorTest.h similarity index 100% rename from alib2data/test-src/common/VisitorTest.h rename to alib2common/test-src/core/VisitorTest.h diff --git a/alib2data/src/object/ObjectClasses.h b/alib2data/src/object/ObjectClasses.h deleted file mode 100644 index a1e45f0caa..0000000000 --- a/alib2data/src/object/ObjectClasses.h +++ /dev/null @@ -1,13 +0,0 @@ -/* - * ObjectClasses.h - * - * Created on: Jun 19, 2014 - * Author: Jan Travnicek - */ - -#ifndef OBJECT_CLASSES_H_ -#define OBJECT_CLASSES_H_ - -#include "Void.h" - -#endif /* OBJECT_CLASSES_H_ */ diff --git a/alib2data/src/object/ObjectFeatures.h b/alib2data/src/object/ObjectFeatures.h deleted file mode 100644 index a57aa1f843..0000000000 --- a/alib2data/src/object/ObjectFeatures.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * ObjectFeatures.h - * - * Created on: Jun 19, 2014 - * Author: Jan Travnicek - */ - -#ifndef OBJECT_FEATURES_H_ -#define OBJECT_FEATURES_H_ - -namespace alib { - -enum class FEATURES { - VOID -}; - -class Object; -class ObjectBase; - -class Void; - -} /* namespace alib */ - -#endif /* OBJECT_FEATURES_H_ */ diff --git a/alib2data/src/object/WrapperBase.h b/alib2data/src/object/WrapperBase.h deleted file mode 100644 index 39abe6180f..0000000000 --- a/alib2data/src/object/WrapperBase.h +++ /dev/null @@ -1,19 +0,0 @@ -/* - * WrapperBase.h - * - * Created on: Apr 10, 2013 - * Author: Jan Travnicek - */ - -#ifndef WRAPPER_BASE_H_ -#define WRAPPER_BASE_H_ - -#include <compare> - -namespace alib { - -class WrapperBase {}; - -} /* namespace alib */ - -#endif /* WRAPPER_BASE_H_ */ -- GitLab