Skip to content
Snippets Groups Projects
Commit 0f4f4f97 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

Cast PrefixRankedNotation to string

parent 69290752
No related branches found
No related tags found
No related merge requests found
......@@ -7,7 +7,7 @@
 
#include <exception/AlibException.h>
#include <factory/XmlDataFactory.hpp>
#include <cxxabi.h>
#include <type_traits>
 
template<typename T, typename R, typename std::enable_if< std::is_constructible<T, R>::value >::type* = nullptr >
T cast(const R& orig) {
......@@ -85,15 +85,7 @@ public:
 
template<typename BaseVisitor, typename Base, typename Types, typename R, typename ... Rs >
void cast_helper<BaseVisitor, Base, Types, R, Rs ...>::do_cast(const std::string& name, const Base& obj) {
int status;
char namespaceId[100];
char classId[100];
char* ret = abi::__cxa_demangle(typeid(R).name(), 0, 0, &status);
sscanf(ret, "%[a-zA-Z]::%[a-zA-Z]", namespaceId, classId);
free( ret );
if(std::string(classId) == name) {
if(std::is_same_type<R>(name.c_str())) {
cast_implementer<BaseVisitor, Base, R, Types>::cast(obj);
} else {
cast_helper<BaseVisitor, Base, Types, Rs ...>::do_cast(name, obj);
......
......@@ -46,7 +46,10 @@ int main(int argc, char** argv) {
/*alib::Object object = alib::XmlDataFactory::fromTokens<alib::Object>(tokens);
CastBaseVisitor::do_cast(type.getValue(), object.getData());*/
 
if(alib::XmlDataFactory::first<automaton::Automaton>(tokens)) {
if(alib::XmlDataFactory::first<tree::PrefixRankedNotation>(tokens) && std::is_same_type<string::LinearString>(type.getValue().c_str())) {
tree::PrefixRankedNotation tree = alib::XmlDataFactory::fromTokens<tree::PrefixRankedNotation>(tokens);
alib::XmlDataFactory::toStdout(string::LinearString(tree));
} else if(alib::XmlDataFactory::first<automaton::Automaton>(tokens)) {
automaton::Automaton automaton = alib::XmlDataFactory::fromTokens<automaton::Automaton>(tokens);
AutomatonCastVisitor::doCast(type.getValue(), automaton);
} else if(alib::XmlDataFactory::first<grammar::Grammar>(tokens)) {
......
......@@ -20,6 +20,15 @@ LinearString::LinearString() {
 
}
 
LinearString::LinearString(const tree::PrefixRankedNotation& tree) {
for(const alphabet::RankedSymbol& symbol : tree.getAlphabet()) {
this->alphabet.insert(alphabet::Symbol(std::move(symbol)));
}
for(const alphabet::RankedSymbol& symbol : tree.getContent()) {
this->m_Data.push_back(alphabet::Symbol(symbol));
}
}
LinearString::LinearString(std::set<alphabet::Symbol> alphabet, std::vector<alphabet::Symbol> data) {
this->alphabet = std::move(alphabet);
setContent(std::move(data));
......
......@@ -16,6 +16,7 @@
#include "StringBase.h"
#include "common/StringAlphabet.h"
#include "Epsilon.h"
#include "../tree/ranked/PrefixRankedNotation.h"
 
namespace string {
 
......@@ -28,6 +29,7 @@ class LinearString : public std::acceptor<LinearString, VisitableStringBase, std
 
public:
explicit LinearString();
explicit LinearString(const tree::PrefixRankedNotation& tree);
explicit LinearString(std::set<alphabet::Symbol> alphabet, std::vector<alphabet::Symbol> data);
explicit LinearString(std::vector<alphabet::Symbol> data);
explicit LinearString(const std::string& string);
......
......@@ -32,6 +32,23 @@ namespace std {
static const bool value = is_base_of<T, F>::value || is_base_of_any<T, Ts...>::value;
};
 
template<typename T>
bool is_same_type(const char* name) {
int status;
char namespaceId[100];
char classId[100];
char* ret = abi::__cxa_demangle(typeid(T).name(), 0, 0, &status);
sscanf(ret, "%[a-zA-Z]::%[a-zA-Z]", namespaceId, classId);
free( ret );
if(strcmp(classId, name) == 0) {
return true;
} else {
return false;
}
}
} /* namespace std */
 
#endif // TYPE_TRAITS_HPP_
......@@ -2,6 +2,10 @@
#define __TYPE_TRAITS_HEADER_WRAPPER_
 
#include <bits/../type_traits>
#include <cxxabi.h>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include "extensions/type_traits.hpp"
 
#endif /* __TYPE_TRAITS_HEADER_WRAPPER_ */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment