diff --git a/acast2/makefile b/acast2/makefile new file mode 100644 index 0000000000000000000000000000000000000000..924ac432c6e7039d6fa03a59cbdae3f49e8f4f83 --- /dev/null +++ b/acast2/makefile @@ -0,0 +1,178 @@ +SHELL:=/bin/bash +EXECUTABLE:=acast2 + +define NEW_LINE + + +endef + +export NEW_LINE + +GCC_LDFLAGS_DEBUG:=-L../alib2std/lib-gcc-debug -L../alib2data/lib-gcc-debug -L../alib2algo/lib-gcc-debug -L../alib2elgo/lib-gcc-debug -rdynamic -lxml2 -lalib2std -lalib2data -lalib2algo -lalib2elgo -Wl,-rpath,. +LLVM_LDFLAGS_DEBUG:=-L../alib2std/lib-llvm-debug -L../alib2data/lib-llvm-debug -L../alib2algo/lib-llvm-debug -L../alib2elgo/lib-llvm-debug -rdynamic -lxml2 -lalib2std -lalib2data -lalib2algo -lalib2elgo -Wl,-rpath,. + +GCC_LDFLAGS_RELEASE:=-L../alib2std/lib-gcc-release -L../alib2data/lib-gcc-release -L../alib2algo/lib-gcc-release -L../alib2elgo/lib-gcc-release -rdynamic -lxml2 -lalib2std -lalib2data -lalib2algo -lalib2elgo -Wl,-rpath,. +LLVM_LDFLAGS_RELEASE:=-L../alib2std/lib-llvm-release -L../alib2data/lib-llvm-release -L../alib2algo/lib-llvm-release -L../alib2elgo/lib-llvm-release -rdynamic -lxml2 -lalib2std -lalib2data -lalib2algo -lalib2elgo -Wl,-rpath,. + +OBJECTS_GCC_DEBUG:=$(patsubst src/%.cpp, obj-gcc-debug/%.o, $(shell find src/ -name *cpp)) +OBJECTS_LLVM_DEBUG:=$(patsubst src/%.cpp, obj-llvm-debug/%.o, $(shell find src/ -name *cpp)) + +OBJECTS_GCC_RELEASE:=$(patsubst src/%.cpp, obj-gcc-release/%.o, $(shell find src/ -name *cpp)) +OBJECTS_LLVM_RELEASE:=$(patsubst src/%.cpp, obj-llvm-release/%.o, $(shell find src/ -name *cpp)) + +.PHONY: all build-gcc-debug build-llvm-debug build-gcc-release build-llvm-release clean-gcc-debug clean-llvm-debug clean-gcc-release clean-llvm-release doc + +all: + @echo "What to do master?" + +obj%/makefile: makefile + mkdir -p $(dir $@) + echo "\ + SHELL:=/bin/bash$${NEW_LINE}\ + CXXX:=$(patsubst obj-%-release/,%,$(patsubst obj-%-debug/,%,$(dir $@)))$${NEW_LINE}\ + ifeq (gcc, \$$(CXXX))$${NEW_LINE}\ + CXX:=g++$${NEW_LINE}\ + else$${NEW_LINE}\ + ifeq (llvm, \$$(CXXX))$${NEW_LINE}\ + CXX:=clang++$${NEW_LINE}\ + else$${NEW_LINE}\ + \$$(error \"invalid compiler\")$${NEW_LINE}\ + endif$${NEW_LINE}\ + endif$${NEW_LINE}\ + SRCDIR:=$${NEW_LINE}\ + DEPTH:=$${NEW_LINE}\ + OBJECTS_BASE_DIR:=$${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:= -std=c++11 \$$(CXX_OTHER_FLAGS) -c -Wall -pedantic -Wextra -Werror -fPIC -I/usr/include/libxml2/ -I../../\$$(DEPTH)alib2std/src -I../../\$$(DEPTH)alib2data/src/ -I../../\$$(DEPTH)alib2algo/src/ -I../../\$$(DEPTH)alib2elgo/src/$${NEW_LINE}\ + $${NEW_LINE}\ + SOURCES:= \$$(shell find ../\$$(DEPTH)\$$(SOURCES_BASE_DIR)/\$$(SRCDIR) -maxdepth 1 -type f -name \"*.cpp\")$${NEW_LINE}\ + DEPENDENCIES:= \$$(patsubst ../\$$(DEPTH)\$$(SOURCES_BASE_DIR)/\$$(SRCDIR)%.cpp, ../\$$(DEPTH)\$$(OBJECTS_BASE_DIR)/\$$(SRCDIR)%.d, \$$(SOURCES))$${NEW_LINE}\ + OBJECTS:= \$$(patsubst %.d, %.o, \$$(DEPENDENCIES))$${NEW_LINE}\ + SOURCES_DIRS:= \$$(shell find ../\$$(DEPTH)\$$(SOURCES_BASE_DIR)/\$$(SRCDIR) -maxdepth 1 -mindepth 1 -type d)$${NEW_LINE}\ + OBJECTS_DIRS:= \$$(patsubst ../\$$(DEPTH)\$$(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 ../\$$(DEPTH)\$$(OBJECTS_BASE_DIR)/\$$(SRCDIR)%.d,../\$$(DEPTH)\$$(SOURCES_BASE_DIR)/\$$(SRCDIR)%.cpp, \$$@) 2>/dev/null || echo \\\"\$$(patsubst ../\$$(DEPTH)\$$(OBJECTS_BASE_DIR)/\$$(SRCDIR)%.d,../\$$(DEPTH)\$$(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 %/, %, \$$@))/ DEPTH=\$$(DEPTH)../ 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)" > $@ + +gcc-debug: build-gcc-debug + +llvm-debug: build-llvm-debug + +gcc-release: build-gcc-release + +llvm-release: build-llvm-release + +clean: clean-gcc-debug clean-gcc-release + $(RM) -r doc + +clean: clean-llvm-debug clean-llvm-release + $(RM) -r doc + + + +bin-gcc-debug/$(EXECUTABLE): obj-gcc-debug/ $(OBJECTS_GCC_DEBUG) + mkdir -p $(dir $@) + g++ $(OBJECTS_GCC_DEBUG) -o $@ $(GCC_LDFLAGS_DEBUG) + +bin-llvm-debug/$(EXECUTABLE): obj-llvm-debug/ $(OBJECTS_LLVM_DEBUG) + mkdir -p $(dir $@) + clang++ $(OBJECTS_LLVM_DEBUG) -o $@ $(LLVM_LDFLAGS_DEBUG) + +bin-gcc-release/$(EXECUTABLE): obj-gcc-release/ $(OBJECTS_GCC_RELEASE) + mkdir -p $(dir $@) + g++ $(OBJECTS_GCC_RELEASE) -o $@ $(GCC_LDFLAGS_RELEASE) + +bin-llvm-release/$(EXECUTABLE): obj-llvm-release/ $(OBJECTS_LLVM_RELEASE) + mkdir -p $(dir $@) + g++ $(OBJECTS_LLVM_RELEASE) -o $@ $(LLVM_LDFLAGS_RELEASE) + + + +obj-gcc-debug/: FORCE | obj-gcc-debug/makefile + $(MAKE) -C $@ OBJECTS_BASE_DIR=obj-gcc-debug SOURCES_BASE_DIR=src CXX_OTHER_FLAGS="-g -O0" + +obj-llvm-debug/: FORCE | obj-llvm-debug/makefile + $(MAKE) -C $@ OBJECTS_BASE_DIR=obj-llvm-debug SOURCES_BASE_DIR=src CXX_OTHER_FLAGS="-g -O0" + +obj-gcc-release/: FORCE | obj-gcc-release/makefile + $(MAKE) -C $@ OBJECTS_BASE_DIR=obj-gcc-release SOURCES_BASE_DIR=src CXX_OTHER_FLAGS="-O3" + +obj-llvm-release/: FORCE | obj-llvm-release/makefile + $(MAKE) -C $@ OBJECTS_BASE_DIR=obj-llvm-release SOURCES_BASE_DIR=src CXX_OTHER_FLAGS="-O3" + + + +$(OBJECTS_GCC_DEBUG): obj-gcc-debug/ + +$(OBJECTS_LLVM_DEBUG): obj-llvm-debug/ + +$(OBJECTS_GCC_RELEASE): obj-gcc-release/ + +$(OBJECTS_LLVM_RELEASE): obj-llvm-release/ + + + +build-gcc-debug: bin-gcc-debug/$(EXECUTABLE) + +build-llvm-debug: bin-llvm-debug/$(EXECUTABLE) + +build-gcc-release: bin-gcc-release/$(EXECUTABLE) + +build-llvm-release: bin-llvm-release/$(EXECUTABLE) + + + +clean-gcc-debug: + $(RM) -r *.o *.d bin-gcc-debug obj-gcc-debug + +clean-llvm-debug: + $(RM) -r *.o *.d bin-llvm-debug obj-llvm-debug + +clean-gcc-release: + $(RM) -r *.o *.d bin-gcc-release obj-gcc-release + +clean-llvm-release: + $(RM) -r *.o *.d bin-llvm-release obj-llvm-release + + + +FORCE: + + + +doc: + doxygen + diff --git a/acast2/src/acast.cpp b/acast2/src/acast.cpp new file mode 100644 index 0000000000000000000000000000000000000000..564d14df22229921c2346b278b02ee2b062c043e --- /dev/null +++ b/acast2/src/acast.cpp @@ -0,0 +1,154 @@ +/* + * acast.cpp + * + * Created on: 24. 2. 2014 + * Author: Jan Travnicek + */ + +#include <tclap/CmdLine.h> +#include <string> +#include <exception/AlibException.h> +#include <factory/XmlDataFactory.hpp> +#include <sax/SaxParseInterface.h> +#include <sax/ParserException.h> +#include <object/Object.h> + +template<typename T, typename R, typename std::enable_if< std::is_constructible<T, R>::value >::type* = nullptr > +T cast(const R& orig) { + return T(orig); +} + +template<typename T, typename R, typename std::enable_if< ! std::is_constructible<T, R>::value >::type* = nullptr > +T cast(const R& /* orig */) { + throw exception::AlibException(std::string("Invalid cast from ") + typeid(R).name() + " to " + typeid(T).name()); +} + +// -------------------------------------------------------------------------------------------------------------- + +template<typename R, typename ... Types> +class cast_implementer_helper; + +template<typename R> +class cast_implementer_helper< R > : public alib::VisitableObjectBase::const_visitor_type { + +}; + +template<typename R, typename T, typename ... Types> +class cast_implementer_helper<R, T, Types ...> : public cast_implementer_helper<R, Types ...> { +public: + #ifdef __clang__ + using cast_implementer_helper<R, Types ...>::Visit; + #endif + void Visit(void*, const T& orig) const; +}; + +template<typename R, typename T, typename ... Types> +void cast_implementer_helper<R, T, Types ...>::Visit(void*, const T& orig) const { + alib::XmlDataFactory::toStdout(cast<R, T>(orig)); +} + +// -------------------------------------------------------------------------------------------------------------------- + +template<typename R, typename Types> +class cast_implementer { +}; + +template<typename R, typename ... Ts> +class cast_implementer< R, std::tuple< Ts ...> > : public cast_implementer_helper< R, Ts ... > { +public: + using cast_implementer_helper<R, Ts ... >::Visit; + + static void cast(const alib::ObjectBase& obj); +}; + +template<typename R, typename ... Ts> +void cast_implementer<R, std::tuple< Ts ... > >::cast(const alib::ObjectBase& obj) { + cast_implementer<R, std::tuple< Ts ... > > tmp; + obj.Accept(NULL, tmp); +} + +// ---------------------------------------------------------------------------------------- + +template<typename ... Rs> +class cast_helper; + +template<> +class cast_helper<> { +public: + static void do_cast(const std::string&, const alib::ObjectBase&/* obj*/) { + throw exception::AlibException("invalid type specified"); + } +}; + +template<typename R, typename ... Rs > +class cast_helper< R, Rs ... > : public cast_helper< Rs ...> { +public: + static void do_cast(const std::string& name, const alib::ObjectBase& obj); +}; + +template<typename R, typename ... Rs > +void cast_helper<R, Rs ...>::do_cast(const std::string& name, const alib::ObjectBase& obj) { + if(std::string(typeid(R).name()).find(name) != std::string::npos) { + cast_implementer<R, alib::Types>::cast(obj); + } else { + cast_helper<Rs ...>::do_cast(name, obj); + } +} + +// ----------------------------------------------------------------------------------------- + +template<typename Types> +class cast_base_helper { +}; + +template<typename ... Ts> +class cast_base_helper< std::tuple< Ts ... > > : public cast_helper< Ts ... > { +public: + +}; + +typedef cast_base_helper< alib::Types > CastBase; + +// ----------------------------------------------------------------------------------------- + +int main(int argc, char** argv) { + try { + TCLAP::CmdLine cmd("cast binary", ' ', "0.01"); + + TCLAP::ValueArg<std::string> input( "i", "input", "Input to echo", false, "-", "file"); + cmd.add( input ); + + TCLAP::ValueArg<std::string> type( "t", "type", "Output type", true, "", "string"); + cmd.add( type ); + + cmd.parse(argc, argv); + + std::deque<sax::Token> tokens; + if(input.isSet()) { + if(input.getValue() == "-") { + sax::SaxParseInterface::parseStdin(tokens); + } else { + sax::SaxParseInterface::parseFile(input.getValue(), tokens); + } + } else { + sax::SaxParseInterface::parseStdin(tokens); + } + + alib::Object object = alib::XmlDataFactory::fromTokens<alib::Object>(tokens); + CastBase::do_cast(type.getValue(), object.getData()); + + return 0; + } catch(const exception::AlibException& exception) { + alib::XmlDataFactory::toStdout(exception); + return 1; + } catch(const TCLAP::ArgException& exception) { + std::cerr << 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/aecho2/src/aecho.cpp b/aecho2/src/aecho.cpp index 8232766a714f9d095bc71e083a2c4c764dc70354..d9be4c83e7fca9d732c4422d8ad861ece7c219e7 100644 --- a/aecho2/src/aecho.cpp +++ b/aecho2/src/aecho.cpp @@ -15,7 +15,7 @@ int main(int argc, char** argv) { try { - TCLAP::CmdLine cmd("Cat binary", ' ', "0.01"); + TCLAP::CmdLine cmd("echo binary", ' ', "0.01"); TCLAP::ValueArg<std::string> input( "i", "input", "Input to echo", false, "-", "file"); cmd.add( input ); diff --git a/makefile b/makefile index c16f5a982bb896ac32b3f9fc37325e251c9c3b3f..a92cabb449dec3894c43802af7f71ce6f3adceb2 100644 --- a/makefile +++ b/makefile @@ -9,6 +9,7 @@ ALGO_LIB = alib2algo ELGO_LIB = alib2elgo SUBDIRS_BINS = aecho2 \ aarbology2 \ + acast2 \ aconversions2 \ aconvert2 \ acompaction2 \