From 5a9ded20fbb25d1a51c315c5a6e867b7afa422de Mon Sep 17 00:00:00 2001
From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz>
Date: Thu, 21 May 2015 17:20:38 +0200
Subject: [PATCH] simplify types spec

---
 alib2data/src/alphabet/SymbolBase.h     | 19 ++++++--
 alib2data/src/automaton/AutomatonBase.h | 21 +++++++--
 alib2data/src/container/ContainerBase.h | 24 +++++++---
 alib2data/src/grammar/GrammarBase.h     | 21 +++++++--
 alib2data/src/graph/GraphBase.h         | 29 +++++++++---
 alib2data/src/label/LabelBase.h         | 21 +++++++--
 alib2data/src/object/ObjectBase.h       | 62 +++++++++++++++++++------
 alib2data/src/primitive/PrimitiveBase.h | 21 +++++++--
 alib2data/src/regexp/RegExpBase.h       | 22 +++++++--
 alib2data/src/string/StringBase.h       | 24 ++++++++--
 alib2data/src/tree/TreeBase.h           | 21 +++++++--
 11 files changed, 226 insertions(+), 59 deletions(-)

diff --git a/alib2data/src/alphabet/SymbolBase.h b/alib2data/src/alphabet/SymbolBase.h
index 44781e16d1..40511b9bcb 100644
--- a/alib2data/src/alphabet/SymbolBase.h
+++ b/alib2data/src/alphabet/SymbolBase.h
@@ -14,9 +14,22 @@ namespace alphabet {
 
 class SymbolBase;
 
-typedef std::acceptor_base<SymbolBase,
-			EndSymbol, LabeledSymbol, BlankSymbol, BottomOfTheStackSymbol, RankedSymbol, BarSymbol, RankedBarSymbol, SubtreeWildcardSymbol, SymbolSetSymbol, SymbolPairSymbol, UniqueSymbol, StartSymbol
-	> VisitableSymbolBase;
+// ----------------------------------------------------------------------------------------------------------------------
+
+template<typename T>
+class acceptor_base_helper {
+};
+
+template<typename ... Ts>
+class acceptor_base_helper< std::tuple< Ts ... > > :
+	public std::acceptor_base<
+			SymbolBase, Ts ...
+	> {
+};
+
+typedef acceptor_base_helper< alib::SymbolTypes > VisitableSymbolBase;
+
+// ----------------------------------------------------------------------------------------------------------------------
 
 /**
  * Represents symbol in an alphabet.
diff --git a/alib2data/src/automaton/AutomatonBase.h b/alib2data/src/automaton/AutomatonBase.h
index ebcfc1846a..10fb746870 100644
--- a/alib2data/src/automaton/AutomatonBase.h
+++ b/alib2data/src/automaton/AutomatonBase.h
@@ -15,12 +15,25 @@ namespace automaton {
 
 class AutomatonBase;
 
-typedef std::acceptor_base<AutomatonBase,
-			automaton::DFA, automaton::NFA, automaton::MultiInitialStateNFA, automaton::EpsilonNFA, automaton::CompactNFA, automaton::ExtendedNFA, automaton::DFTA, automaton::NFTA, automaton::DPDA, automaton::SinglePopDPDA, automaton::InputDrivenDPDA, automaton::VisiblyPushdownDPDA, automaton::RealTimeHeightDeterministicDPDA, automaton::NPDA, automaton::SinglePopNPDA, automaton::InputDrivenNPDA, automaton::VisiblyPushdownNPDA, automaton::RealTimeHeightDeterministicNPDA, automaton::OneTapeDTM
-	> VisitableAutomatonBase;
+// ----------------------------------------------------------------------------------------------------------------------
+
+template<typename T>
+class acceptor_base_helper {
+};
+
+template<typename ... Ts>
+class acceptor_base_helper< std::tuple< Ts ... > > :
+	public std::acceptor_base<
+			AutomatonBase, Ts ...
+	> {
+};
+
+typedef acceptor_base_helper< alib::AutomatonTypes > VisitableAutomatonBase;
+
+// ----------------------------------------------------------------------------------------------------------------------
 
 /**
- * Abstract base class for all automata.
+ * Represents symbol in an alphabet.
  */
 class AutomatonBase : public alib::ObjectBase, public VisitableAutomatonBase {
 public:
diff --git a/alib2data/src/container/ContainerBase.h b/alib2data/src/container/ContainerBase.h
index 84608d550e..1da3921ddc 100644
--- a/alib2data/src/container/ContainerBase.h
+++ b/alib2data/src/container/ContainerBase.h
@@ -14,15 +14,25 @@ namespace container {
 
 class ContainerBase;
 
-typedef std::acceptor_base<ContainerBase,
-			container::ObjectsSet,
-			container::ObjectsVector,
-			container::ObjectsPair,
-			container::ObjectsMap
-	> VisitableContainerBase;
+// ----------------------------------------------------------------------------------------------------------------------
+
+template<typename T>
+class acceptor_base_helper {
+};
+
+template<typename ... Ts>
+class acceptor_base_helper< std::tuple< Ts ... > > :
+	public std::acceptor_base<
+			ContainerBase, Ts ...
+	> {
+};
+
+typedef acceptor_base_helper< alib::ContainerTypes > VisitableContainerBase;
+
+// ----------------------------------------------------------------------------------------------------------------------
 
 /**
- * Represents container in a hierarchy.
+ * Represents symbol in an alphabet.
  */
 class ContainerBase : public alib::ObjectBase, public VisitableContainerBase {
 public:
diff --git a/alib2data/src/grammar/GrammarBase.h b/alib2data/src/grammar/GrammarBase.h
index 9dc7b96f19..4f6727ade3 100644
--- a/alib2data/src/grammar/GrammarBase.h
+++ b/alib2data/src/grammar/GrammarBase.h
@@ -15,12 +15,25 @@ namespace grammar {
 
 class GrammarBase;
 
-typedef std::acceptor_base<GrammarBase,
-			grammar::LeftLG, grammar::LeftRG, grammar::RightLG, grammar::RightRG, grammar::LG, grammar::CFG, grammar::EpsilonFreeCFG, grammar::CNF, grammar::GNF, grammar::CSG, grammar::NonContractingGrammar, grammar::ContextPreservingUnrestrictedGrammar, grammar::UnrestrictedGrammar
-	> VisitableGrammarBase;
+// ----------------------------------------------------------------------------------------------------------------------
+
+template<typename T>
+class acceptor_base_helper {
+};
+
+template<typename ... Ts>
+class acceptor_base_helper< std::tuple< Ts ... > > :
+	public std::acceptor_base<
+			GrammarBase, Ts ...
+	> {
+};
+
+typedef acceptor_base_helper< alib::GrammarTypes > VisitableGrammarBase;
+
+// ----------------------------------------------------------------------------------------------------------------------
 
 /**
- * Abstract base class for all grammars.
+ * Represents symbol in an alphabet.
  */
 class GrammarBase : public alib::ObjectBase, public VisitableGrammarBase {
 public:
diff --git a/alib2data/src/graph/GraphBase.h b/alib2data/src/graph/GraphBase.h
index aafa9ff94c..4158ba8c94 100644
--- a/alib2data/src/graph/GraphBase.h
+++ b/alib2data/src/graph/GraphBase.h
@@ -8,17 +8,34 @@ namespace graph {
 
 class GraphBase;
 
-typedef std::acceptor_base<GraphBase, DirectedGraph, UndirectedGraph> VisitableGraphBase;
+// ----------------------------------------------------------------------------------------------------------------------
 
-// Abstract base class for all graphs.
-class GraphBase : public alib::ObjectBase, public VisitableGraphBase
-{
+template<typename T>
+class acceptor_base_helper {
+};
+
+template<typename ... Ts>
+class acceptor_base_helper< std::tuple< Ts ... > > :
+	public std::acceptor_base<
+			GraphBase, Ts ...
+	> {
+};
+
+typedef acceptor_base_helper< alib::GraphTypes > VisitableGraphBase;
+
+// ----------------------------------------------------------------------------------------------------------------------
+
+/**
+ * Represents symbol in an alphabet.
+ */
+class GraphBase : public alib::ObjectBase, public VisitableGraphBase {
 public:
 	using VisitableGraphBase::Accept;
 	using alib::VisitableObjectBase::Accept;
 
-	virtual GraphBase *clone() const = 0;
-	virtual GraphBase *plunder() && = 0;
+	virtual GraphBase* clone() const = 0;
+	virtual GraphBase* plunder() && = 0;
+
 };
 
 } // namespace graph
diff --git a/alib2data/src/label/LabelBase.h b/alib2data/src/label/LabelBase.h
index fe0b81816a..0d5e1260cf 100644
--- a/alib2data/src/label/LabelBase.h
+++ b/alib2data/src/label/LabelBase.h
@@ -14,12 +14,25 @@ namespace label {
 
 class LabelBase;
 
-typedef std::acceptor_base<LabelBase,
-			label::PrimitiveLabel, label::HexavigesimalLabel, label::ObjectLabel, label::LabelSetLabel, label::LabelPairLabel, label::UniqueLabel
-	> VisitableLabelBase;
+// ----------------------------------------------------------------------------------------------------------------------
+
+template<typename T>
+class acceptor_base_helper {
+};
+
+template<typename ... Ts>
+class acceptor_base_helper< std::tuple< Ts ... > > :
+	public std::acceptor_base<
+			LabelBase, Ts ...
+	> {
+};
+
+typedef acceptor_base_helper< alib::LabelTypes > VisitableLabelBase;
+
+// ----------------------------------------------------------------------------------------------------------------------
 
 /**
- * Abstract base class for all automata.
+ * Represents symbol in an alphabet.
  */
 class LabelBase : public alib::ObjectBase, public VisitableLabelBase {
 public:
diff --git a/alib2data/src/object/ObjectBase.h b/alib2data/src/object/ObjectBase.h
index 5d13cb6a58..05250ce675 100644
--- a/alib2data/src/object/ObjectBase.h
+++ b/alib2data/src/object/ObjectBase.h
@@ -150,20 +150,54 @@ namespace alib {
 
 class ObjectBase;
 
-typedef std::tuple<
-			Void,
-			exception::AlibException,
-			automaton::DFA, automaton::NFA, automaton::MultiInitialStateNFA, automaton::EpsilonNFA, automaton::CompactNFA, automaton::ExtendedNFA, automaton::DFTA, automaton::NFTA, automaton::DPDA, automaton::SinglePopDPDA, automaton::InputDrivenDPDA, automaton::VisiblyPushdownDPDA, automaton::RealTimeHeightDeterministicDPDA, automaton::NPDA, automaton::SinglePopNPDA, automaton::InputDrivenNPDA, automaton::VisiblyPushdownNPDA, automaton::RealTimeHeightDeterministicNPDA, automaton::OneTapeDTM,
-			grammar::LeftLG, grammar::LeftRG, grammar::RightLG, grammar::RightRG, grammar::LG, grammar::CFG, grammar::EpsilonFreeCFG, grammar::CNF, grammar::GNF, grammar::CSG, grammar::NonContractingGrammar, grammar::ContextPreservingUnrestrictedGrammar, grammar::UnrestrictedGrammar,
-			graph::DirectedGraph, graph::UndirectedGraph,
-			label::PrimitiveLabel, label::HexavigesimalLabel, label::ObjectLabel, label::LabelSetLabel, label::LabelPairLabel, label::UniqueLabel,
-			regexp::UnboundedRegExp, regexp::FormalRegExp,
-			string::Epsilon, string::LinearString, string::CyclicString,
-			alphabet::EndSymbol, alphabet::LabeledSymbol, alphabet::BlankSymbol, alphabet::BottomOfTheStackSymbol, alphabet::RankedSymbol, alphabet::BarSymbol, alphabet::RankedBarSymbol, alphabet::SubtreeWildcardSymbol, alphabet::SymbolPairSymbol, alphabet::SymbolSetSymbol, alphabet::UniqueSymbol, alphabet::StartSymbol,
-			container::ObjectsSet, container::ObjectsVector, container::ObjectsPair, container::ObjectsMap,
-			primitive::String, primitive::Integer, primitive::Character, primitive::Unsigned, primitive::Bool,
-			tree::RankedTree, tree::PrefixRankedNotation, tree::UnrankedTree
-	> Types;
+typedef std::tuple< tree::RankedTree, tree::PrefixRankedNotation, tree::UnrankedTree
+	> TreeTypes;
+
+typedef std::tuple< primitive::String, primitive::Integer, primitive::Character, primitive::Unsigned, primitive::Bool
+	> PrimitiveTypes;
+
+typedef std::tuple< container::ObjectsSet, container::ObjectsVector, container::ObjectsPair, container::ObjectsMap
+	> ContainerTypes;
+
+typedef std::tuple< alphabet::EndSymbol, alphabet::LabeledSymbol, alphabet::BlankSymbol, alphabet::BottomOfTheStackSymbol, alphabet::RankedSymbol, alphabet::BarSymbol, alphabet::RankedBarSymbol, alphabet::SubtreeWildcardSymbol, alphabet::SymbolPairSymbol, alphabet::SymbolSetSymbol, alphabet::UniqueSymbol, alphabet::StartSymbol
+	> SymbolTypes;
+
+typedef std::tuple< string::Epsilon, string::LinearString, string::CyclicString
+	> StringTypes;
+
+typedef std::tuple< regexp::UnboundedRegExp, regexp::FormalRegExp
+	> RegExpTypes;
+
+typedef std::tuple< label::PrimitiveLabel, label::HexavigesimalLabel, label::ObjectLabel, label::LabelSetLabel, label::LabelPairLabel, label::UniqueLabel
+	> LabelTypes;
+
+typedef std::tuple< graph::DirectedGraph, graph::UndirectedGraph
+	> GraphTypes;
+
+typedef std::tuple< grammar::LeftLG, grammar::LeftRG, grammar::RightLG, grammar::RightRG, grammar::LG, grammar::CFG, grammar::EpsilonFreeCFG, grammar::CNF, grammar::GNF, grammar::CSG, grammar::NonContractingGrammar, grammar::ContextPreservingUnrestrictedGrammar, grammar::UnrestrictedGrammar
+	> GrammarTypes;
+
+typedef std::tuple< automaton::DFA, automaton::NFA, automaton::MultiInitialStateNFA, automaton::EpsilonNFA, automaton::CompactNFA, automaton::ExtendedNFA, automaton::DFTA, automaton::NFTA, automaton::DPDA, automaton::SinglePopDPDA, automaton::InputDrivenDPDA, automaton::VisiblyPushdownDPDA, automaton::RealTimeHeightDeterministicDPDA, automaton::NPDA, automaton::SinglePopNPDA, automaton::InputDrivenNPDA, automaton::VisiblyPushdownNPDA, automaton::RealTimeHeightDeterministicNPDA, automaton::OneTapeDTM
+	> AutomatonTypes;
+
+typedef std::tuple< Void, exception::AlibException
+	> OtherTypes;
+// --------------------------------------------------------------------------------------------------------------------
+
+template<typename ... Ts>
+class types_merger {
+};
+
+template<typename ... TreeTypes, typename ... PrimitiveTypes, typename ... ContainerTypes, typename ... SymbolTypes, typename ... StringTypes, typename ... RegExpTypes, typename ... LabelTypes, typename ... GraphTypes, typename ... GrammarTypes, typename ... AutomatonTypes, typename ... OtherTypes>
+class types_merger<std::tuple<TreeTypes...>, std::tuple<PrimitiveTypes...>, std::tuple<ContainerTypes...>, std::tuple<SymbolTypes...>, std::tuple<StringTypes...>, std::tuple<RegExpTypes...>, std::tuple<LabelTypes...>, std::tuple<GraphTypes...>, std::tuple<GrammarTypes...>, std::tuple<AutomatonTypes...>, std::tuple<OtherTypes...>> {
+public:
+	typedef std::tuple<
+			OtherTypes..., AutomatonTypes..., GrammarTypes..., GraphTypes..., LabelTypes..., RegExpTypes..., StringTypes..., SymbolTypes..., ContainerTypes..., PrimitiveTypes..., TreeTypes...
+		> MergedTypes;
+
+};
+
+typedef types_merger<TreeTypes, PrimitiveTypes, ContainerTypes, SymbolTypes, StringTypes, RegExpTypes, LabelTypes, GraphTypes, GrammarTypes, AutomatonTypes, OtherTypes>::MergedTypes Types;
 
 // ----------------------------------------------------------------------------------------------------------------------
 
diff --git a/alib2data/src/primitive/PrimitiveBase.h b/alib2data/src/primitive/PrimitiveBase.h
index 4ff1465fc6..f78c0aeb10 100644
--- a/alib2data/src/primitive/PrimitiveBase.h
+++ b/alib2data/src/primitive/PrimitiveBase.h
@@ -14,12 +14,25 @@ namespace primitive {
 
 class PrimitiveBase;
 
-typedef std::acceptor_base<PrimitiveBase,
-			primitive::String, primitive::Integer, primitive::Character, primitive::Unsigned, primitive::Bool
-	> VisitablePrimitiveBase;
+// ----------------------------------------------------------------------------------------------------------------------
+
+template<typename T>
+class acceptor_base_helper {
+};
+
+template<typename ... Ts>
+class acceptor_base_helper< std::tuple< Ts ... > > :
+	public std::acceptor_base<
+			PrimitiveBase, Ts ...
+	> {
+};
+
+typedef acceptor_base_helper< alib::PrimitiveTypes > VisitablePrimitiveBase;
+
+// ----------------------------------------------------------------------------------------------------------------------
 
 /**
- * Abstract base class for all automata.
+ * Represents symbol in an alphabet.
  */
 class PrimitiveBase : public alib::ObjectBase, public VisitablePrimitiveBase {
 public:
diff --git a/alib2data/src/regexp/RegExpBase.h b/alib2data/src/regexp/RegExpBase.h
index 103f005fa7..532148c92d 100644
--- a/alib2data/src/regexp/RegExpBase.h
+++ b/alib2data/src/regexp/RegExpBase.h
@@ -14,12 +14,25 @@ namespace regexp {
 
 class RegExpBase;
 
-typedef std::acceptor_base<RegExpBase,
-			UnboundedRegExp, FormalRegExp
-	> VisitableRegExpBase;
+// ----------------------------------------------------------------------------------------------------------------------
+
+template<typename T>
+class acceptor_base_helper {
+};
+
+template<typename ... Ts>
+class acceptor_base_helper< std::tuple< Ts ... > > :
+	public std::acceptor_base<
+			RegExpBase, Ts ...
+	> {
+};
+
+typedef acceptor_base_helper< alib::RegExpTypes > VisitableRegExpBase;
+
+// ----------------------------------------------------------------------------------------------------------------------
 
 /**
- * Abstract base class for all automata.
+ * Represents symbol in an alphabet.
  */
 class RegExpBase : public alib::ObjectBase, public VisitableRegExpBase {
 public:
@@ -28,6 +41,7 @@ public:
 
 	virtual RegExpBase* clone() const = 0;
 	virtual RegExpBase* plunder() && = 0;
+
 };
 
 } /* namespace regexp */
diff --git a/alib2data/src/string/StringBase.h b/alib2data/src/string/StringBase.h
index bd7627fb72..d2a3e40b58 100644
--- a/alib2data/src/string/StringBase.h
+++ b/alib2data/src/string/StringBase.h
@@ -14,20 +14,34 @@ namespace string {
 
 class StringBase;
 
-typedef std::acceptor_base<StringBase,
-			string::Epsilon, string::LinearString, string::CyclicString
-	> VisitableStringBase;
+// ----------------------------------------------------------------------------------------------------------------------
+
+template<typename T>
+class acceptor_base_helper {
+};
+
+template<typename ... Ts>
+class acceptor_base_helper< std::tuple< Ts ... > > :
+	public std::acceptor_base<
+			StringBase, Ts ...
+	> {
+};
+
+typedef acceptor_base_helper< alib::StringTypes > VisitableStringBase;
+
+// ----------------------------------------------------------------------------------------------------------------------
 
 /**
- * Represents string in an alphabet.
+ * Represents symbol in an alphabet.
  */
-class StringBase : public VisitableStringBase, public alib::ObjectBase {
+class StringBase : public alib::ObjectBase, public VisitableStringBase {
 public:
 	using VisitableStringBase::Accept;
 	using alib::VisitableObjectBase::Accept;
 
 	virtual StringBase* clone() const = 0;
 	virtual StringBase* plunder() && = 0;
+
 };
 
 } /* namespace string */
diff --git a/alib2data/src/tree/TreeBase.h b/alib2data/src/tree/TreeBase.h
index 4a91f60f7e..85198e5efb 100644
--- a/alib2data/src/tree/TreeBase.h
+++ b/alib2data/src/tree/TreeBase.h
@@ -16,12 +16,25 @@ namespace tree {
 
 class TreeBase;
 
-typedef std::acceptor_base<TreeBase,
-			tree::RankedTree, tree::PrefixRankedNotation, tree::UnrankedTree
-	> VisitableTreeBase;
+// ----------------------------------------------------------------------------------------------------------------------
+
+template<typename T>
+class acceptor_base_helper {
+};
+
+template<typename ... Ts>
+class acceptor_base_helper< std::tuple< Ts ... > > :
+	public std::acceptor_base<
+			TreeBase, Ts ...
+	> {
+};
+
+typedef acceptor_base_helper< alib::TreeTypes > VisitableTreeBase;
+
+// ----------------------------------------------------------------------------------------------------------------------
 
 /**
- * Abstract base class for all trees.
+ * Represents symbol in an alphabet.
  */
 class TreeBase : public alib::ObjectBase, public VisitableTreeBase {
 public:
-- 
GitLab