diff --git a/aaccess2/makefile b/aaccess2/makefile new file mode 100644 index 0000000000000000000000000000000000000000..dd28431218de3e5e12d74d27f43649de54c2e156 --- /dev/null +++ b/aaccess2/makefile @@ -0,0 +1,157 @@ +SHELL:=/bin/bash +USE_RAMDISK ?= 0 +-include makefile.conf + +define NEW_LINE + + +endef + +export NEW_LINE + +LDFLAGS_DEBUG:=-Wl,-no-as-needed $(addprefix -L, $(addsuffix lib-debug, $(LINK_PATHS))) -rdynamic $(addprefix -l, $(LINK_LIBRARIES)) -Wl,-rpath,. + +LDFLAGS_RELEASE:=-Wl,-no-as-needed $(addprefix -L, $(addsuffix lib-release, $(LINK_PATHS))) -rdynamic $(addprefix -l, $(LINK_LIBRARIES)) -Wl,-rpath,. + +OBJECTS_DEBUG:=$(patsubst src/%.cpp, obj-debug/%.o, $(shell find src/ -name *cpp)) + +OBJECTS_RELEASE:=$(patsubst src/%.cpp, obj-release/%.o, $(shell find src/ -name *cpp)) + +.PHONY: all build-debug clean-debug doc + +all: + @echo "What to do master?" + +FORCE: + +# ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +# make subdir makefile + +%/makefile: makefile makefile.conf + if [ ! -w $(dir $@) ] && [ $(USE_RAMDISK) -eq 1 ]; then\ + ln -s /tmp/`date +'%s%N'`-$(dir $@) $(subst /, , $(dir $@)) 2>/dev/null;\ + fi;\ + if [ -L $(subst /, , $(dir $@)) ]; then\ + mkdir -p `readlink $(subst /, , $(dir $@))`;\ + else\ + mkdir -p $(dir $@);\ + fi + echo "\ + SHELL:=/bin/bash$${NEW_LINE}\ + SRCDIR:=$${NEW_LINE}\ + $${NEW_LINE}\ + define NEW_LINE$${NEW_LINE}\ + $${NEW_LINE}\ + $${NEW_LINE}\ + endef$${NEW_LINE}\ + $${NEW_LINE}\ + export NEW_LINE$${NEW_LINE}\ + $${NEW_LINE}\ + CXXFLAGS:= -pipe -std=c++11 \$$(CXX_OTHER_FLAGS) -c -Wall -pedantic -Wextra -Werror -fPIC $(addprefix -I, $(INCLUDE_PATHS))$${NEW_LINE}\ + $${NEW_LINE}\ + SOURCES:= \$$(shell find \$$(SOURCES_BASE_DIR)/\$$(SRCDIR) -maxdepth 1 -type f -name \"*.cpp\")$${NEW_LINE}\ + DEPENDENCIES:= \$$(patsubst \$$(SOURCES_BASE_DIR)/\$$(SRCDIR)%.cpp, \$$(OBJECTS_BASE_DIR)/\$$(SRCDIR)%.d, \$$(SOURCES))$${NEW_LINE}\ + OBJECTS:= \$$(patsubst %.d, %.o, \$$(DEPENDENCIES))$${NEW_LINE}\ + SOURCES_DIRS:= \$$(shell find \$$(SOURCES_BASE_DIR)/\$$(SRCDIR) -maxdepth 1 -mindepth 1 -type d)$${NEW_LINE}\ + OBJECTS_DIRS:= \$$(patsubst \$$(SOURCES_BASE_DIR)/\$$(SRCDIR)%, %/, \$$(SOURCES_DIRS))$${NEW_LINE}\ + OBJECTS_DIRS_MAKEFILES:= \$$(patsubst %, %makefile, \$$(OBJECTS_DIRS))$${NEW_LINE}\ + $${NEW_LINE}\ + .PHONY: all$${NEW_LINE}\ + .PRECIOUS: \$$(DEPENDECIES) \$$(OBJECTS_DIRS_MAKEFILES)$${NEW_LINE}\ + $${NEW_LINE}\ + all: \$$(OBJECTS_DIRS) \$$(OBJECTS)$${NEW_LINE}\ + $${NEW_LINE}\ + %.d: makefile$${NEW_LINE}\ + @echo \"\\$${NEW_LINE}\ + \$$(shell sha1sum <<< \"\$$@\" | sed \"s/ -//g\") = \\$$\$$(shell (\\$$\$$(CXX) -M \\$$\$$(CXXFLAGS) \$$(patsubst \$$(OBJECTS_BASE_DIR)/\$$(SRCDIR)%.d,\$$(SOURCES_BASE_DIR)/\$$(SRCDIR)%.cpp, \$$@) 2>/dev/null || echo \\\"\$$(patsubst \$$(OBJECTS_BASE_DIR)/\$$(SRCDIR)%.d,\$$(SOURCES_BASE_DIR)/\$$(SRCDIR)%.cpp, \$$@) FORCE\\\") | sed \\\"s/.*://g;s/\\\\\\\\\\\\\\\\//g\\\")\$$\$${NEW_LINE}\\$${NEW_LINE}\ + \$$(patsubst %.d,%.o, \$$@): \\$$\$$(\$$(shell sha1sum <<< \"\$$@\" | sed \"s/ -//g\")) makefile\$$\$${NEW_LINE}\\$${NEW_LINE}\ + \\$$\$$(CXX) \\$$\$$(CXXFLAGS) \\$$\$$< -o \$$(patsubst %.d,%.o, \$$@)\$$\$${NEW_LINE}\\$${NEW_LINE}\ + \" > \$$@$${NEW_LINE}\ + $${NEW_LINE}\ + %/makefile: makefile$${NEW_LINE}\ + mkdir -p \$$(dir \$$@)$${NEW_LINE}\ + cp makefile \$$@$${NEW_LINE}\ + $${NEW_LINE}\ + %/: FORCE | %/makefile$${NEW_LINE}\ + @accesstime=\`stat -c %Y \$$@\` && \\$${NEW_LINE}\ + \$$(MAKE) -C \$$@ SRCDIR=\$$(SRCDIR)\$$(notdir \$$(patsubst %/, %, \$$@))/ OBJECTS_BASE_DIR=\$$(OBJECTS_BASE_DIR) SOURCES_BASE_DIR=\$$(SOURCES_BASE_DIR) CXX_OTHER_FLAGS=\"\$$(CXX_OTHER_FLAGS)\" && \\$${NEW_LINE}\ + accesstime2=\`stat -c %Y \$$@\` && \\$${NEW_LINE}\ + if [ "\$$\$$accesstime" -ne "\$$\$$accesstime2" ]; then \\$${NEW_LINE}\ + touch .; \\$${NEW_LINE}\ + fi$${NEW_LINE}\ + $${NEW_LINE}\ + FORCE:$${NEW_LINE}\ + $${NEW_LINE}\ + -include \$$(DEPENDENCIES)" > $@ + +# ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +# final lib/bin construction + +bin-debug/$(EXECUTABLE): obj-debug/ $(OBJECTS_DEBUG) + if [ ! -w $(dir $@) ] && [ $(USE_RAMDISK) -eq 1 ]; then\ + ln -s /tmp/`date +'%s%N'`-$(dir $@) $(subst /, , $(dir $@)) 2>/dev/null;\ + fi;\ + if [ -L $(subst /, , $(dir $@)) ]; then\ + mkdir -p `readlink $(subst /, , $(dir $@))`;\ + else\ + mkdir -p $(dir $@);\ + fi + $(CXX) $(OBJECTS_DEBUG) -o $@ $(LDFLAGS_DEBUG) + +bin-release/$(EXECUTABLE): obj-release/ $(OBJECTS_RELEASE) + if [ ! -w $(dir $@) ] && [ $(USE_RAMDISK) -eq 1 ]; then\ + ln -s /tmp/`date +'%s%N'`-$(dir $@) $(subst /, , $(dir $@)) 2>/dev/null;\ + fi;\ + if [ -L $(subst /, , $(dir $@)) ]; then\ + mkdir -p `readlink $(subst /, , $(dir $@))`;\ + else\ + mkdir -p $(dir $@);\ + fi + $(CXX) $(OBJECTS_RELEASE) -o $@ $(LDFLAGS_RELEASE) + +# ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +# subdir make calls + +obj-debug/: FORCE | obj-debug/makefile + $(MAKE) -C $@ OBJECTS_BASE_DIR=$(realpath obj-debug) SOURCES_BASE_DIR=$(realpath src) CXX_OTHER_FLAGS="-g -O0 -DDEBUG" + +obj-release/: FORCE | obj-release/makefile + $(MAKE) -C $@ OBJECTS_BASE_DIR=$(realpath obj-release) SOURCES_BASE_DIR=$(realpath src) CXX_OTHER_FLAGS="-O3 -DNDEBUG -DRELEASE" + +# ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +# objects dependencies + +$(OBJECTS_DEBUG): obj-debug/ + +$(OBJECTS_RELEASE): obj-release/ + +# ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +# main targets + +debug: bin-debug/$(EXECUTABLE) + +release: bin-release/$(EXECUTABLE) + +clean: clean-debug clean-release + $(RM) -r doc + +clean-debug: + if [ -L obj-debug ]; then\ + rm -r `readlink obj-debug`;\ + fi + if [ -L bin-debug ]; then\ + rm -r `readlink bin-debug`;\ + fi + $(RM) -r *.o *.d bin-debug obj-debug + +clean-release: + if [ -L obj-release ]; then\ + rm -r `readlink obj-release`;\ + fi + if [ -L lib-release ]; then\ + rm -r `readlink lib-release`;\ + fi + $(RM) -r *.o *.d bin-release obj-release + +doc: + doxygen diff --git a/aaccess2/makefile.conf b/aaccess2/makefile.conf new file mode 100644 index 0000000000000000000000000000000000000000..6ba6290e7bd690b11286fd9e44d2112217f9879b --- /dev/null +++ b/aaccess2/makefile.conf @@ -0,0 +1,4 @@ +EXECUTABLE:=aaccess2 +LINK_PATHS=../alib2elgo/ ../alib2algo/ ../alib2data/ ../alib2common/ ../alib2std/ +LINK_LIBRARIES=alib2elgo alib2algo alib2data alib2common alib2std xml2 +INCLUDE_PATHS=\$$(SOURCES_BASE_DIR)/../../alib2elgo/src/ \$$(SOURCES_BASE_DIR)/../../alib2algo/src/ \$$(SOURCES_BASE_DIR)/../../alib2data/src/ \$$(SOURCES_BASE_DIR)/../../alib2common/src/ \$$(SOURCES_BASE_DIR)/../../alib2std/src/ /usr/include/libxml2/ diff --git a/aaccess2/src/AutomatonAccess.cpp b/aaccess2/src/AutomatonAccess.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e852f1a7530794b8765b84df33b9c737940b9041 --- /dev/null +++ b/aaccess2/src/AutomatonAccess.cpp @@ -0,0 +1,113 @@ +/* + * AutomatonAccess.cpp + * + * Created on: 20. 9. 2014 + * Author: Jan Travnicek + */ + +#include "AutomatonAccess.h" + +#include <automaton/FSM/NFA.h> +#include <automaton/FSM/DFA.h> + +#include <automaton/PDA/InputDrivenNPDA.h> +#include <automaton/PDA/InputDrivenDPDA.h> + +#include <automaton/PDA/DPDA.h> +#include <automaton/PDA/NPDA.h> + +#include <factory/XmlDataFactory.hpp> +#include <container/ObjectsSet.h> +#include <container/ObjectsMap.h> +#include <container/ObjectsTuple.h> +#include <container/ObjectsVector.h> +#include <container/ObjectsVariant.h> +#include <container/ObjectsPair.h> + +void AutomatonAccess::access ( const automaton::Automaton & automaton, const std::set < AutomatonSettings::Settings > & settings ) { + dispatch ( automaton.getData ( ), settings ); +} + +void AutomatonAccess::access ( const automaton::NFA & automaton, const std::set < AutomatonSettings::Settings > & settings ) { + if ( settings.count ( AutomatonSettings::Settings::STATES ) ) alib::XmlDataFactory::toStdout ( automaton.getStates ( ) ); + + if ( settings.count ( AutomatonSettings::Settings::FINAL_STATES ) ) alib::XmlDataFactory::toStdout ( automaton.getFinalStates ( ) ); + + if ( settings.count ( AutomatonSettings::Settings::INITIAL_STATES ) ) alib::XmlDataFactory::toStdout ( automaton.getInitialState ( ) ); + + if ( settings.count ( AutomatonSettings::Settings::INPUT_ALPHABET ) ) alib::XmlDataFactory::toStdout ( automaton.getInputAlphabet ( ) ); + + if ( settings.count ( AutomatonSettings::Settings::TRANSITIONS ) ) alib::XmlDataFactory::toStdout ( automaton.getTransitions ( ) ); +} + +auto AutomatonAccessNFA = AutomatonAccess::RegistratorWrapper < void, automaton::NFA > ( AutomatonAccess::access ); + +void AutomatonAccess::access ( const automaton::DFA & automaton, const std::set < AutomatonSettings::Settings > & settings ) { + if ( settings.count ( AutomatonSettings::Settings::STATES ) ) alib::XmlDataFactory::toStdout ( automaton.getStates ( ) ); + + if ( settings.count ( AutomatonSettings::Settings::FINAL_STATES ) ) alib::XmlDataFactory::toStdout ( automaton.getFinalStates ( ) ); + + if ( settings.count ( AutomatonSettings::Settings::INITIAL_STATES ) ) alib::XmlDataFactory::toStdout ( automaton.getInitialState ( ) ); + + if ( settings.count ( AutomatonSettings::Settings::INPUT_ALPHABET ) ) alib::XmlDataFactory::toStdout ( automaton.getInputAlphabet ( ) ); + + if ( settings.count ( AutomatonSettings::Settings::TRANSITIONS ) ) alib::XmlDataFactory::toStdout ( automaton.getTransitions ( ) ); +} + +auto AutomatonAccessDFA = AutomatonAccess::RegistratorWrapper < void, automaton::DFA > ( AutomatonAccess::access ); + +void AutomatonAccess::access ( const automaton::InputDrivenNPDA & automaton, const std::set < AutomatonSettings::Settings > & settings ) { + if ( settings.count ( AutomatonSettings::Settings::STATES ) ) alib::XmlDataFactory::toStdout ( automaton.getStates ( ) ); + + if ( settings.count ( AutomatonSettings::Settings::FINAL_STATES ) ) alib::XmlDataFactory::toStdout ( automaton.getFinalStates ( ) ); + + if ( settings.count ( AutomatonSettings::Settings::INITIAL_STATES ) ) alib::XmlDataFactory::toStdout ( automaton.getInitialState ( ) ); + + if ( settings.count ( AutomatonSettings::Settings::INPUT_ALPHABET ) ) alib::XmlDataFactory::toStdout ( automaton.getInputAlphabet ( ) ); + + if ( settings.count ( AutomatonSettings::Settings::TRANSITIONS ) ) alib::XmlDataFactory::toStdout ( automaton.getTransitions ( ) ); +} + +auto AutomatonAccessInputDrivenNPDA = AutomatonAccess::RegistratorWrapper < void, automaton::InputDrivenNPDA > ( AutomatonAccess::access ); + +void AutomatonAccess::access ( const automaton::InputDrivenDPDA & automaton, const std::set < AutomatonSettings::Settings > & settings ) { + if ( settings.count ( AutomatonSettings::Settings::STATES ) ) alib::XmlDataFactory::toStdout ( automaton.getStates ( ) ); + + if ( settings.count ( AutomatonSettings::Settings::FINAL_STATES ) ) alib::XmlDataFactory::toStdout ( automaton.getFinalStates ( ) ); + + if ( settings.count ( AutomatonSettings::Settings::INITIAL_STATES ) ) alib::XmlDataFactory::toStdout ( automaton.getInitialState ( ) ); + + if ( settings.count ( AutomatonSettings::Settings::INPUT_ALPHABET ) ) alib::XmlDataFactory::toStdout ( automaton.getInputAlphabet ( ) ); + + if ( settings.count ( AutomatonSettings::Settings::TRANSITIONS ) ) alib::XmlDataFactory::toStdout ( automaton.getTransitions ( ) ); +} + +auto AutomatonAccessInputDrivenDPDA = AutomatonAccess::RegistratorWrapper < void, automaton::InputDrivenDPDA > ( AutomatonAccess::access ); + +void AutomatonAccess::access ( const automaton::NPDA & automaton, const std::set < AutomatonSettings::Settings > & settings ) { + if ( settings.count ( AutomatonSettings::Settings::STATES ) ) alib::XmlDataFactory::toStdout ( automaton.getStates ( ) ); + + if ( settings.count ( AutomatonSettings::Settings::FINAL_STATES ) ) alib::XmlDataFactory::toStdout ( automaton.getFinalStates ( ) ); + + if ( settings.count ( AutomatonSettings::Settings::INITIAL_STATES ) ) alib::XmlDataFactory::toStdout ( automaton.getInitialState ( ) ); + + if ( settings.count ( AutomatonSettings::Settings::INPUT_ALPHABET ) ) alib::XmlDataFactory::toStdout ( automaton.getInputAlphabet ( ) ); + + if ( settings.count ( AutomatonSettings::Settings::TRANSITIONS ) ) alib::XmlDataFactory::toStdout ( automaton.getTransitions ( ) ); +} + +auto AutomatonAccessNPDA = AutomatonAccess::RegistratorWrapper < void, automaton::NPDA > ( AutomatonAccess::access ); + +void AutomatonAccess::access ( const automaton::DPDA & automaton, const std::set < AutomatonSettings::Settings > & settings ) { + if ( settings.count ( AutomatonSettings::Settings::STATES ) ) alib::XmlDataFactory::toStdout ( automaton.getStates ( ) ); + + if ( settings.count ( AutomatonSettings::Settings::FINAL_STATES ) ) alib::XmlDataFactory::toStdout ( automaton.getFinalStates ( ) ); + + if ( settings.count ( AutomatonSettings::Settings::INITIAL_STATES ) ) alib::XmlDataFactory::toStdout ( automaton.getInitialState ( ) ); + + if ( settings.count ( AutomatonSettings::Settings::INPUT_ALPHABET ) ) alib::XmlDataFactory::toStdout ( automaton.getInputAlphabet ( ) ); + + if ( settings.count ( AutomatonSettings::Settings::TRANSITIONS ) ) alib::XmlDataFactory::toStdout ( automaton.getTransitions ( ) ); +} + +auto AutomatonAccessDPDA = AutomatonAccess::RegistratorWrapper < void, automaton::DPDA > ( AutomatonAccess::access ); diff --git a/aaccess2/src/AutomatonAccess.h b/aaccess2/src/AutomatonAccess.h new file mode 100644 index 0000000000000000000000000000000000000000..63566ba74e4a956b0e62aaccef162a93d6745881 --- /dev/null +++ b/aaccess2/src/AutomatonAccess.h @@ -0,0 +1,33 @@ +/* + * AutomatonAccess.h + * + * Created on: 20. 9. 2014 + * Author: Jan Travnicek + */ + +#ifndef AUTOMATA_STAT_H_ +#define AUTOMATA_STAT_H_ + +#include <core/multipleDispatch.hpp> + +#include "automaton/Automaton.h" +#include "automaton/AutomatonFeatures.h" + +#include "settings/AutomatonSettings.h" +#include <set> + +class AutomatonAccess : public std::SingleDispatchLastStaticParam < AutomatonAccess, void, automaton::AutomatonBase, const std::set < AutomatonSettings::Settings > & > { +public: + static void access ( const automaton::Automaton & automaton, const std::set < AutomatonSettings::Settings > & settings ); + + static void access ( const automaton::NFA & automaton, const std::set < AutomatonSettings::Settings > & settings ); + static void access ( const automaton::DFA & automaton, const std::set < AutomatonSettings::Settings > & settings ); + + static void access ( const automaton::InputDrivenNPDA & automaton, const std::set < AutomatonSettings::Settings > & settings ); + static void access ( const automaton::InputDrivenDPDA & automaton, const std::set < AutomatonSettings::Settings > & settings ); + + static void access ( const automaton::DPDA & automaton, const std::set < AutomatonSettings::Settings > & settings ); + static void access ( const automaton::NPDA & automaton, const std::set < AutomatonSettings::Settings > & settings ); +}; + +#endif /* AUTOMATA_STAT_H_ */ diff --git a/aaccess2/src/GrammarAccess.cpp b/aaccess2/src/GrammarAccess.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b82110488c4b1cbf765609110b635676c4e19dc0 --- /dev/null +++ b/aaccess2/src/GrammarAccess.cpp @@ -0,0 +1,47 @@ +/* + * GrammarAccess.cpp + * + * Created on: 20. 9. 2014 + * Author: Jan Travnicek + */ + +#include "GrammarAccess.h" + +#include <grammar/Regular/RightRG.h> +#include <grammar/Regular/RightLG.h> + +#include <factory/XmlDataFactory.hpp> +#include <container/ObjectsSet.h> +#include <container/ObjectsMap.h> +#include <container/ObjectsTuple.h> +#include <container/ObjectsVector.h> +#include <container/ObjectsVariant.h> +#include <container/ObjectsPair.h> + +void GrammarAccess::access ( const grammar::Grammar & grammar, const std::set < GrammarSettings::Settings > & settings ) { + dispatch ( grammar.getData ( ), settings ); +} + +void GrammarAccess::access ( const grammar::RightRG & grammar, const std::set < GrammarSettings::Settings > & settings ) { + if ( settings.count ( GrammarSettings::Settings::NONTERMINALS ) ) alib::XmlDataFactory::toStdout ( grammar.getNonterminalAlphabet ( ) ); + + if ( settings.count ( GrammarSettings::Settings::TERMINALS ) ) alib::XmlDataFactory::toStdout ( grammar.getTerminalAlphabet ( ) ); + + if ( settings.count ( GrammarSettings::Settings::INITIAL_SYMBOLS ) ) alib::XmlDataFactory::toStdout ( grammar.getInitialSymbol ( ) ); + + if ( settings.count ( GrammarSettings::Settings::RULES ) ) alib::XmlDataFactory::toStdout ( grammar.getRules ( ) ); +} + +auto GrammarAccessRightRG = GrammarAccess::RegistratorWrapper < void, grammar::RightRG > ( GrammarAccess::access ); + +void GrammarAccess::access ( const grammar::RightLG & grammar, const std::set < GrammarSettings::Settings > & settings ) { + if ( settings.count ( GrammarSettings::Settings::NONTERMINALS ) ) alib::XmlDataFactory::toStdout ( grammar.getNonterminalAlphabet ( ) ); + + if ( settings.count ( GrammarSettings::Settings::TERMINALS ) ) alib::XmlDataFactory::toStdout ( grammar.getTerminalAlphabet ( ) ); + + if ( settings.count ( GrammarSettings::Settings::INITIAL_SYMBOLS ) ) alib::XmlDataFactory::toStdout ( grammar.getInitialSymbol ( ) ); + + if ( settings.count ( GrammarSettings::Settings::RULES ) ) alib::XmlDataFactory::toStdout ( grammar.getRules ( ) ); +} + +auto GrammarAccessRightLG = GrammarAccess::RegistratorWrapper < void, grammar::RightLG > ( GrammarAccess::access ); diff --git a/aaccess2/src/GrammarAccess.h b/aaccess2/src/GrammarAccess.h new file mode 100644 index 0000000000000000000000000000000000000000..96c2b54329119875d2aa2701a82c5c0f6b0aa005 --- /dev/null +++ b/aaccess2/src/GrammarAccess.h @@ -0,0 +1,27 @@ +/* + * GrammarAccess.h + * + * Created on: 20. 9. 2014 + * Author: Jan Travnicek + */ + +#ifndef GRAMMAR_STAT_H_ +#define GRAMMAR_STAT_H_ + +#include <core/multipleDispatch.hpp> + +#include "grammar/Grammar.h" +#include "grammar/GrammarFeatures.h" + +#include "settings/GrammarSettings.h" +#include <set> + +class GrammarAccess : public std::SingleDispatchLastStaticParam < GrammarAccess, void, grammar::GrammarBase, const std::set < GrammarSettings::Settings > & > { +public: + static void access ( const grammar::Grammar & grammar, const std::set < GrammarSettings::Settings > & settings ); + + static void access ( const grammar::RightRG & grammar, const std::set < GrammarSettings::Settings > & settings ); + static void access ( const grammar::RightLG & grammar, const std::set < GrammarSettings::Settings > & settings ); +}; + +#endif /* GRAMMAR_STAT_H_ */ diff --git a/aaccess2/src/RegExpAccess.cpp b/aaccess2/src/RegExpAccess.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a54ab80f3a97e725b1cb1fedbdd6fa8aa1bb4855 --- /dev/null +++ b/aaccess2/src/RegExpAccess.cpp @@ -0,0 +1,43 @@ +/* + * RegExpAccess.cpp + * + * Created on: 20. 9. 2014 + * Author: Jan Travnicek + */ + +#include "RegExpAccess.h" + +#include <exception/CommonException.h> + +#include <regexp/formal/FormalRegExp.h> +#include <regexp/formal/FormalRegExpElement.h> +#include <regexp/unbounded/UnboundedRegExp.h> +#include <regexp/unbounded/UnboundedRegExpElement.h> + +#include <factory/XmlDataFactory.hpp> +#include <container/ObjectsSet.h> +#include <container/ObjectsMap.h> +#include <container/ObjectsTuple.h> +#include <container/ObjectsVector.h> +#include <container/ObjectsVariant.h> +#include <container/ObjectsPair.h> + +void RegExpAccess::access ( const regexp::RegExp & regexp, const std::set < RegExpSettings::Settings > & settings ) { + dispatch ( regexp.getData ( ), settings ); +} + +void RegExpAccess::access ( const regexp::FormalRegExp & regexp, const std::set < RegExpSettings::Settings > & settings ) { + if ( settings.count ( RegExpSettings::Settings::ALPHABET ) ) alib::XmlDataFactory::toStdout ( regexp.getAlphabet ( ) ); + + if ( settings.count ( RegExpSettings::Settings::CONTENT ) ) alib::XmlDataFactory::toStdout ( regexp.getRegExp ( ) ); +} + +auto RegExpAccessFormalRegExp = RegExpAccess::RegistratorWrapper < void, regexp::FormalRegExp > ( RegExpAccess::access ); + +void RegExpAccess::access ( const regexp::UnboundedRegExp & regexp, const std::set < RegExpSettings::Settings > & settings ) { + if ( settings.count ( RegExpSettings::Settings::ALPHABET ) ) alib::XmlDataFactory::toStdout ( regexp.getAlphabet ( ) ); + + if ( settings.count ( RegExpSettings::Settings::CONTENT ) ) alib::XmlDataFactory::toStdout ( regexp.getRegExp ( ) ); +} + +auto RegExpAccessUnboundedRegExp = RegExpAccess::RegistratorWrapper < void, regexp::UnboundedRegExp > ( RegExpAccess::access ); diff --git a/aaccess2/src/RegExpAccess.h b/aaccess2/src/RegExpAccess.h new file mode 100644 index 0000000000000000000000000000000000000000..44fafb9e8566eaa1671f05828ccb82c2e9d17372 --- /dev/null +++ b/aaccess2/src/RegExpAccess.h @@ -0,0 +1,27 @@ +/* + * RegExpAccess.h + * + * Created on: 20. 9. 2014 + * Author: Jan Travnicek + */ + +#ifndef REG_EXP_STAT_H_ +#define REG_EXP_STAT_H_ + +#include <core/multipleDispatch.hpp> + +#include "regexp/RegExp.h" +#include "regexp/RegExpFeatures.h" + +#include "settings/RegExpSettings.h" +#include <set> + +class RegExpAccess : public std::SingleDispatchLastStaticParam < RegExpAccess, void, regexp::RegExpBase, const std::set < RegExpSettings::Settings > & > { +public: + static void access ( const regexp::RegExp & regexp, const std::set < RegExpSettings::Settings > & settings ); + + static void access ( const regexp::UnboundedRegExp & regexp, const std::set < RegExpSettings::Settings > & settings ); + static void access ( const regexp::FormalRegExp & regexp, const std::set < RegExpSettings::Settings > & settings ); +}; + +#endif /* REG_EXP_STAT_H_ */ diff --git a/aaccess2/src/StringAccess.cpp b/aaccess2/src/StringAccess.cpp new file mode 100644 index 0000000000000000000000000000000000000000..811ab707901ca7918f01134111ab911fbb4f1728 --- /dev/null +++ b/aaccess2/src/StringAccess.cpp @@ -0,0 +1,39 @@ +/* + * StringAccess.cpp + * + * Created on: 20. 9. 2014 + * Author: Jan Travnicek + */ + +#include "StringAccess.h" + +#include <string/LinearString.h> +#include <string/CyclicString.h> + +#include <factory/XmlDataFactory.hpp> +#include <container/ObjectsSet.h> +#include <container/ObjectsMap.h> +#include <container/ObjectsTuple.h> +#include <container/ObjectsVector.h> +#include <container/ObjectsVariant.h> +#include <container/ObjectsPair.h> + +void StringAccess::access ( const string::String & string, const std::set < StringSettings::Settings > & settings ) { + dispatch ( string.getData ( ), settings ); +} + +void StringAccess::access ( const string::LinearString & string, const std::set < StringSettings::Settings > & settings ) { + if ( settings.count ( StringSettings::Settings::ALPHABET ) ) alib::XmlDataFactory::toStdout ( string.getAlphabet ( ) ); + + if ( settings.count ( StringSettings::Settings::CONTENT ) ) alib::XmlDataFactory::toStdout ( string.getContent ( ) ); +} + +auto StringAccessFormalString = StringAccess::RegistratorWrapper < void, string::LinearString > ( StringAccess::access ); + +void StringAccess::access ( const string::CyclicString & string, const std::set < StringSettings::Settings > & settings ) { + if ( settings.count ( StringSettings::Settings::ALPHABET ) ) alib::XmlDataFactory::toStdout ( string.getAlphabet ( ) ); + + if ( settings.count ( StringSettings::Settings::CONTENT ) ) alib::XmlDataFactory::toStdout ( string.getContent ( ) ); +} + +auto StringAccessUnboundedString = StringAccess::RegistratorWrapper < void, string::CyclicString > ( StringAccess::access ); diff --git a/aaccess2/src/StringAccess.h b/aaccess2/src/StringAccess.h new file mode 100644 index 0000000000000000000000000000000000000000..e5fa9cab38cf8b4d933f4572757db7035135a996 --- /dev/null +++ b/aaccess2/src/StringAccess.h @@ -0,0 +1,27 @@ +/* + * StringAccess.h + * + * Created on: 20. 9. 2014 + * Author: Jan Travnicek + */ + +#ifndef STRING_STAT_H_ +#define STRING_STAT_H_ + +#include <core/multipleDispatch.hpp> + +#include "string/String.h" +#include "string/StringFeatures.h" + +#include "settings/StringSettings.h" +#include <set> + +class StringAccess : public std::SingleDispatchLastStaticParam < StringAccess, void, string::StringBase, const std::set < StringSettings::Settings > & > { +public: + static void access ( const string::String & string, const std::set < StringSettings::Settings > & settings ); + + static void access ( const string::LinearString & string, const std::set < StringSettings::Settings > & settings ); + static void access ( const string::CyclicString & string, const std::set < StringSettings::Settings > & settings ); +}; + +#endif /* STRING_STAT_H_ */ diff --git a/aaccess2/src/TreeAccess.cpp b/aaccess2/src/TreeAccess.cpp new file mode 100644 index 0000000000000000000000000000000000000000..440d967311cfccdd242061880d873ca810139ea3 --- /dev/null +++ b/aaccess2/src/TreeAccess.cpp @@ -0,0 +1,73 @@ +/* + * TreeAccess.cpp + * + * Created on: 20. 9. 2014 + * Author: Jan Travnicek + */ + +#include "TreeAccess.h" + +#include <tree/ranked/RankedTree.h> +#include <tree/ranked/RankedPattern.h> +#include <tree/ranked/RankedNonlinearPattern.h> +#include <tree/unranked/UnrankedTree.h> + +#include <factory/XmlDataFactory.hpp> +#include <container/ObjectsSet.h> +#include <container/ObjectsMap.h> +#include <container/ObjectsTuple.h> +#include <container/ObjectsVector.h> +#include <container/ObjectsVariant.h> +#include <container/ObjectsPair.h> + +void TreeAccess::access ( const tree::Tree & tree, const std::set < TreeSettings::Settings > & settings ) { + dispatch ( tree.getData ( ), settings ); +} + +void TreeAccess::access ( const tree::RankedTree & tree, const std::set < TreeSettings::Settings > & settings ) { + if ( settings.count ( TreeSettings::Settings::ALPHABET ) ) alib::XmlDataFactory::toStdout ( tree.getAlphabet ( ) ); + + if ( settings.count ( TreeSettings::Settings::CONTENT ) ) alib::XmlDataFactory::toStdout ( tree.getRoot ( ) ); + + if ( settings.count ( TreeSettings::Settings::SUBTREE_WILDCARD ) ) throw exception::CommonException ( "Not available" ); + + if ( settings.count ( TreeSettings::Settings::NONLINEAR_VARIABLES ) ) throw exception::CommonException ( "Not available" ); +} + +auto TreeAccessRankedTree = TreeAccess::RegistratorWrapper < void, tree::RankedTree > ( TreeAccess::access ); + +void TreeAccess::access ( const tree::RankedPattern & tree, const std::set < TreeSettings::Settings > & settings ) { + if ( settings.count ( TreeSettings::Settings::ALPHABET ) ) alib::XmlDataFactory::toStdout ( tree.getAlphabet ( ) ); + + if ( settings.count ( TreeSettings::Settings::CONTENT ) ) alib::XmlDataFactory::toStdout ( tree.getRoot ( ) ); + + if ( settings.count ( TreeSettings::Settings::SUBTREE_WILDCARD ) ) alib::XmlDataFactory::toStdout ( tree.getSubtreeWildcard ( ) ); + + if ( settings.count ( TreeSettings::Settings::NONLINEAR_VARIABLES ) ) throw exception::CommonException ( "Not available" ); +} + +auto TreeAccessRankedPattern = TreeAccess::RegistratorWrapper < void, tree::RankedPattern > ( TreeAccess::access ); + +void TreeAccess::access ( const tree::RankedNonlinearPattern & tree, const std::set < TreeSettings::Settings > & settings ) { + if ( settings.count ( TreeSettings::Settings::ALPHABET ) ) alib::XmlDataFactory::toStdout ( tree.getAlphabet ( ) ); + + if ( settings.count ( TreeSettings::Settings::CONTENT ) ) alib::XmlDataFactory::toStdout ( tree.getRoot ( ) ); + + if ( settings.count ( TreeSettings::Settings::SUBTREE_WILDCARD ) ) alib::XmlDataFactory::toStdout ( tree.getSubtreeWildcard ( ) ); + + if ( settings.count ( TreeSettings::Settings::NONLINEAR_VARIABLES ) ) alib::XmlDataFactory::toStdout ( tree.getNonlinearVariables ( ) ); +} + +auto TreeAccessRankedNonlinearPattern = TreeAccess::RegistratorWrapper < void, tree::RankedNonlinearPattern > ( TreeAccess::access ); + +void TreeAccess::access ( const tree::UnrankedTree & tree, const std::set < TreeSettings::Settings > & settings ) { + if ( settings.count ( TreeSettings::Settings::ALPHABET ) ) alib::XmlDataFactory::toStdout ( tree.getAlphabet ( ) ); + + if ( settings.count ( TreeSettings::Settings::CONTENT ) ) alib::XmlDataFactory::toStdout ( tree.getRoot ( ) ); + + if ( settings.count ( TreeSettings::Settings::SUBTREE_WILDCARD ) ) throw exception::CommonException ( "Not available" ); + + if ( settings.count ( TreeSettings::Settings::NONLINEAR_VARIABLES ) ) throw exception::CommonException ( "Not available" ); +} + +auto TreeAccessUnrankedTree = TreeAccess::RegistratorWrapper < void, tree::UnrankedTree > ( TreeAccess::access ); diff --git a/aaccess2/src/TreeAccess.h b/aaccess2/src/TreeAccess.h new file mode 100644 index 0000000000000000000000000000000000000000..e012c26666bdd1b9aeb9c2c0d59847137d7c8a59 --- /dev/null +++ b/aaccess2/src/TreeAccess.h @@ -0,0 +1,29 @@ +/* + * TreeAccess.h + * + * Created on: 20. 9. 2014 + * Author: Jan Travnicek + */ + +#ifndef TREE_STAT_H_ +#define TREE_STAT_H_ + +#include <core/multipleDispatch.hpp> + +#include "tree/Tree.h" +#include "tree/TreeFeatures.h" + +#include "settings/TreeSettings.h" +#include <set> + +class TreeAccess : public std::SingleDispatchLastStaticParam < TreeAccess, void, tree::TreeBase, const std::set < TreeSettings::Settings > & > { +public: + static void access ( const tree::Tree & tree, const std::set < TreeSettings::Settings > & settings ); + + static void access ( const tree::RankedTree & tree, const std::set < TreeSettings::Settings > & settings ); + static void access ( const tree::RankedPattern & tree, const std::set < TreeSettings::Settings > & settings ); + static void access ( const tree::RankedNonlinearPattern & tree, const std::set < TreeSettings::Settings > & settings ); + static void access ( const tree::UnrankedTree & tree, const std::set < TreeSettings::Settings > & settings ); +}; + +#endif /* TREE_STAT_H_ */ diff --git a/aaccess2/src/aaccess.cpp b/aaccess2/src/aaccess.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e42e31b4970c9f9ef65af84155ddab91b19b7782 --- /dev/null +++ b/aaccess2/src/aaccess.cpp @@ -0,0 +1,194 @@ +/* + * aaccess.cpp + * + * Created on: 26. 3. 2014 + * Author: Jan Travnicek + */ + +#include <tclap/CmdLine.h> +#include <global/GlobalData.h> +#include <measure> +#include <vector> +#include <sax/FromXMLParserHelper.h> + +#include <factory/XmlDataFactory.hpp> +#include <exception/CommonException.h> + +#include "AutomatonAccess.h" +#include "GrammarAccess.h" +#include "RegExpAccess.h" +#include "StringAccess.h" +#include "TreeAccess.h" + +int main ( int argc, char * argv[] ) { + try { + common::GlobalData::argc = argc; + common::GlobalData::argv = argv; + + TCLAP::CmdLine cmd ( "Prints internals of automata, grammars, regexps, ...", ' ', "0.01" ); + + // ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- + std::vector < std::string > automatonSettings { + AutomatonSettings::stringsVector ( ) + }; + + TCLAP::ValuesConstraint < std::string > automatonPrintingOptionsVals ( automatonSettings ); + + TCLAP::MultiArg < std::string > automaton ( "", "automaton", "Display stats of automata", false, & automatonPrintingOptionsVals ); + + // ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- + + std::vector < std::string > grammarSettings { + GrammarSettings::stringsVector ( ) + }; + + TCLAP::ValuesConstraint < std::string > grammarPrintingOptionsVals ( grammarSettings ); + + TCLAP::MultiArg < std::string > grammar ( "", "grammar", "Display stats of grammars", false, & grammarPrintingOptionsVals ); + + // ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- + + std::vector < std::string > regexpSettings { + RegExpSettings::stringsVector ( ) + }; + + TCLAP::ValuesConstraint < std::string > regexpPrintingOptionsVals ( regexpSettings ); + + TCLAP::MultiArg < std::string > regexp ( "", "regexp", "Display stats of regexps", false, & regexpPrintingOptionsVals ); + + // ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- + + std::vector < std::string > stringSettings { + StringSettings::stringsVector ( ) + }; + + TCLAP::ValuesConstraint < std::string > stringPrintingOptionsVals ( stringSettings ); + + TCLAP::MultiArg < std::string > string ( "", "string", "Display stats of strings", false, & stringPrintingOptionsVals ); + + // ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- + + std::vector < std::string > treeSettings { + TreeSettings::stringsVector ( ) + }; + + TCLAP::ValuesConstraint < std::string > treePrintingOptionsVals ( treeSettings ); + + TCLAP::MultiArg < std::string > tree ( "", "tree", "Display stats of trees", false, & treePrintingOptionsVals ); + + // ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- + + std::vector < TCLAP::Arg * > xorlist; + xorlist.push_back ( & automaton ); + xorlist.push_back ( & grammar ); + xorlist.push_back ( & regexp ); + xorlist.push_back ( & string ); + xorlist.push_back ( & tree ); + cmd.xorAdd ( xorlist ); + + TCLAP::ValueArg < std::string > file ( "i", "input", "Read from file", false, "-", "file" ); + cmd.add ( file ); + + TCLAP::SwitchArg measure ( "m", "measure", "Measure times", false ); + cmd.add ( measure ); + + TCLAP::SwitchArg verbose ( "v", "verbose", "Be verbose", false ); + cmd.add ( verbose ); + + cmd.parse ( argc, argv ); + + if ( verbose.isSet ( ) ) + common::GlobalData::verbose = true; + + if ( measure.isSet ( ) ) + common::GlobalData::measure = true; + + measurements::start ( "Overal", measurements::Type::OVERALL ); + measurements::start ( "Input read", measurements::Type::AUXILIARY ); + + std::deque < sax::Token > tokens = sax::FromXMLParserHelper::parseInput ( file ); + + if ( alib::XmlDataFactory::first < automaton::Automaton > ( tokens ) && automaton.isSet ( ) ) { + std::set < AutomatonSettings::Settings > settings; + + for ( const std::string & param : automaton.getValue ( ) ) + settings.insert ( AutomatonSettings::fromString ( param ) ); + + automaton::Automaton automaton = alib::XmlDataFactory::fromTokens < automaton::Automaton > ( std::move ( tokens ) ); + + measurements::end ( ); + measurements::start ( "Accesss print", measurements::Type::MAIN ); + + AutomatonAccess::access ( automaton, settings ); + } else if ( alib::XmlDataFactory::first < grammar::Grammar > ( tokens ) && grammar.isSet ( ) ) { + std::set < GrammarSettings::Settings > settings; + + for ( const std::string & param : grammar.getValue ( ) ) + settings.insert ( GrammarSettings::fromString ( param ) ); + + grammar::Grammar grammar = alib::XmlDataFactory::fromTokens < grammar::Grammar > ( std::move ( tokens ) ); + + measurements::end ( ); + measurements::start ( "Accesss print", measurements::Type::MAIN ); + + GrammarAccess::access ( grammar, settings ); + } else if ( alib::XmlDataFactory::first < regexp::RegExp > ( tokens ) && regexp.isSet ( ) ) { + std::set < RegExpSettings::Settings > settings; + + for ( const std::string & param : regexp.getValue ( ) ) + settings.insert ( RegExpSettings::fromString ( param ) ); + + regexp::RegExp regexp = alib::XmlDataFactory::fromTokens < regexp::RegExp > ( std::move ( tokens ) ); + + measurements::end ( ); + measurements::start ( "Accesss print", measurements::Type::MAIN ); + + RegExpAccess::access ( regexp, settings ); + } else if ( alib::XmlDataFactory::first < string::String > ( tokens ) && string.isSet ( ) ) { + std::set < StringSettings::Settings > settings; + + for ( const std::string & param : string.getValue ( ) ) + settings.insert ( StringSettings::fromString ( param ) ); + + string::String string = alib::XmlDataFactory::fromTokens < string::String > ( std::move ( tokens ) ); + + measurements::end ( ); + measurements::start ( "Accesss print", measurements::Type::MAIN ); + + StringAccess::access ( string, settings ); + } else if ( alib::XmlDataFactory::first < tree::Tree > ( tokens ) && tree.isSet ( ) ) { + std::set < TreeSettings::Settings > settings; + + for ( const std::string & param : tree.getValue ( ) ) + settings.insert ( TreeSettings::fromString ( param ) ); + + tree::Tree tree = alib::XmlDataFactory::fromTokens < tree::Tree > ( std::move ( tokens ) ); + + measurements::end ( ); + measurements::start ( "Accesss print", measurements::Type::MAIN ); + + TreeAccess::access ( tree, settings ); + } else { + throw exception::CommonException ( "Input not recognized." ); + } + + measurements::end ( ); + measurements::end ( ); + + if ( measure.getValue ( ) ) std::cmeasure << measurements::results ( ) << std::endl; + + return 0; + } catch ( const exception::CommonException & exception ) { + alib::XmlDataFactory::toStdout ( exception ); + return 1; + } catch ( const TCLAP::ArgException & exception ) { + std::cout << exception.error ( ) << std::endl; + return 2; + } catch ( const std::exception & exception ) { + std::cerr << "Exception caught: " << exception.what ( ) << std::endl; + return 3; + } catch ( ... ) { + std::cerr << "Unknown exception caught." << std::endl; + return 127; + } +} diff --git a/aaccess2/src/settings/AutomatonSettings.h b/aaccess2/src/settings/AutomatonSettings.h new file mode 100644 index 0000000000000000000000000000000000000000..055bdb553e6ce97a97687d4c937e35aaa18358c5 --- /dev/null +++ b/aaccess2/src/settings/AutomatonSettings.h @@ -0,0 +1,53 @@ +/* + * AutomatonSettings.h + * + * Created on: 26. 3. 2014 + * Author: Jan Travnicek + */ + +#ifndef __AUTOMATA_SETTINGS_H__ +#define __AUTOMATA_SETTINGS_H__ + +#include "SettingsHelper.h" + +class AutomatonEnum { +public: + enum class Settings { + STATES, FINAL_STATES, INITIAL_STATES, INPUT_ALPHABET, TRANSITIONS, EPSILON_TRANSITIONS, READING_TRANSITIONS, __MAX__ + }; + + static std::string toString ( AutomatonEnum::Settings settings ) { + switch ( settings ) { + case AutomatonEnum::Settings::STATES: + return "states"; + + case AutomatonEnum::Settings::FINAL_STATES: + return "final_states"; + + case AutomatonEnum::Settings::INITIAL_STATES: + return "initial_states"; + + case AutomatonEnum::Settings::INPUT_ALPHABET: + return "input_alphabet"; + + case AutomatonEnum::Settings::TRANSITIONS: + return "transitions"; + + case AutomatonEnum::Settings::EPSILON_TRANSITIONS: + return "epsilon_transitions"; + + case AutomatonEnum::Settings::READING_TRANSITIONS: + return "reading_transitions"; + + case AutomatonEnum::Settings::__MAX__: + throw exception::CommonException ( "Invalid enumeration" ); + } + throw exception::CommonException ( "Invalid enumeration" ); + } + +}; + +class AutomatonSettings : public AutomatonEnum, public EnumClassHelper < AutomatonEnum > { +}; + +#endif /* __AUTOMATA_SETTINGS_H__ */ diff --git a/aaccess2/src/settings/GrammarSettings.h b/aaccess2/src/settings/GrammarSettings.h new file mode 100644 index 0000000000000000000000000000000000000000..fb4735adcc022c34027932e217c29ee2ed3f2c4f --- /dev/null +++ b/aaccess2/src/settings/GrammarSettings.h @@ -0,0 +1,44 @@ +/* + * GrammarSettings.h + * + * Created on: 26. 3. 2014 + * Author: Jan Travnicek + */ + +#ifndef __GRAMMAR_SETTINGS_H__ +#define __GRAMMAR_SETTINGS_H__ + +#include "SettingsHelper.h" + +class GrammarEnum { +public: + enum class Settings { + NONTERMINALS, TERMINALS, INITIAL_SYMBOLS, RULES, __MAX__ + }; + + static std::string toString ( GrammarEnum::Settings settings ) { + switch ( settings ) { + case GrammarEnum::Settings::NONTERMINALS: + return "nonterminals"; + + case GrammarEnum::Settings::TERMINALS: + return "terminals"; + + case GrammarEnum::Settings::INITIAL_SYMBOLS: + return "initial_symbols"; + + case GrammarEnum::Settings::RULES: + return "rules"; + + case GrammarEnum::Settings::__MAX__: + throw exception::CommonException ( "Invalid enumeration" ); + } + throw exception::CommonException ( "Invalid enumeration" ); + } + +}; + +class GrammarSettings : public GrammarEnum, public EnumClassHelper < GrammarEnum > { +}; + +#endif /* __GRAMMAR_SETTINGS_H__ */ diff --git a/aaccess2/src/settings/RegExpSettings.h b/aaccess2/src/settings/RegExpSettings.h new file mode 100644 index 0000000000000000000000000000000000000000..232f16bd7e39146dfe60584bb0491fc665c740d0 --- /dev/null +++ b/aaccess2/src/settings/RegExpSettings.h @@ -0,0 +1,38 @@ +/* + * RegExpSettings.h + * + * Created on: 26. 3. 2014 + * Author: Jan Travnicek + */ + +#ifndef __REG_EXP_SETTINGS_H__ +#define __REG_EXP_SETTINGS_H__ + +#include "SettingsHelper.h" + +class RegExpEnum { +public: + enum class Settings { + ALPHABET, CONTENT, __MAX__ + }; + + static std::string toString ( RegExpEnum::Settings settings ) { + switch ( settings ) { + case RegExpEnum::Settings::ALPHABET: + return "alphabet"; + + case RegExpEnum::Settings::CONTENT: + return "content"; + + case RegExpEnum::Settings::__MAX__: + throw exception::CommonException ( "Invalid enumeration" ); + } + throw exception::CommonException ( "Invalid enumeration" ); + } + +}; + +class RegExpSettings : public RegExpEnum, public EnumClassHelper < RegExpEnum > { +}; + +#endif /* __REG_EXP_SETTINGS_H__ */ diff --git a/aaccess2/src/settings/SettingsHelper.h b/aaccess2/src/settings/SettingsHelper.h new file mode 100644 index 0000000000000000000000000000000000000000..7c491b66cde90148406611ae501bd43f16e4d7ea --- /dev/null +++ b/aaccess2/src/settings/SettingsHelper.h @@ -0,0 +1,79 @@ +/* + * SettingsHelper.h + * + * Created on: 26. 3. 2014 + * Author: Jan Travnicek + */ + +#ifndef __SETTINGS_HELPER_H__ +#define __SETTINGS_HELPER_H__ + +#include <string> +#include <map> +#include <vector> +#include <exception/CommonException.h> + +template < class EnumClass > +class EnumClassHelper { + static const std::vector < typename EnumClass::Settings > & vectorInit ( ) { + static std::vector < typename EnumClass::Settings > res; + + for ( int i = 0; i < static_cast < int > ( EnumClass::Settings::__MAX__ ); i++ ) + res.push_back ( static_cast < typename EnumClass::Settings > ( i ) ); + + return res; + } + +public: + static const std::vector < typename EnumClass::Settings > & settingsVector ( ) { + static std::vector < typename EnumClass::Settings > res = vectorInit ( ); + + return res; + } + +private: + static const std::map < std::string, typename EnumClass::Settings > & mapInit ( ) { + static std::map < std::string, typename EnumClass::Settings > res; + + for ( typename EnumClass::Settings setting : settingsVector ( ) ) + res.insert ( std::make_pair ( EnumClass::toString ( setting ), setting ) ); + + return res; + } + + static const std::vector < std::string > & stringsInit ( ) { + static std::vector < std::string > res; + + for ( typename EnumClass::Settings setting : settingsVector ( ) ) + res.push_back ( EnumClass::toString ( setting ) ); + + return res; + } + +public: + static const std::map < std::string, typename EnumClass::Settings > & settingsMap ( ) { + static std::map < std::string, typename EnumClass::Settings > res = mapInit ( ); + + return res; + } + + static const std::vector < std::string > & stringsVector ( ) { + static const std::vector < std::string > & res = stringsInit ( ); + + return res; + } + + static typename EnumClass::Settings fromString ( const std::string & str ) { + const std::map < std::string, typename EnumClass::Settings > & mapping = settingsMap ( ); + + typename std::map < std::string, typename EnumClass::Settings >::const_iterator iter = mapping.find ( str ); + + if ( iter == mapping.end ( ) ) + throw exception::CommonException ( "Enumeration element not found" ); + + return iter->second; + } + +}; + +#endif /* __SETTINGS_HELPER_H__ */ diff --git a/aaccess2/src/settings/StringSettings.h b/aaccess2/src/settings/StringSettings.h new file mode 100644 index 0000000000000000000000000000000000000000..08004e142e104f9369b60b947d7653e701969ae7 --- /dev/null +++ b/aaccess2/src/settings/StringSettings.h @@ -0,0 +1,38 @@ +/* + * StringSettings.h + * + * Created on: 26. 3. 2014 + * Author: Jan Travnicek + */ + +#ifndef __STRING_SETTINGS_H__ +#define __STRING_SETTINGS_H__ + +#include "SettingsHelper.h" + +class StringEnum { +public: + enum class Settings { + ALPHABET, CONTENT, __MAX__ + }; + + static std::string toString ( StringEnum::Settings settings ) { + switch ( settings ) { + case StringEnum::Settings::ALPHABET: + return "alphabet"; + + case StringEnum::Settings::CONTENT: + return "content"; + + case StringEnum::Settings::__MAX__: + throw exception::CommonException ( "Invalid enumeration" ); + } + throw exception::CommonException ( "Invalid enumeration" ); + } + +}; + +class StringSettings : public StringEnum, public EnumClassHelper < StringEnum > { +}; + +#endif /* __STRING_SETTINGS_H__ */ diff --git a/aaccess2/src/settings/TreeSettings.h b/aaccess2/src/settings/TreeSettings.h new file mode 100644 index 0000000000000000000000000000000000000000..3b99e57396940065a5c57bf0cf2a6982c8df3b30 --- /dev/null +++ b/aaccess2/src/settings/TreeSettings.h @@ -0,0 +1,44 @@ +/* + * TreeSettings.h + * + * Created on: 26. 3. 2014 + * Author: Jan Travnicek + */ + +#ifndef __TREE_SETTINGS_H__ +#define __TREE_SETTINGS_H__ + +#include "SettingsHelper.h" + +class TreeEnum { +public: + enum class Settings { + ALPHABET, CONTENT, SUBTREE_WILDCARD, NONLINEAR_VARIABLES, __MAX__ + }; + + static std::string toString ( TreeEnum::Settings settings ) { + switch ( settings ) { + case TreeEnum::Settings::ALPHABET: + return "alphabet"; + + case TreeEnum::Settings::CONTENT: + return "content"; + + case TreeEnum::Settings::SUBTREE_WILDCARD: + return "subtree_wildcard"; + + case TreeEnum::Settings::NONLINEAR_VARIABLES: + return "nonlinear_variables"; + + case TreeEnum::Settings::__MAX__: + throw exception::CommonException ( "Invalid enumeration" ); + } + throw exception::CommonException ( "Invalid enumeration" ); + } + +}; + +class TreeSettings : public TreeEnum, public EnumClassHelper < TreeEnum > { +}; + +#endif /* __TREE_SETTINGS_H__ */ diff --git a/makefile b/makefile index 987a81e5559b2929dd105902203c126032f329d6..7be3e99c1c56c672e08040df9e3451d50b4c15be 100644 --- a/makefile +++ b/makefile @@ -46,6 +46,7 @@ SUBDIRS_BINS = aecho2 \ areverse2 \ arun2 \ astat2 \ + aaccess2 \ astringology2 \ atrim2 \ tniceprint \