From 49f2d82d392c20e77ba45e7fd71c0a1e88a06152 Mon Sep 17 00:00:00 2001
From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz>
Date: Mon, 25 Aug 2014 15:50:57 +0200
Subject: [PATCH] private composers

---
 alib2data/src/Api.cpp                         | 74 +++++++++----------
 alib2data/src/Api.hpp                         | 10 +--
 .../src/alphabet/SymbolToXMLComposer.cpp      |  2 +-
 alib2data/src/alphabet/SymbolToXMLComposer.h  | 10 ++-
 .../src/automaton/AutomatonToXMLComposer.cpp  | 42 +++++------
 .../src/automaton/AutomatonToXMLComposer.h    | 11 ++-
 .../src/container/ContainerToXMLComposer.hpp  |  1 -
 .../src/exception/ExceptionToXMLComposer.h    | 10 ++-
 .../src/grammar/GrammarToXMLComposer.cpp      | 46 ++++++------
 alib2data/src/grammar/GrammarToXMLComposer.h  | 11 ++-
 alib2data/src/label/LabelToXMLComposer.h      | 10 ++-
 alib2data/src/object/ObjectToXMLComposer.h    | 10 ++-
 alib2data/src/regexp/RegExpToXMLComposer.cpp  |  8 +-
 alib2data/src/regexp/RegExpToXMLComposer.h    | 10 ++-
 alib2data/src/string/StringToXMLComposer.cpp  | 10 +--
 alib2data/src/string/StringToXMLComposer.h    | 10 ++-
 alib2data/test-src/alphabet/SymbolTest.cpp    |  3 +-
 .../test-src/automaton/AutomatonTest.cpp      |  6 +-
 alib2data/test-src/grammar/GrammarTest.cpp    | 36 +++------
 alib2data/test-src/label/LabelTest.cpp        |  3 +-
 alib2data/test-src/regexp/RegExpTest.cpp      |  3 +-
 alib2data/test-src/string/StringTest.cpp      |  3 +-
 22 files changed, 187 insertions(+), 142 deletions(-)

diff --git a/alib2data/src/Api.cpp b/alib2data/src/Api.cpp
index 6cbd75faff..afb892b509 100644
--- a/alib2data/src/Api.cpp
+++ b/alib2data/src/Api.cpp
@@ -397,151 +397,151 @@ std::list<sax::Token> api<string::Epsilon>::compose(const string::Epsilon& data)
 }
 
 void ToXMLComposers::Visit(void* data, const container::ObjectsSet& container) const {
-	*((std::list<sax::Token>*) data) = std::move(ToXMLComposers::containerComposer.compose(container));
+	*((std::list<sax::Token>*) data) = std::move(api<container::ObjectsSet>::compose(container));
 }
 
 void ToXMLComposers::Visit(void* data, const exception::AlibException& symbol) const {
-	*((std::list<sax::Token>*) data) = std::move(ToXMLComposers::exceptionComposer.compose(symbol));
+	*((std::list<sax::Token>*) data) = std::move(api<exception::AlibException>::compose(symbol));
 }
 
 void ToXMLComposers::Visit(void* data, const alphabet::BlankSymbol& symbol) const {
-	*((std::list<sax::Token>*) data) = std::move(ToXMLComposers::symbolComposer.compose(symbol));
+	*((std::list<sax::Token>*) data) = std::move(api<alphabet::BlankSymbol>::compose(symbol));
 }
 
 void ToXMLComposers::Visit(void* data, const alphabet::BottomOfTheStackSymbol& symbol) const {
-	*((std::list<sax::Token>*) data) = std::move(ToXMLComposers::symbolComposer.compose(symbol));
+	*((std::list<sax::Token>*) data) = std::move(api<alphabet::BottomOfTheStackSymbol>::compose(symbol));
 }
 
 void ToXMLComposers::Visit(void* data, const alphabet::EndSymbol& symbol) const {
-	*((std::list<sax::Token>*) data) = std::move(ToXMLComposers::symbolComposer.compose(symbol));
+	*((std::list<sax::Token>*) data) = std::move(api<alphabet::EndSymbol>::compose(symbol));
 }
 
 void ToXMLComposers::Visit(void* data, const alphabet::LabeledSymbol& symbol) const {
-	*((std::list<sax::Token>*) data) = std::move(ToXMLComposers::symbolComposer.compose(symbol));
+	*((std::list<sax::Token>*) data) = std::move(api<alphabet::LabeledSymbol>::compose(symbol));
 }
 
 void ToXMLComposers::Visit(void* data, const automaton::UnknownAutomaton& automaton) const {
-	*((std::list<sax::Token>*) data) = std::move(ToXMLComposers::automatonComposer.compose(automaton));
+	*((std::list<sax::Token>*) data) = std::move(api<automaton::UnknownAutomaton>::compose(automaton));
 }
 
 void ToXMLComposers::Visit(void* data, const automaton::EpsilonNFA& automaton) const {
-	*((std::list<sax::Token>*) data) = std::move(ToXMLComposers::automatonComposer.compose(automaton));
+	*((std::list<sax::Token>*) data) = std::move(api<automaton::EpsilonNFA>::compose(automaton));
 }
 
 void ToXMLComposers::Visit(void* data, const automaton::NFA& automaton) const {
-	*((std::list<sax::Token>*) data) = std::move(ToXMLComposers::automatonComposer.compose(automaton));
+	*((std::list<sax::Token>*) data) = std::move(api<automaton::NFA>::compose(automaton));
 }
 
 void ToXMLComposers::Visit(void* data, const automaton::DFA& automaton) const {
-	*((std::list<sax::Token>*) data) = std::move(ToXMLComposers::automatonComposer.compose(automaton));
+	*((std::list<sax::Token>*) data) = std::move(api<automaton::DFA>::compose(automaton));
 }
 
 void ToXMLComposers::Visit(void* data, const automaton::ExtendedNFA& automaton) const {
-	*((std::list<sax::Token>*) data) = std::move(ToXMLComposers::automatonComposer.compose(automaton));
+	*((std::list<sax::Token>*) data) = std::move(api<automaton::ExtendedNFA>::compose(automaton));
 }
 
 void ToXMLComposers::Visit(void* data, const automaton::CompactNFA& automaton) const {
-	*((std::list<sax::Token>*) data) = std::move(ToXMLComposers::automatonComposer.compose(automaton));
+	*((std::list<sax::Token>*) data) = std::move(api<automaton::CompactNFA>::compose(automaton));
 }
 
 void ToXMLComposers::Visit(void* data, const automaton::NPDA& automaton) const {
-	*((std::list<sax::Token>*) data) = std::move(ToXMLComposers::automatonComposer.compose(automaton));
+	*((std::list<sax::Token>*) data) = std::move(api<automaton::NPDA>::compose(automaton));
 }
 
 void ToXMLComposers::Visit(void* data, const automaton::SinglePopNPDA& automaton) const {
-	*((std::list<sax::Token>*) data) = std::move(ToXMLComposers::automatonComposer.compose(automaton));
+	*((std::list<sax::Token>*) data) = std::move(api<automaton::SinglePopNPDA>::compose(automaton));
 }
 
 void ToXMLComposers::Visit(void* data, const automaton::OneTapeDTM& automaton) const {
-	*((std::list<sax::Token>*) data) = std::move(ToXMLComposers::automatonComposer.compose(automaton));
+	*((std::list<sax::Token>*) data) = std::move(api<automaton::OneTapeDTM>::compose(automaton));
 }
 
 void ToXMLComposers::Visit(void* data, const grammar::UnknownGrammar& grammar) const {
-	*((std::list<sax::Token>*) data) = std::move(ToXMLComposers::grammarComposer.compose(grammar));
+	*((std::list<sax::Token>*) data) = std::move(api<grammar::UnknownGrammar>::compose(grammar));
 }
 
 void ToXMLComposers::Visit(void* data, const grammar::LeftLG& grammar) const {
-	*((std::list<sax::Token>*) data) = std::move(ToXMLComposers::grammarComposer.compose(grammar));
+	*((std::list<sax::Token>*) data) = std::move(api<grammar::LeftLG>::compose(grammar));
 }
 
 void ToXMLComposers::Visit(void* data, const grammar::LeftRG& grammar) const {
-	*((std::list<sax::Token>*) data) = std::move(ToXMLComposers::grammarComposer.compose(grammar));
+	*((std::list<sax::Token>*) data) = std::move(api<grammar::LeftRG>::compose(grammar));
 }
 
 void ToXMLComposers::Visit(void* data, const grammar::RightLG& grammar) const {
-	*((std::list<sax::Token>*) data) = std::move(ToXMLComposers::grammarComposer.compose(grammar));
+	*((std::list<sax::Token>*) data) = std::move(api<grammar::RightLG>::compose(grammar));
 }
 
 void ToXMLComposers::Visit(void* data, const grammar::RightRG& grammar) const {
-	*((std::list<sax::Token>*) data) = std::move(ToXMLComposers::grammarComposer.compose(grammar));
+	*((std::list<sax::Token>*) data) = std::move(api<grammar::RightRG>::compose(grammar));
 }
 
 void ToXMLComposers::Visit(void* data, const grammar::LG& grammar) const {
-	*((std::list<sax::Token>*) data) = std::move(ToXMLComposers::grammarComposer.compose(grammar));
+	*((std::list<sax::Token>*) data) = std::move(api<grammar::LG>::compose(grammar));
 }
 
 void ToXMLComposers::Visit(void* data, const grammar::CFG& grammar) const {
-	*((std::list<sax::Token>*) data) = std::move(ToXMLComposers::grammarComposer.compose(grammar));
+	*((std::list<sax::Token>*) data) = std::move(api<grammar::CFG>::compose(grammar));
 }
 
 void ToXMLComposers::Visit(void* data, const grammar::EpsilonFreeCFG& grammar) const {
-	*((std::list<sax::Token>*) data) = std::move(ToXMLComposers::grammarComposer.compose(grammar));
+	*((std::list<sax::Token>*) data) = std::move(api<grammar::EpsilonFreeCFG>::compose(grammar));
 }
 
 void ToXMLComposers::Visit(void* data, const grammar::CNF& grammar) const {
-	*((std::list<sax::Token>*) data) = std::move(ToXMLComposers::grammarComposer.compose(grammar));
+	*((std::list<sax::Token>*) data) = std::move(api<grammar::CNF>::compose(grammar));
 }
 
 void ToXMLComposers::Visit(void* data, const grammar::GNF& grammar) const {
-	*((std::list<sax::Token>*) data) = std::move(ToXMLComposers::grammarComposer.compose(grammar));
+	*((std::list<sax::Token>*) data) = std::move(api<grammar::GNF>::compose(grammar));
 }
 
 void ToXMLComposers::Visit(void* data, const grammar::CSG& grammar) const {
-	*((std::list<sax::Token>*) data) = std::move(ToXMLComposers::grammarComposer.compose(grammar));
+	*((std::list<sax::Token>*) data) = std::move(api<grammar::CSG>::compose(grammar));
 }
 
 void ToXMLComposers::Visit(void* data, const grammar::NonContractingGrammar& grammar) const {
-	*((std::list<sax::Token>*) data) = std::move(ToXMLComposers::grammarComposer.compose(grammar));
+	*((std::list<sax::Token>*) data) = std::move(api<grammar::NonContractingGrammar>::compose(grammar));
 }
 
 void ToXMLComposers::Visit(void* data, const grammar::ContextPreservingUnrestrictedGrammar& grammar) const {
-	*((std::list<sax::Token>*) data) = std::move(ToXMLComposers::grammarComposer.compose(grammar));
+	*((std::list<sax::Token>*) data) = std::move(api<grammar::ContextPreservingUnrestrictedGrammar>::compose(grammar));
 }
 
 void ToXMLComposers::Visit(void* data, const grammar::UnrestrictedGrammar& grammar) const {
-	*((std::list<sax::Token>*) data) = std::move(ToXMLComposers::grammarComposer.compose(grammar));
+	*((std::list<sax::Token>*) data) = std::move(api<grammar::UnrestrictedGrammar>::compose(grammar));
 }
 
 void ToXMLComposers::Visit(void* data, const label::IntegerLabel& label) const {
-	*((std::list<sax::Token>*) data) = std::move(ToXMLComposers::labelComposer.compose(label));
+	*((std::list<sax::Token>*) data) = std::move(api<label::IntegerLabel>::compose(label));
 }
 
 void ToXMLComposers::Visit(void* data, const label::CharacterLabel& label) const {
-	*((std::list<sax::Token>*) data) = std::move(ToXMLComposers::labelComposer.compose(label));
+	*((std::list<sax::Token>*) data) = std::move(api<label::CharacterLabel>::compose(label));
 }
 
 void ToXMLComposers::Visit(void* data, const label::StringLabel& label) const {
-	*((std::list<sax::Token>*) data) = std::move(ToXMLComposers::labelComposer.compose(label));
+	*((std::list<sax::Token>*) data) = std::move(api<label::StringLabel>::compose(label));
 }
 
 void ToXMLComposers::Visit(void* data, const regexp::UnboundedRegExp& regexp) const {
-	*((std::list<sax::Token>*) data) = std::move(ToXMLComposers::regexpComposer.compose(regexp));
+	*((std::list<sax::Token>*) data) = std::move(api<regexp::UnboundedRegExp>::compose(regexp));
 }
 
 void ToXMLComposers::Visit(void* data, const regexp::FormalRegExp& regexp) const {
-	*((std::list<sax::Token>*) data) = std::move(ToXMLComposers::regexpComposer.compose(regexp));
+	*((std::list<sax::Token>*) data) = std::move(api<regexp::FormalRegExp>::compose(regexp));
 }
 
 void ToXMLComposers::Visit(void* data, const string::Epsilon& string) const {
-	*((std::list<sax::Token>*) data) = std::move(ToXMLComposers::stringComposer.compose(string));
+	*((std::list<sax::Token>*) data) = std::move(api<string::Epsilon>::compose(string));
 }
 
 void ToXMLComposers::Visit(void* data, const string::CyclicString& string) const {
-	*((std::list<sax::Token>*) data) = std::move(ToXMLComposers::stringComposer.compose(string));
+	*((std::list<sax::Token>*) data) = std::move(api<string::CyclicString>::compose(string));
 }
 
 void ToXMLComposers::Visit(void* data, const string::LinearString& string) const {
-	*((std::list<sax::Token>*) data) = std::move(ToXMLComposers::stringComposer.compose(string));
+	*((std::list<sax::Token>*) data) = std::move(api<string::LinearString>::compose(string));
 }
 
 } /* namespace alib */
diff --git a/alib2data/src/Api.hpp b/alib2data/src/Api.hpp
index c2ce6cbc02..21204778c7 100644
--- a/alib2data/src/Api.hpp
+++ b/alib2data/src/Api.hpp
@@ -50,9 +50,9 @@ struct api<container::ObjectsSet> {
 
 
 template<>
-struct api<alib::Object> {
-	static alib::Object parse(std::list<sax::Token>& input);
-	static std::list<sax::Token> compose(const alib::Object& data);
+struct api<Object> {
+	static Object parse(std::list<sax::Token>& input);
+	static std::list<sax::Token> compose(const Object& data);
 };
 
 
@@ -341,7 +341,7 @@ public:
 	static const automaton::AutomatonFromXMLParser automatonParser;
 	static const grammar::GrammarFromXMLParser grammarParser;
 	static const exception::ExceptionFromXMLParser exceptionParser;
-	static const alib::ObjectFromXMLParser objectParser;
+	static const ObjectFromXMLParser objectParser;
 	static const container::ContainerFromXMLParser containerParser;
 
 };
@@ -400,7 +400,7 @@ public:
 	static const automaton::AutomatonToXMLComposer automatonComposer;
 	static const grammar::GrammarToXMLComposer grammarComposer;
 	static const exception::ExceptionToXMLComposer exceptionComposer;
-	static const alib::ObjectToXMLComposer objectComposer;
+	static const ObjectToXMLComposer objectComposer;
 	static const container::ContainerToXMLComposer containerComposer;
 
 	static const ToXMLComposers toXMLComposers;
diff --git a/alib2data/src/alphabet/SymbolToXMLComposer.cpp b/alib2data/src/alphabet/SymbolToXMLComposer.cpp
index d65be04a76..76f674fb8e 100644
--- a/alib2data/src/alphabet/SymbolToXMLComposer.cpp
+++ b/alib2data/src/alphabet/SymbolToXMLComposer.cpp
@@ -26,7 +26,7 @@ std::list<sax::Token> SymbolToXMLComposer::compose(const SymbolBase& symbol) con
 std::list<sax::Token> SymbolToXMLComposer::compose(const LabeledSymbol& symbol) const {
 	std::list<sax::Token> out;
 	out.push_back(sax::Token("LabeledSymbol", sax::Token::TokenType::START_ELEMENT));
-	out.splice(out.end(), alib::ToXMLComposers::labelComposer.compose(symbol.getLabel()));
+	out.splice(out.end(), alib::api<label::Label>::compose(symbol.getLabel()));
 	out.push_back(sax::Token("LabeledSymbol", sax::Token::TokenType::END_ELEMENT));
 	return out;
 }
diff --git a/alib2data/src/alphabet/SymbolToXMLComposer.h b/alib2data/src/alphabet/SymbolToXMLComposer.h
index 0d06615401..dff6166b3b 100644
--- a/alib2data/src/alphabet/SymbolToXMLComposer.h
+++ b/alib2data/src/alphabet/SymbolToXMLComposer.h
@@ -13,13 +13,19 @@
 #include "../sax/Token.h"
 #include "../label/Label.h"
 
+namespace alib {
+
+template<typename T>
+struct api;
+
+} /* namespace alib */
+
 namespace alphabet {
 
 /**
  * This class contains methods to print XML representation of string to the output stream.
  */
 class SymbolToXMLComposer {
-public:
 	/**
 	 * Prints XML representation of UnknownAutomaton to the output stream.
 	 * @param automaton automaton to print
@@ -38,6 +44,8 @@ public:
 	std::list<sax::Token> compose(const BlankSymbol& symbol) const;
 	std::list<sax::Token> compose(const BottomOfTheStackSymbol& symbol) const;
 	std::list<sax::Token> compose(const EndSymbol& symbol) const;
+
+	template<typename T> friend class alib::api;
 };
 
 } /* namespace alphabet */
diff --git a/alib2data/src/automaton/AutomatonToXMLComposer.cpp b/alib2data/src/automaton/AutomatonToXMLComposer.cpp
index 2a24812c23..dc493a25de 100644
--- a/alib2data/src/automaton/AutomatonToXMLComposer.cpp
+++ b/alib2data/src/automaton/AutomatonToXMLComposer.cpp
@@ -15,7 +15,7 @@ namespace automaton {
 void AutomatonToXMLComposer::composeStates(std::list<sax::Token>& out, const std::set<State>& states) const {
 	out.push_back(sax::Token("states", sax::Token::TokenType::START_ELEMENT));
 	for (const auto& state : states) {
-		out.splice(out.end(), alib::ToXMLComposers::labelComposer.compose(state.getName()));
+		out.splice(out.end(), alib::api<label::Label>::compose(state.getName()));
 	}
 	out.push_back(sax::Token("states", sax::Token::TokenType::END_ELEMENT));
 }
@@ -23,7 +23,7 @@ void AutomatonToXMLComposer::composeStates(std::list<sax::Token>& out, const std
 void AutomatonToXMLComposer::composeInputAlphabet(std::list<sax::Token>& out, const std::set<alphabet::Symbol>& symbols) const {
 	out.push_back(sax::Token("inputAlphabet", sax::Token::TokenType::START_ELEMENT));
 	for (const auto& symbol : symbols) {
-		out.splice(out.end(), alib::ToXMLComposers::symbolComposer.compose(symbol));
+		out.splice(out.end(), alib::api<alphabet::Symbol>::compose(symbol));
 	}
 	out.push_back(sax::Token("inputAlphabet", sax::Token::TokenType::END_ELEMENT));
 }
@@ -31,21 +31,21 @@ void AutomatonToXMLComposer::composeInputAlphabet(std::list<sax::Token>& out, co
 void AutomatonToXMLComposer::composeInitialStates(std::list<sax::Token>& out, const std::set<State>& states) const {
 	out.push_back(sax::Token("initialStates", sax::Token::TokenType::START_ELEMENT));
 	for (const auto& state : states) {
-		out.splice(out.end(), alib::ToXMLComposers::labelComposer.compose(state.getName()));
+		out.splice(out.end(), alib::api<label::Label>::compose(state.getName()));
 	}
 	out.push_back(sax::Token("initialStates", sax::Token::TokenType::END_ELEMENT));
 }
 
 void AutomatonToXMLComposer::composeInitialState(std::list<sax::Token>& out, const State& state) const {
 	out.push_back(sax::Token("initialState", sax::Token::TokenType::START_ELEMENT));
-	out.splice(out.end(), alib::ToXMLComposers::labelComposer.compose(state.getName()));
+	out.splice(out.end(), alib::api<label::Label>::compose(state.getName()));
 	out.push_back(sax::Token("initialState", sax::Token::TokenType::END_ELEMENT));
 }
 
 void AutomatonToXMLComposer::composeFinalStates(std::list<sax::Token>& out, const std::set<State>& states) const {
 	out.push_back(sax::Token("finalStates", sax::Token::TokenType::START_ELEMENT));
 	for (const auto& state : states) {
-		out.splice(out.end(), alib::ToXMLComposers::labelComposer.compose(state.getName()));
+		out.splice(out.end(), alib::api<label::Label>::compose(state.getName()));
 	}
 	out.push_back(sax::Token("finalStates", sax::Token::TokenType::END_ELEMENT));
 }
@@ -53,7 +53,7 @@ void AutomatonToXMLComposer::composeFinalStates(std::list<sax::Token>& out, cons
 void AutomatonToXMLComposer::composeStackAlphabet(std::list<sax::Token>& out, const std::set<alphabet::Symbol>& symbols) const {
 	out.push_back(sax::Token("stackAlphabet", sax::Token::TokenType::START_ELEMENT));
 	for (const auto& symbol : symbols) {
-		out.splice(out.end(), alib::ToXMLComposers::symbolComposer.compose(symbol));
+		out.splice(out.end(), alib::api<alphabet::Symbol>::compose(symbol));
 	}
 	out.push_back(sax::Token("stackAlphabet", sax::Token::TokenType::END_ELEMENT));
 }
@@ -61,28 +61,28 @@ void AutomatonToXMLComposer::composeStackAlphabet(std::list<sax::Token>& out, co
 void AutomatonToXMLComposer::composeInitialStackSymbols(std::list<sax::Token>& out, const std::set<alphabet::Symbol>& symbols) const {
 	out.push_back(sax::Token("initialStackSymbols", sax::Token::TokenType::START_ELEMENT));
 	for (const auto& symbol : symbols) {
-		out.splice(out.end(), alib::ToXMLComposers::symbolComposer.compose(symbol));
+		out.splice(out.end(), alib::api<alphabet::Symbol>::compose(symbol));
 	}
 	out.push_back(sax::Token("initialStackSymbols", sax::Token::TokenType::END_ELEMENT));
 }
 
 void AutomatonToXMLComposer::composeInitialStackSymbol(std::list<sax::Token>& out, const alphabet::Symbol& symbol) const {
 	out.push_back(sax::Token("initialStackSymbol", sax::Token::TokenType::START_ELEMENT));
-	out.splice(out.end(), alib::ToXMLComposers::symbolComposer.compose(symbol));
+	out.splice(out.end(), alib::api<alphabet::Symbol>::compose(symbol));
 	out.push_back(sax::Token("initialStackSymbol", sax::Token::TokenType::END_ELEMENT));
 }
 
 void AutomatonToXMLComposer::composeTapeAlphabet(std::list<sax::Token>& out, const std::set<alphabet::Symbol>& symbols) const {
 	out.push_back(sax::Token("tapeAlphabet", sax::Token::TokenType::START_ELEMENT));
 	for (const auto& symbol : symbols) {
-		out.splice(out.end(), alib::ToXMLComposers::symbolComposer.compose(symbol));
+		out.splice(out.end(), alib::api<alphabet::Symbol>::compose(symbol));
 	}
 	out.push_back(sax::Token("tapeAlphabet", sax::Token::TokenType::END_ELEMENT));
 }
 
 void AutomatonToXMLComposer::composeBlankSymbol(std::list<sax::Token>& out, const alphabet::Symbol& symbol) const {
 	out.push_back(sax::Token("blankSymbol", sax::Token::TokenType::START_ELEMENT));
-	out.splice(out.end(), alib::ToXMLComposers::symbolComposer.compose(symbol));
+	out.splice(out.end(), alib::api<alphabet::Symbol>::compose(symbol));
 	out.push_back(sax::Token("blankSymbol", sax::Token::TokenType::END_ELEMENT));
 }
 
@@ -259,13 +259,13 @@ void AutomatonToXMLComposer::composeTransitions(std::list<sax::Token>& out, cons
 
 void AutomatonToXMLComposer::composeTransitionTo(std::list<sax::Token>& out, const State& state) const {
 	out.push_back(sax::Token("to", sax::Token::TokenType::START_ELEMENT));
-	out.splice(out.end(), alib::ToXMLComposers::labelComposer.compose(state.getName()));
+	out.splice(out.end(), alib::api<label::Label>::compose(state.getName()));
 	out.push_back(sax::Token("to", sax::Token::TokenType::END_ELEMENT));
 }
 
 void AutomatonToXMLComposer::composeTransitionFrom(std::list<sax::Token>& out, const State& state) const {
 	out.push_back(sax::Token("from", sax::Token::TokenType::START_ELEMENT));
-	out.splice(out.end(), alib::ToXMLComposers::labelComposer.compose(state.getName()));
+	out.splice(out.end(), alib::api<label::Label>::compose(state.getName()));
 	out.push_back(sax::Token("from", sax::Token::TokenType::END_ELEMENT));
 }
 
@@ -278,34 +278,34 @@ void AutomatonToXMLComposer::composeTransitionShift(std::list<sax::Token>& out,
 void AutomatonToXMLComposer::composeTransitionPop(std::list<sax::Token>& out, const std::vector<alphabet::Symbol>& symbols) const {
 	out.push_back(sax::Token("pop", sax::Token::TokenType::START_ELEMENT));
 	for (const auto& symbol : symbols) {
-		out.splice(out.end(), alib::ToXMLComposers::symbolComposer.compose(symbol));
+		out.splice(out.end(), alib::api<alphabet::Symbol>::compose(symbol));
 	}
 	out.push_back(sax::Token("pop", sax::Token::TokenType::END_ELEMENT));
 }
 
 void AutomatonToXMLComposer::composeTransitionSinglePop(std::list<sax::Token>& out, const alphabet::Symbol& symbol) const {
 	out.push_back(sax::Token("pop", sax::Token::TokenType::START_ELEMENT));
-	out.splice(out.end(), alib::ToXMLComposers::symbolComposer.compose(symbol));
+	out.splice(out.end(), alib::api<alphabet::Symbol>::compose(symbol));
 	out.push_back(sax::Token("pop", sax::Token::TokenType::END_ELEMENT));
 }
 
 void AutomatonToXMLComposer::composeTransitionPush(std::list<sax::Token>& out, const std::vector<alphabet::Symbol>& symbols) const {
 	out.push_back(sax::Token("push", sax::Token::TokenType::START_ELEMENT));
 	for (const auto& symbol : symbols) {
-		out.splice(out.end(), alib::ToXMLComposers::symbolComposer.compose(symbol));
+		out.splice(out.end(), alib::api<alphabet::Symbol>::compose(symbol));
 	}
 	out.push_back(sax::Token("push", sax::Token::TokenType::END_ELEMENT));
 }
 
 void AutomatonToXMLComposer::composeTransitionInputSymbol(std::list<sax::Token>& out, const alphabet::Symbol& symbol) const {
 	out.push_back(sax::Token("input", sax::Token::TokenType::START_ELEMENT));
-	out.splice(out.end(), alib::ToXMLComposers::symbolComposer.compose(symbol));
+	out.splice(out.end(), alib::api<alphabet::Symbol>::compose(symbol));
 	out.push_back(sax::Token("input", sax::Token::TokenType::END_ELEMENT));
 }
 
 void AutomatonToXMLComposer::composeTransitionOutputSymbol(std::list<sax::Token>& out, const alphabet::Symbol& symbol) const {
 	out.push_back(sax::Token("output", sax::Token::TokenType::START_ELEMENT));
-	out.splice(out.end(), alib::ToXMLComposers::symbolComposer.compose(symbol));
+	out.splice(out.end(), alib::api<alphabet::Symbol>::compose(symbol));
 	out.push_back(sax::Token("output", sax::Token::TokenType::END_ELEMENT));
 }
 
@@ -315,7 +315,7 @@ void AutomatonToXMLComposer::composeTransitionInputEpsilonSymbol(std::list<sax::
 		out.push_back(sax::Token("epsilon", sax::Token::TokenType::START_ELEMENT));
 		out.push_back(sax::Token("epsilon", sax::Token::TokenType::END_ELEMENT));
 	} else {
-		out.splice(out.end(), alib::ToXMLComposers::symbolComposer.compose(symbol.get<alphabet::Symbol>()));
+		out.splice(out.end(), alib::api<alphabet::Symbol>::compose(symbol.get<alphabet::Symbol>()));
 	}
 	out.push_back(sax::Token("input", sax::Token::TokenType::END_ELEMENT));
 }
@@ -326,20 +326,20 @@ void AutomatonToXMLComposer::composeTransitionOutputEpsilonSymbol(std::list<sax:
 		out.push_back(sax::Token("epsilon", sax::Token::TokenType::START_ELEMENT));
 		out.push_back(sax::Token("epsilon", sax::Token::TokenType::END_ELEMENT));
 	} else {
-		out.splice(out.end(), alib::ToXMLComposers::symbolComposer.compose(symbol.get<alphabet::Symbol>()));
+		out.splice(out.end(), alib::api<alphabet::Symbol>::compose(symbol.get<alphabet::Symbol>()));
 	}
 	out.push_back(sax::Token("output", sax::Token::TokenType::END_ELEMENT));
 }
 
 void AutomatonToXMLComposer::composeTransitionInputString(std::list<sax::Token>& out, const string::String& string) const {
 	out.push_back(sax::Token("input", sax::Token::TokenType::START_ELEMENT));
-	out.splice(out.end(), alib::ToXMLComposers::stringComposer.compose(string));
+	out.splice(out.end(), alib::api<string::String>::compose(string));
 	out.push_back(sax::Token("input", sax::Token::TokenType::END_ELEMENT));
 }
 
 void AutomatonToXMLComposer::composeTransitionInputRegexp(std::list<sax::Token>& out, const regexp::RegExp& regexp) const {
 	out.push_back(sax::Token("input", sax::Token::TokenType::START_ELEMENT));
-	out.splice(out.end(), alib::ToXMLComposers::regexpComposer.compose(regexp));
+	out.splice(out.end(), alib::api<regexp::RegExp>::compose(regexp));
 	out.push_back(sax::Token("input", sax::Token::TokenType::END_ELEMENT));
 }
 
diff --git a/alib2data/src/automaton/AutomatonToXMLComposer.h b/alib2data/src/automaton/AutomatonToXMLComposer.h
index 65ea720316..6a5cd16aee 100644
--- a/alib2data/src/automaton/AutomatonToXMLComposer.h
+++ b/alib2data/src/automaton/AutomatonToXMLComposer.h
@@ -22,13 +22,19 @@
 #include "TM/OneTapeDTM.h"
 #include "../sax/Token.h"
 
+namespace alib {
+
+template<typename T>
+struct api;
+
+} /* namespace alib */
+
 namespace automaton {
 
 /**
  * This class contains methods to print XML representation of automata to the output stream.
  */
 class AutomatonToXMLComposer {
-protected:
 	void composeStates(std::list<sax::Token>&, const std::set<State>& states) const;
 	void composeInputAlphabet(std::list<sax::Token>&, const std::set<alphabet::Symbol>& symbols) const;
 	void composeInitialStates(std::list<sax::Token>&, const std::set<State>& states) const;
@@ -63,7 +69,6 @@ protected:
 	void composeTransitionInputString(std::list<sax::Token>&, const string::String& string) const;
 	void composeTransitionInputRegexp(std::list<sax::Token>&, const regexp::RegExp& regexp) const;
 
-public:
 	/**
 	 * Prints XML representation of UnknownAutomaton to the output stream.
 	 * @param automaton automaton to print
@@ -82,6 +87,8 @@ public:
 	std::list<sax::Token> compose(const NPDA& automaton) const;
 	std::list<sax::Token> compose(const SinglePopNPDA& automaton) const;
 	std::list<sax::Token> compose(const OneTapeDTM& automaton) const;
+
+	template<typename T> friend class alib::api;
 };
 
 } /* namespace automaton */
diff --git a/alib2data/src/container/ContainerToXMLComposer.hpp b/alib2data/src/container/ContainerToXMLComposer.hpp
index ecc2b8d834..74eb8341f6 100644
--- a/alib2data/src/container/ContainerToXMLComposer.hpp
+++ b/alib2data/src/container/ContainerToXMLComposer.hpp
@@ -28,7 +28,6 @@ namespace container {
  * This class contains methods to print XML representation of automata to the output stream.
  */
 class ContainerToXMLComposer {
-public:
 	/**
 	 * Prints XML representation of UnknownAutomaton to the output stream.
 	 * @param automaton automaton to print
diff --git a/alib2data/src/exception/ExceptionToXMLComposer.h b/alib2data/src/exception/ExceptionToXMLComposer.h
index 54d68dae97..0a6ccc9308 100644
--- a/alib2data/src/exception/ExceptionToXMLComposer.h
+++ b/alib2data/src/exception/ExceptionToXMLComposer.h
@@ -12,19 +12,27 @@
 #include "AlibException.h"
 #include "../sax/Token.h"
 
+namespace alib {
+
+template<typename T>
+struct api;
+
+} /* namespace alib */
+
 namespace exception {
 
 /**
  * This class contains methods to print XML representation of string to the output stream.
  */
 class ExceptionToXMLComposer {
-public:
 	/**
 	 * Prints XML representation of AlibException to the output stream.
 	 * @param string Exception to print
 	 * @param out output stream to which print the String
 	 */
 	std::list<sax::Token> compose(const AlibException& exception) const;
+
+	template<typename T> friend class alib::api;
 };
 
 } /* namespace exception */
diff --git a/alib2data/src/grammar/GrammarToXMLComposer.cpp b/alib2data/src/grammar/GrammarToXMLComposer.cpp
index 1725cd274e..887456daa1 100644
--- a/alib2data/src/grammar/GrammarToXMLComposer.cpp
+++ b/alib2data/src/grammar/GrammarToXMLComposer.cpp
@@ -223,7 +223,7 @@ std::list<sax::Token> GrammarToXMLComposer::compose(const UnrestrictedGrammar& g
 void GrammarToXMLComposer::composeNonterminalAlphabet(std::list<sax::Token>& out, const std::set<alphabet::Symbol>& symbols) const {
 	out.push_back(sax::Token("nonterminalAlphabet", sax::Token::TokenType::START_ELEMENT));
 	for (const auto& symbol : symbols) {
-		out.splice(out.end(), alib::ToXMLComposers::symbolComposer.compose(symbol));
+		out.splice(out.end(), alib::api<alphabet::Symbol>::compose(symbol));
 	}
 	out.push_back(sax::Token("nonterminalAlphabet", sax::Token::TokenType::END_ELEMENT));
 }
@@ -231,14 +231,14 @@ void GrammarToXMLComposer::composeNonterminalAlphabet(std::list<sax::Token>& out
 void GrammarToXMLComposer::composeTerminalAlphabet(std::list<sax::Token>& out, const std::set<alphabet::Symbol>& symbols) const {
 	out.push_back(sax::Token("terminalAlphabet", sax::Token::TokenType::START_ELEMENT));
 	for (const auto& symbol : symbols) {
-		out.splice(out.end(), alib::ToXMLComposers::symbolComposer.compose(symbol));
+		out.splice(out.end(), alib::api<alphabet::Symbol>::compose(symbol));
 	}
 	out.push_back(sax::Token("terminalAlphabet", sax::Token::TokenType::END_ELEMENT));
 }
 
 void GrammarToXMLComposer::composeInitialSymbol(std::list<sax::Token>& out, const alphabet::Symbol& symbol) const {
 	out.push_back(sax::Token("initialSymbol", sax::Token::TokenType::START_ELEMENT));
-	out.splice(out.end(), alib::ToXMLComposers::symbolComposer.compose(symbol));
+	out.splice(out.end(), alib::api<alphabet::Symbol>::compose(symbol));
 	out.push_back(sax::Token("initialSymbol", sax::Token::TokenType::END_ELEMENT));
 }
 
@@ -503,7 +503,7 @@ void GrammarToXMLComposer::composeRuleLContext(std::list<sax::Token>& out, const
 		out.push_back(sax::Token("epsilon", sax::Token::TokenType::START_ELEMENT));
 		out.push_back(sax::Token("epsilon", sax::Token::TokenType::END_ELEMENT));
 	} else for (const auto& symbol : symbols) {
-		out.splice(out.end(), alib::ToXMLComposers::symbolComposer.compose(symbol));
+		out.splice(out.end(), alib::api<alphabet::Symbol>::compose(symbol));
 	}
 	out.push_back(sax::Token("lContext", sax::Token::TokenType::END_ELEMENT));
 }
@@ -514,7 +514,7 @@ void GrammarToXMLComposer::composeRuleLHS(std::list<sax::Token>& out, const std:
 		out.push_back(sax::Token("epsilon", sax::Token::TokenType::START_ELEMENT));
 		out.push_back(sax::Token("epsilon", sax::Token::TokenType::END_ELEMENT));
 	} else for (const auto& symbol : symbols) {
-		out.splice(out.end(), alib::ToXMLComposers::symbolComposer.compose(symbol));
+		out.splice(out.end(), alib::api<alphabet::Symbol>::compose(symbol));
 	}
 	out.push_back(sax::Token("lhs", sax::Token::TokenType::END_ELEMENT));
 }
@@ -525,14 +525,14 @@ void GrammarToXMLComposer::composeRuleRContext(std::list<sax::Token>& out, const
 		out.push_back(sax::Token("epsilon", sax::Token::TokenType::START_ELEMENT));
 		out.push_back(sax::Token("epsilon", sax::Token::TokenType::END_ELEMENT));
 	} else for (const auto& symbol : symbols) {
-		out.splice(out.end(), alib::ToXMLComposers::symbolComposer.compose(symbol));
+		out.splice(out.end(), alib::api<alphabet::Symbol>::compose(symbol));
 	}
 	out.push_back(sax::Token("rContext", sax::Token::TokenType::END_ELEMENT));
 }
 
 void GrammarToXMLComposer::composeRuleSingleSymbolLHS(std::list<sax::Token>& out, const alphabet::Symbol& symbol) const {
 	out.push_back(sax::Token("lhs", sax::Token::TokenType::START_ELEMENT));
-	out.splice(out.end(), alib::ToXMLComposers::symbolComposer.compose(symbol));
+	out.splice(out.end(), alib::api<alphabet::Symbol>::compose(symbol));
 	out.push_back(sax::Token("lhs", sax::Token::TokenType::END_ELEMENT));
 }
 
@@ -542,7 +542,7 @@ void GrammarToXMLComposer::composeRuleRHS(std::list<sax::Token>& out, const std:
 		out.push_back(sax::Token("epsilon", sax::Token::TokenType::START_ELEMENT));
 		out.push_back(sax::Token("epsilon", sax::Token::TokenType::END_ELEMENT));
 	} else for (const auto& symbol : symbols) {
-		out.splice(out.end(), alib::ToXMLComposers::symbolComposer.compose(symbol));
+		out.splice(out.end(), alib::api<alphabet::Symbol>::compose(symbol));
 	}
 	out.push_back(sax::Token("rhs", sax::Token::TokenType::END_ELEMENT));
 }
@@ -550,11 +550,11 @@ void GrammarToXMLComposer::composeRuleRHS(std::list<sax::Token>& out, const std:
 void GrammarToXMLComposer::composeRuleOneOrTwoSymbolsRHS(std::list<sax::Token>& out, const std::variant<alphabet::Symbol, std::pair<alphabet::Symbol, alphabet::Symbol>>& symbols) const {
 	out.push_back(sax::Token("rhs", sax::Token::TokenType::START_ELEMENT));
 	if(symbols.is<alphabet::Symbol>()) {
-		out.splice(out.end(), alib::ToXMLComposers::symbolComposer.compose(symbols.get<alphabet::Symbol>()));
+		out.splice(out.end(), alib::api<alphabet::Symbol>::compose(symbols.get<alphabet::Symbol>()));
 	} else {
 		const std::pair<alphabet::Symbol, alphabet::Symbol>& rhs = symbols.get<std::pair<alphabet::Symbol, alphabet::Symbol>>();
-		out.splice(out.end(), alib::ToXMLComposers::symbolComposer.compose(rhs.first));
-		out.splice(out.end(), alib::ToXMLComposers::symbolComposer.compose(rhs.second));
+		out.splice(out.end(), alib::api<alphabet::Symbol>::compose(rhs.first));
+		out.splice(out.end(), alib::api<alphabet::Symbol>::compose(rhs.second));
 	}
 	out.push_back(sax::Token("rhs", sax::Token::TokenType::END_ELEMENT));
 }
@@ -562,10 +562,10 @@ void GrammarToXMLComposer::composeRuleOneOrTwoSymbolsRHS(std::list<sax::Token>&
 void GrammarToXMLComposer::composeRuleGNFRHS(std::list<sax::Token>& out, const std::pair<alphabet::Symbol, std::vector<alphabet::Symbol>>& symbols) const {
 	out.push_back(sax::Token("rhs", sax::Token::TokenType::START_ELEMENT));
 
-	out.splice(out.end(), alib::ToXMLComposers::symbolComposer.compose(symbols.first));
+	out.splice(out.end(), alib::api<alphabet::Symbol>::compose(symbols.first));
 
 	for (const auto& symbol : symbols.second) {
-		out.splice(out.end(), alib::ToXMLComposers::symbolComposer.compose(symbol));
+		out.splice(out.end(), alib::api<alphabet::Symbol>::compose(symbol));
 	}
 
 	out.push_back(sax::Token("rhs", sax::Token::TokenType::END_ELEMENT));
@@ -579,16 +579,16 @@ void GrammarToXMLComposer::composeRuleLGRHS(std::list<sax::Token>& out, const st
 			out.push_back(sax::Token("epsilon", sax::Token::TokenType::START_ELEMENT));
 			out.push_back(sax::Token("epsilon", sax::Token::TokenType::END_ELEMENT));
 		} else for (const auto& symbol : symbols.get<std::vector<alphabet::Symbol>>()) {
-			out.splice(out.end(), alib::ToXMLComposers::symbolComposer.compose(symbol));
+			out.splice(out.end(), alib::api<alphabet::Symbol>::compose(symbol));
 		}
 	} else {
 		const std::tuple<std::vector<alphabet::Symbol>, alphabet::Symbol, std::vector<alphabet::Symbol>>& rhs = symbols.get<std::tuple<std::vector<alphabet::Symbol>, alphabet::Symbol, std::vector<alphabet::Symbol>>>();
 		for (const auto& symbol : std::get<0>(rhs)) {
-			out.splice(out.end(), alib::ToXMLComposers::symbolComposer.compose(symbol));
+			out.splice(out.end(), alib::api<alphabet::Symbol>::compose(symbol));
 		}
-		out.splice(out.end(), alib::ToXMLComposers::symbolComposer.compose(std::get<1>(rhs)));
+		out.splice(out.end(), alib::api<alphabet::Symbol>::compose(std::get<1>(rhs)));
 		for (const auto& symbol : std::get<2>(rhs)) {
-			out.splice(out.end(), alib::ToXMLComposers::symbolComposer.compose(symbol));
+			out.splice(out.end(), alib::api<alphabet::Symbol>::compose(symbol));
 		}
 	}
 	out.push_back(sax::Token("rhs", sax::Token::TokenType::END_ELEMENT));
@@ -602,13 +602,13 @@ void GrammarToXMLComposer::composeRuleLeftLGRHS(std::list<sax::Token>& out, cons
 			out.push_back(sax::Token("epsilon", sax::Token::TokenType::START_ELEMENT));
 			out.push_back(sax::Token("epsilon", sax::Token::TokenType::END_ELEMENT));
 		} else for (const auto& symbol : symbols.get<std::vector<alphabet::Symbol>>()) {
-			out.splice(out.end(), alib::ToXMLComposers::symbolComposer.compose(symbol));
+			out.splice(out.end(), alib::api<alphabet::Symbol>::compose(symbol));
 		}
 	} else {
 		const std::pair<alphabet::Symbol, std::vector<alphabet::Symbol>>& rhs = symbols.get<std::pair<alphabet::Symbol, std::vector<alphabet::Symbol>>>();
-		out.splice(out.end(), alib::ToXMLComposers::symbolComposer.compose(rhs.first));
+		out.splice(out.end(), alib::api<alphabet::Symbol>::compose(rhs.first));
 		for (const auto& symbol : rhs.second) {
-			out.splice(out.end(), alib::ToXMLComposers::symbolComposer.compose(symbol));
+			out.splice(out.end(), alib::api<alphabet::Symbol>::compose(symbol));
 		}
 	}
 	out.push_back(sax::Token("rhs", sax::Token::TokenType::END_ELEMENT));
@@ -623,15 +623,15 @@ void GrammarToXMLComposer::composeRuleRightLGRHS(std::list<sax::Token>& out, con
 			out.push_back(sax::Token("epsilon", sax::Token::TokenType::END_ELEMENT));
 		} else {
 			for (const auto& symbol : symbols.get<std::vector<alphabet::Symbol>>()) {
-				out.splice(out.end(), alib::ToXMLComposers::symbolComposer.compose(symbol));
+				out.splice(out.end(), alib::api<alphabet::Symbol>::compose(symbol));
 			}
 		}
 	} else {
 		const std::pair<std::vector<alphabet::Symbol>, alphabet::Symbol>& rhs = symbols.get<std::pair<std::vector<alphabet::Symbol>, alphabet::Symbol>>();
 		for (const auto& symbol : rhs.first) {
-			out.splice(out.end(), alib::ToXMLComposers::symbolComposer.compose(symbol));
+			out.splice(out.end(), alib::api<alphabet::Symbol>::compose(symbol));
 		}
-		out.splice(out.end(), alib::ToXMLComposers::symbolComposer.compose(rhs.second));
+		out.splice(out.end(), alib::api<alphabet::Symbol>::compose(rhs.second));
 	}
 	out.push_back(sax::Token("rhs", sax::Token::TokenType::END_ELEMENT));
 }
diff --git a/alib2data/src/grammar/GrammarToXMLComposer.h b/alib2data/src/grammar/GrammarToXMLComposer.h
index 31c4b9c0a8..80beb747d1 100644
--- a/alib2data/src/grammar/GrammarToXMLComposer.h
+++ b/alib2data/src/grammar/GrammarToXMLComposer.h
@@ -27,6 +27,13 @@
 #include "Unrestricted/UnrestrictedGrammar.h"
 #include "../sax/Token.h"
 
+namespace alib {
+
+template<typename T>
+struct api;
+
+} /* namespace alib */
+
 namespace grammar {
 
 /**
@@ -63,7 +70,7 @@ class GrammarToXMLComposer {
 	void composeRuleLeftLGRHS(std::list<sax::Token>& out, const std::variant<std::vector<alphabet::Symbol>, std::pair<alphabet::Symbol, std::vector<alphabet::Symbol>>>& symbols) const;
 	void composeRuleRightLGRHS(std::list<sax::Token>& out, const std::variant<std::vector<alphabet::Symbol>, std::pair<std::vector<alphabet::Symbol>, alphabet::Symbol>>& symbols) const;
 	void composeRuleLGRHS(std::list<sax::Token>& out, const std::variant<std::vector<alphabet::Symbol>, std::tuple<std::vector<alphabet::Symbol>, alphabet::Symbol, std::vector<alphabet::Symbol>>>& symbols) const;
-public:
+	
 	/**
 	 * Prints XML representation of UnknownGrammar to the output stream.
 	 * @param grammar grammar to print
@@ -87,6 +94,8 @@ public:
 	std::list<sax::Token> compose(const NonContractingGrammar& grammar) const;
 	std::list<sax::Token> compose(const ContextPreservingUnrestrictedGrammar& grammar) const;
 	std::list<sax::Token> compose(const UnrestrictedGrammar& grammar) const;
+
+	template<typename T> friend class alib::api;
 };
 
 } /* namespace grammar */
diff --git a/alib2data/src/label/LabelToXMLComposer.h b/alib2data/src/label/LabelToXMLComposer.h
index 268a55e658..5f967bea93 100644
--- a/alib2data/src/label/LabelToXMLComposer.h
+++ b/alib2data/src/label/LabelToXMLComposer.h
@@ -12,13 +12,19 @@
 #include "Label.h"
 #include "../sax/Token.h"
 
+namespace alib {
+
+template<typename T>
+struct api;
+
+} /* namespace alib */
+
 namespace label {
 
 /**
  * This class contains methods to print XML representation of string to the output stream.
  */
 class LabelToXMLComposer {
-public:
 	/**
 	 * Prints XML representation of String to the output stream.
 	 * @param string String to print
@@ -36,6 +42,8 @@ public:
 	std::list<sax::Token> compose(const StringLabel& label) const;
 	std::list<sax::Token> compose(const IntegerLabel& label) const;
 	std::list<sax::Token> compose(const CharacterLabel& label) const;
+
+	template<typename T> friend class alib::api;
 };
 
 } /* namespace label */
diff --git a/alib2data/src/object/ObjectToXMLComposer.h b/alib2data/src/object/ObjectToXMLComposer.h
index 19716a87e5..23c69b5380 100644
--- a/alib2data/src/object/ObjectToXMLComposer.h
+++ b/alib2data/src/object/ObjectToXMLComposer.h
@@ -15,11 +15,17 @@
 
 namespace alib {
 
+template<typename T>
+struct api;
+
+} /* namespace alib */
+
+namespace alib {
+
 /**
  * This class contains methods to print XML representation of string to the output stream.
  */
 class ObjectToXMLComposer {
-public:
 	/**
 	 * Prints XML representation of UnknownAutomaton to the output stream.
 	 * @param automaton automaton to print
@@ -33,6 +39,8 @@ public:
 	 * @param out output stream to which print the String
 	 */
 	std::list<sax::Token> compose(const Object& object) const;
+
+	template<typename T> friend class alib::api;
 };
 
 } /* namespace alib */
diff --git a/alib2data/src/regexp/RegExpToXMLComposer.cpp b/alib2data/src/regexp/RegExpToXMLComposer.cpp
index 4142f82e83..10a03c0eb1 100644
--- a/alib2data/src/regexp/RegExpToXMLComposer.cpp
+++ b/alib2data/src/regexp/RegExpToXMLComposer.cpp
@@ -46,7 +46,7 @@ void RegExpToXMLComposer::Visit(void* userData, const UnboundedRegExpIteration&
 void RegExpToXMLComposer::Visit(void* userData, const UnboundedRegExpSymbol& symbol) const {
 	std::list<sax::Token> &out = *((std::list<sax::Token>*) userData);
 
-	out.splice(out.end(), alib::ToXMLComposers::symbolComposer.compose(symbol.getSymbol()));
+	out.splice(out.end(), alib::api<alphabet::Symbol>::compose(symbol.getSymbol()));
 }
 
 void RegExpToXMLComposer::Visit(void* userData, const UnboundedRegExpEpsilon&) const {
@@ -110,7 +110,7 @@ void RegExpToXMLComposer::Visit(void* userData, const FormalRegExpIteration& ite
 void RegExpToXMLComposer::Visit(void* userData, const FormalRegExpSymbol& symbol) const {
 	std::list<sax::Token> &out = *((std::list<sax::Token>*) userData);
 
-	out.splice(out.end(), alib::ToXMLComposers::symbolComposer.compose(symbol.getSymbol()));
+	out.splice(out.end(), alib::api<alphabet::Symbol>::compose(symbol.getSymbol()));
 }
 
 void RegExpToXMLComposer::Visit(void* userData, const FormalRegExpEpsilon&) const {
@@ -145,7 +145,7 @@ std::list<sax::Token> RegExpToXMLComposer::compose(const UnboundedRegExp& regexp
 	{
 		out.push_back(sax::Token("alphabet", sax::Token::TokenType::START_ELEMENT));
 		for (const auto& symbol: regexp.getAlphabet()) {
-			out.splice(out.end(), alib::ToXMLComposers::symbolComposer.compose(symbol));
+			out.splice(out.end(), alib::api<alphabet::Symbol>::compose(symbol));
 		}
 		out.push_back(sax::Token("alphabet", sax::Token::TokenType::END_ELEMENT));
 	}
@@ -160,7 +160,7 @@ std::list<sax::Token> RegExpToXMLComposer::compose(const FormalRegExp& regexp) c
 	{
 		out.push_back(sax::Token("alphabet", sax::Token::TokenType::START_ELEMENT));
 		for (const auto& symbol: regexp.getAlphabet()) {
-			out.splice(out.end(), alib::ToXMLComposers::symbolComposer.compose(symbol));
+			out.splice(out.end(), alib::api<alphabet::Symbol>::compose(symbol));
 		}
 		out.push_back(sax::Token("alphabet", sax::Token::TokenType::END_ELEMENT));
 	}
diff --git a/alib2data/src/regexp/RegExpToXMLComposer.h b/alib2data/src/regexp/RegExpToXMLComposer.h
index bd4adec4fc..3ec0aed7b5 100644
--- a/alib2data/src/regexp/RegExpToXMLComposer.h
+++ b/alib2data/src/regexp/RegExpToXMLComposer.h
@@ -14,6 +14,13 @@
 #include "../std/visitor.hpp"
 #include "../sax/Token.h"
 
+namespace alib {
+
+template<typename T>
+struct api;
+
+} /* namespace alib */
+
 namespace regexp {
 
 /**
@@ -36,7 +43,6 @@ class RegExpToXMLComposer :public UnboundedRegExpElement::const_visitor_type, pu
 	void Visit(void*, const FormalRegExpEmpty& empty) const;
 
 
-public:
 	/**
 	 * Composes XML token representation of RegExp.
 	 * @param regexp RegExp to print
@@ -53,6 +59,8 @@ public:
 
 	std::list<sax::Token> compose(const UnboundedRegExp& regexp) const;
 	std::list<sax::Token> compose(const FormalRegExp& regexp) const;
+
+	template<typename T> friend class alib::api;
 };
 
 } /* namespace regexp */
diff --git a/alib2data/src/string/StringToXMLComposer.cpp b/alib2data/src/string/StringToXMLComposer.cpp
index 2f31ea88cd..f45545a17d 100644
--- a/alib2data/src/string/StringToXMLComposer.cpp
+++ b/alib2data/src/string/StringToXMLComposer.cpp
@@ -31,12 +31,12 @@ std::list<sax::Token> StringToXMLComposer::compose(const LinearString& string) c
 	out.push_back(sax::Token("LinearString", sax::Token::TokenType::START_ELEMENT));
 	out.push_back(sax::Token("alphabet", sax::Token::TokenType::START_ELEMENT));
 	for (const auto& symbol: string.getAlphabet()) {
-		out.splice(out.end(), alib::ToXMLComposers::symbolComposer.compose(symbol));
+		out.splice(out.end(), alib::api<alphabet::Symbol>::compose(symbol));
 	}
 	out.push_back(sax::Token("alphabet", sax::Token::TokenType::END_ELEMENT));
 
 	for(const auto& symbol : string.getContent()) {
-		out.splice(out.end(), alib::ToXMLComposers::symbolComposer.compose(symbol));
+		out.splice(out.end(), alib::api<alphabet::Symbol>::compose(symbol));
 	}
 	out.push_back(sax::Token("LinearString", sax::Token::TokenType::END_ELEMENT));
 	return out;
@@ -47,12 +47,12 @@ std::list<sax::Token> StringToXMLComposer::compose(const CyclicString& string) c
 	out.push_back(sax::Token("CyclicString", sax::Token::TokenType::START_ELEMENT));
 	out.push_back(sax::Token("alphabet", sax::Token::TokenType::START_ELEMENT));
 	for (const auto& symbol: string.getAlphabet()) {
-		out.splice(out.end(), alib::ToXMLComposers::symbolComposer.compose(symbol));
+		out.splice(out.end(), alib::api<alphabet::Symbol>::compose(symbol));
 	}
 	out.push_back(sax::Token("alphabet", sax::Token::TokenType::END_ELEMENT));
 
 	for(const auto& symbol : string.getContent()) {
-		out.splice(out.end(), alib::ToXMLComposers::symbolComposer.compose(symbol));
+		out.splice(out.end(), alib::api<alphabet::Symbol>::compose(symbol));
 	}
 	out.push_back(sax::Token("CyclicString", sax::Token::TokenType::END_ELEMENT));
 	return out;
@@ -63,7 +63,7 @@ std::list<sax::Token> StringToXMLComposer::compose(const Epsilon& string) const
 	out.push_back(sax::Token("Epsilon", sax::Token::TokenType::START_ELEMENT));
 	out.push_back(sax::Token("alphabet", sax::Token::TokenType::START_ELEMENT));
 	for (const auto& symbol: string.getAlphabet()) {
-		out.splice(out.end(), alib::ToXMLComposers::symbolComposer.compose(symbol));
+		out.splice(out.end(), alib::api<alphabet::Symbol>::compose(symbol));
 	}
 	out.push_back(sax::Token("alphabet", sax::Token::TokenType::END_ELEMENT));
 	out.push_back(sax::Token("Epsilon", sax::Token::TokenType::END_ELEMENT));
diff --git a/alib2data/src/string/StringToXMLComposer.h b/alib2data/src/string/StringToXMLComposer.h
index 5b1f3ad87a..b2d81bd019 100644
--- a/alib2data/src/string/StringToXMLComposer.h
+++ b/alib2data/src/string/StringToXMLComposer.h
@@ -13,13 +13,19 @@
 #include "../sax/Token.h"
 #include "../alphabet/Symbol.h"
 
+namespace alib {
+
+template<typename T>
+struct api;
+
+} /* namespace alib */
+
 namespace string {
 
 /**
  * This class contains methods to print XML representation of string to the output stream.
  */
 class StringToXMLComposer {
-public:
 	/**
 	 * Prints XML representation of String to the output stream.
 	 * @param string String to print
@@ -37,6 +43,8 @@ public:
 	std::list<sax::Token> compose(const LinearString& string) const;
 	std::list<sax::Token> compose(const CyclicString& string) const;
 	std::list<sax::Token> compose(const Epsilon& string) const;
+
+	template<typename T> friend class alib::api;
 };
 
 } /* namespace string */
diff --git a/alib2data/test-src/alphabet/SymbolTest.cpp b/alib2data/test-src/alphabet/SymbolTest.cpp
index 72453b6fc5..21d11460d9 100644
--- a/alib2data/test-src/alphabet/SymbolTest.cpp
+++ b/alib2data/test-src/alphabet/SymbolTest.cpp
@@ -102,8 +102,7 @@ void SymbolTest::testXMLParser() {
   alphabet::Symbol symbol(alphabet::LabeledSymbol(label::Label(label::StringLabel("1"))));
 
   {
-	alphabet::SymbolToXMLComposer composer;
-	std::list<sax::Token> tokens = composer.compose(symbol);
+	std::list<sax::Token> tokens = alib::DataFactory::toTokens(symbol);
 	std::string tmp;
 	sax::SaxComposeInterface::printMemory(tmp, tokens);
   
diff --git a/alib2data/test-src/automaton/AutomatonTest.cpp b/alib2data/test-src/automaton/AutomatonTest.cpp
index 59661c2160..d7d63c7fb4 100644
--- a/alib2data/test-src/automaton/AutomatonTest.cpp
+++ b/alib2data/test-src/automaton/AutomatonTest.cpp
@@ -38,8 +38,7 @@ void AutomatonTest::testXMLParser() {
   
   CPPUNIT_ASSERT( automaton == automaton );
   {
-	automaton::AutomatonToXMLComposer composer;
-	std::list<sax::Token> tokens = composer.compose(automaton);
+	std::list<sax::Token> tokens = alib::DataFactory::toTokens(automaton);
 	std::string tmp;
 	sax::SaxComposeInterface::printMemory(tmp, tokens);
   
@@ -73,8 +72,7 @@ void AutomatonTest::testDFAParser() {
   
   CPPUNIT_ASSERT( automaton == automaton );
   {
-	automaton::AutomatonToXMLComposer composer;
-	std::list<sax::Token> tokens = composer.compose(automaton);
+	std::list<sax::Token> tokens = alib::DataFactory::toTokens(automaton);
 	std::string tmp;
 	sax::SaxComposeInterface::printMemory(tmp, tokens);
 
diff --git a/alib2data/test-src/grammar/GrammarTest.cpp b/alib2data/test-src/grammar/GrammarTest.cpp
index 784c7b2afa..6d8dcf3009 100644
--- a/alib2data/test-src/grammar/GrammarTest.cpp
+++ b/alib2data/test-src/grammar/GrammarTest.cpp
@@ -35,8 +35,7 @@ void GrammarTest::testXMLParser() {
   
   CPPUNIT_ASSERT( grammar == grammar );
   {
-	grammar::GrammarToXMLComposer composer;
-	std::list<sax::Token> tokens = composer.compose(grammar);
+	std::list<sax::Token> tokens = alib::DataFactory::toTokens(grammar);
 	std::string tmp;
 	sax::SaxComposeInterface::printMemory(tmp, tokens);
   
@@ -73,8 +72,7 @@ void GrammarTest::testUnrestrictedParser() {
 
   CPPUNIT_ASSERT( grammar == grammar );
   {
-	grammar::GrammarToXMLComposer composer;
-	std::list<sax::Token> tokens = composer.compose(grammar);
+	std::list<sax::Token> tokens = alib::DataFactory::toTokens(grammar);
 	std::string tmp;
 	sax::SaxComposeInterface::printMemory(tmp, tokens);
 
@@ -100,8 +98,7 @@ void GrammarTest::testUnrestrictedParser() {
     grammar.addRule(std::vector<alphabet::Symbol> {}, alphabet::Symbol(alphabet::LabeledSymbol(label::Label(label::IntegerLabel(2)))), std::vector<alphabet::Symbol> {}, std::vector<alphabet::Symbol> {});
     CPPUNIT_ASSERT( grammar == grammar );
     {
-	grammar::GrammarToXMLComposer composer;
-	std::list<sax::Token> tokens = composer.compose(grammar);
+	std::list<sax::Token> tokens = alib::DataFactory::toTokens(grammar);
 	std::string tmp;
 	sax::SaxComposeInterface::printMemory(tmp, tokens);
 
@@ -129,8 +126,7 @@ void GrammarTest::testRegularParser() {
 
     CPPUNIT_ASSERT( grammar == grammar );
     {
-	grammar::GrammarToXMLComposer composer;
-	std::list<sax::Token> tokens = composer.compose(grammar);
+	std::list<sax::Token> tokens = alib::DataFactory::toTokens(grammar);
 	std::string tmp;
 	sax::SaxComposeInterface::printMemory(tmp, tokens);
 
@@ -158,8 +154,7 @@ void GrammarTest::testRegularParser() {
 
     CPPUNIT_ASSERT( grammar == grammar );
     {
-	grammar::GrammarToXMLComposer composer;
-	std::list<sax::Token> tokens = composer.compose(grammar);
+	std::list<sax::Token> tokens = alib::DataFactory::toTokens(grammar);
 	std::string tmp;
 	sax::SaxComposeInterface::printMemory(tmp, tokens);
 
@@ -189,8 +184,7 @@ void GrammarTest::testContextFreeParser() {
 
     CPPUNIT_ASSERT( grammar == grammar );
     {
-	grammar::GrammarToXMLComposer composer;
-	std::list<sax::Token> tokens = composer.compose(grammar);
+	std::list<sax::Token> tokens = alib::DataFactory::toTokens(grammar);
 	std::string tmp;
 	sax::SaxComposeInterface::printMemory(tmp, tokens);
 
@@ -218,8 +212,7 @@ void GrammarTest::testContextFreeParser() {
 
     CPPUNIT_ASSERT( grammar == grammar );
     {
-	grammar::GrammarToXMLComposer composer;
-	std::list<sax::Token> tokens = composer.compose(grammar);
+	std::list<sax::Token> tokens = alib::DataFactory::toTokens(grammar);
 	std::string tmp;
 	sax::SaxComposeInterface::printMemory(tmp, tokens);
 
@@ -247,8 +240,7 @@ void GrammarTest::testContextFreeParser() {
 
     CPPUNIT_ASSERT( grammar == grammar );
     {
-	grammar::GrammarToXMLComposer composer;
-	std::list<sax::Token> tokens = composer.compose(grammar);
+	std::list<sax::Token> tokens = alib::DataFactory::toTokens(grammar);
 	std::string tmp;
 	sax::SaxComposeInterface::printMemory(tmp, tokens);
 
@@ -276,8 +268,7 @@ void GrammarTest::testContextFreeParser() {
 
     CPPUNIT_ASSERT( grammar == grammar );
     {
-	grammar::GrammarToXMLComposer composer;
-	std::list<sax::Token> tokens = composer.compose(grammar);
+	std::list<sax::Token> tokens = alib::DataFactory::toTokens(grammar);
 	std::string tmp;
 	sax::SaxComposeInterface::printMemory(tmp, tokens);
 
@@ -305,8 +296,7 @@ void GrammarTest::testContextFreeParser() {
 
     CPPUNIT_ASSERT( grammar == grammar );
     {
-	grammar::GrammarToXMLComposer composer;
-	std::list<sax::Token> tokens = composer.compose(grammar);
+	std::list<sax::Token> tokens = alib::DataFactory::toTokens(grammar);
 	std::string tmp;
 	sax::SaxComposeInterface::printMemory(tmp, tokens);
 
@@ -336,8 +326,7 @@ void GrammarTest::testContextSensitiveParser() {
 
     CPPUNIT_ASSERT( grammar == grammar );
     {
-	grammar::GrammarToXMLComposer composer;
-	std::list<sax::Token> tokens = composer.compose(grammar);
+	std::list<sax::Token> tokens = alib::DataFactory::toTokens(grammar);
 	std::string tmp;
 	sax::SaxComposeInterface::printMemory(tmp, tokens);
 
@@ -364,8 +353,7 @@ void GrammarTest::testContextSensitiveParser() {
 
     CPPUNIT_ASSERT( grammar == grammar );
     {
-	grammar::GrammarToXMLComposer composer;
-	std::list<sax::Token> tokens = composer.compose(grammar);
+	std::list<sax::Token> tokens = alib::DataFactory::toTokens(grammar);
 	std::string tmp;
 	sax::SaxComposeInterface::printMemory(tmp, tokens);
 
diff --git a/alib2data/test-src/label/LabelTest.cpp b/alib2data/test-src/label/LabelTest.cpp
index cc28609daa..953afdefe2 100644
--- a/alib2data/test-src/label/LabelTest.cpp
+++ b/alib2data/test-src/label/LabelTest.cpp
@@ -81,8 +81,7 @@ void LabelTest::testXMLParser() {
   label::Label label(label::StringLabel("1"));
 
   {
-	label::LabelToXMLComposer composer;
-	std::list<sax::Token> tokens = composer.compose(label);
+	std::list<sax::Token> tokens = alib::DataFactory::toTokens(label);
 	std::string tmp;
 	sax::SaxComposeInterface::printMemory(tmp, tokens);
   
diff --git a/alib2data/test-src/regexp/RegExpTest.cpp b/alib2data/test-src/regexp/RegExpTest.cpp
index eff762cff8..7caf0f1e9f 100644
--- a/alib2data/test-src/regexp/RegExpTest.cpp
+++ b/alib2data/test-src/regexp/RegExpTest.cpp
@@ -132,8 +132,7 @@ void RegExpTest::testXMLParser() {
   regexp::RegExp regexp(unboundedRegexp);
 
   {
-	regexp::RegExpToXMLComposer composer;
-	std::list<sax::Token> tokens = composer.compose(regexp);
+	std::list<sax::Token> tokens = alib::DataFactory::toTokens(regexp);
 	std::string tmp;
 	sax::SaxComposeInterface::printMemory(tmp, tokens);
   
diff --git a/alib2data/test-src/string/StringTest.cpp b/alib2data/test-src/string/StringTest.cpp
index ecb97ed6fd..a5086e5376 100644
--- a/alib2data/test-src/string/StringTest.cpp
+++ b/alib2data/test-src/string/StringTest.cpp
@@ -118,8 +118,7 @@ void StringTest::testXMLParser() {
 
   string::String string(linearString);
   {
-	string::StringToXMLComposer composer;
-	std::list<sax::Token> tokens = composer.compose(string);
+	std::list<sax::Token> tokens = alib::DataFactory::toTokens(string);
 	std::string tmp;
 	sax::SaxComposeInterface::printMemory(tmp, tokens);
 
-- 
GitLab