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

drop exception to xml parsing and composing

parent 977a0f13
No related branches found
No related tags found
No related merge requests found
Pipeline #31699 passed
......@@ -37,10 +37,6 @@ CommonException::CommonException ( std::string cause, std::string backtrace, std
this->m_whatMessage += this->m_cause;
}
 
int CommonException::compare(const CommonException& other) const {
return this->m_whatMessage.compare(other.m_whatMessage);
}
const char * CommonException::what ( ) const noexcept {
return m_whatMessage.c_str ( );
}
......
......@@ -12,7 +12,6 @@
#include <ostream>
 
#include <alib/string>
#include <alib/compare>
 
namespace exception {
 
......@@ -22,7 +21,7 @@ namespace exception {
*
* Extends standard exception and additionally contains cause, backtrace (if conputed), and copy of command line string used to execute the program.
*/
class CommonException : public std::exception, public ext::CompareOperators < CommonException > {
class CommonException : public std::exception {
protected:
/**
* \brief
......@@ -61,15 +60,6 @@ public:
*/
explicit CommonException ( std::string cause, std::string backtrace, std::string command );
 
/**
* The actual compare method
*
* \param other the other instance
*
* \returns the actual relation between two by type same expression instances
*/
int compare ( const CommonException & other ) const;
/**
* \return reason why the exception occurred
*/
......
......@@ -26,13 +26,6 @@ public:
}
};
 
template < >
inline bool XmlParserAbstraction < exception::CommonException >::run ( ) {
std::pair < std::shared_ptr < OperationAbstraction >, bool > & param = std::get < 0 > ( this->m_params );
exception::CommonException ex = factory::XmlDataFactory::fromTokens ( abstraction::retrieveValue < ext::deque < sax::Token > && > ( param.first, param.second ) );
throw ex;
}
} /* namespace abstraction */
 
#endif /* _XML_PARSER_ABSTRACTION_HPP_ */
/*
* CommonException.cpp
*
* Created on: Apr 1, 2013
* Author: Martin Zak
*/
#include "CommonException.h"
#include <object/Object.h>
#include <registration/XmlRegistration.hpp>
namespace core {
exception::CommonException xmlApi < exception::CommonException >::parse ( ext::deque < sax::Token >::iterator & input ) {
sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::START_ELEMENT, xmlTagName());
sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::START_ELEMENT, "cause");
std::string cause = "";
if (input->getType() == sax::Token::TokenType::CHARACTER) {
cause = std::move(*input).moveData();
++input;
}
sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::END_ELEMENT, "cause");
sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::START_ELEMENT, "backtrace");
std::string backtrace = "";
if (input->getType() == sax::Token::TokenType::CHARACTER) {
backtrace = std::move(*input).moveData();
++input;
}
sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::END_ELEMENT, "backtrace");
sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::START_ELEMENT, "command");
std::string command = "";
if (input->getType() == sax::Token::TokenType::CHARACTER) {
command = std::move(*input).moveData();
++input;
}
sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::END_ELEMENT, "command");
sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::END_ELEMENT, xmlTagName());
return exception::CommonException(std::move(cause), std::move(backtrace), std::move(command));
}
bool xmlApi < exception::CommonException >::first ( const ext::deque < sax::Token >::const_iterator & input ) {
return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) );
}
std::string xmlApi < exception::CommonException >::xmlTagName ( ) {
return "CommonException";
}
void xmlApi < exception::CommonException >::compose ( ext::deque < sax::Token > & output, const exception::CommonException & data ) {
output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::START_ELEMENT );
output.emplace_back ( "cause", sax::Token::TokenType::START_ELEMENT );
output.emplace_back ( data.getCause ( ), sax::Token::TokenType::CHARACTER );
output.emplace_back ( "cause", sax::Token::TokenType::END_ELEMENT );
output.emplace_back ( "backtrace", sax::Token::TokenType::START_ELEMENT );
output.emplace_back ( data.getBacktrace ( ), sax::Token::TokenType::CHARACTER );
output.emplace_back ( "backtrace", sax::Token::TokenType::END_ELEMENT );
output.emplace_back ( "command", sax::Token::TokenType::START_ELEMENT );
output.emplace_back ( data.getCommand ( ), sax::Token::TokenType::CHARACTER );
output.emplace_back ( "command", sax::Token::TokenType::END_ELEMENT );
output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::END_ELEMENT );
}
} /* namespace core */
namespace {
static auto xmlWrite = registration::XmlWriterRegister < exception::CommonException > ( );
static auto xmlRead = registration::XmlReaderRegister < exception::CommonException > ( );
static auto xmlGroup = registration::XmlRegisterTypeInGroup < object::Object, exception::CommonException > ( );
} /* namespace */
/*
* CommonException.h
*
* Created on: Apr 1, 2013
* Author: Martin Zak
*/
#ifndef _XML_COMMON_EXCEPTION_H_
#define _XML_COMMON_EXCEPTION_H_
#include <exception/CommonException.h>
#include <alib/string>
#include <core/xmlApi.hpp>
namespace core {
template < >
struct xmlApi < exception::CommonException > {
static exception::CommonException parse ( ext::deque < sax::Token >::iterator & input );
static bool first ( const ext::deque < sax::Token >::const_iterator & input );
static std::string xmlTagName ( );
static void compose ( ext::deque < sax::Token > & output, const exception::CommonException & data );
};
} /* namespace core */
#endif /* XML_COMMON_EXCEPTION_H_ */
......@@ -16,7 +16,6 @@
#include <sax/SaxParseInterface.h>
#include <sax/SaxComposeInterface.h>
#include <core/xmlApi.hpp>
#include <exception/xml/CommonException.h>
#include <measure/xml/MeasurementResults.hpp>
 
namespace factory {
......@@ -111,8 +110,6 @@ public:
 
if ( context == tokens.end ( ) ) throw exception::CommonException ( "Empty tokens list" );
 
if ( core::xmlApi < exception::CommonException >::first ( context ) ) throw core::xmlApi < exception::CommonException >::parse ( context );
measurements::start ( "XML Parser", measurements::Type::INIT );
T res = core::xmlApi < T >::parse ( context );
measurements::end ( );
......@@ -132,7 +129,7 @@ public:
static bool first ( const ext::deque < sax::Token > & tokens ) {
if( tokens.empty ( ) ) throw exception::CommonException ( "Empty tokens list" );
 
return core::xmlApi < exception::CommonException >::first ( tokens.begin ( ) ) || core::xmlApi < T >::first ( tokens.begin ( ) );
return core::xmlApi < T >::first ( tokens.begin ( ) );
}
 
/**
......@@ -195,32 +192,12 @@ public:
 
};
 
template < >
inline bool XmlDataFactory::first < exception::CommonException > ( const ext::deque < sax::Token > & tokens ) {
return core::xmlApi < exception::CommonException >::first ( tokens.begin ( ) );
}
template < >
inline XmlDataFactory::fromTokens::operator exception::CommonException ( ) {
core::xmlApiInputContext context ( tokens.begin ( ) );
if ( context == tokens.end ( ) ) throw exception::CommonException ( "Empty tokens list" );
exception::CommonException res = core::xmlApi < exception::CommonException >::parse ( context );
if ( context != tokens.end ( ) ) throw exception::CommonException ( "Unexpeted tokens at the end of the xml" );
return res;
}
template < >
inline XmlDataFactory::fromTokens::operator measurements::MeasurementResults ( ) {
core::xmlApiInputContext context ( tokens.begin ( ) );
 
if ( context == tokens.end ( ) ) throw exception::CommonException ( "Empty tokens list" );
 
if ( core::xmlApi < exception::CommonException >::first ( context ) ) throw core::xmlApi < exception::CommonException >::parse ( context );
measurements::MeasurementResults res = core::xmlApi < measurements::MeasurementResults >::parse ( context );
 
if ( context != tokens.end ( ) ) throw exception::CommonException ( "Unexpeted tokens at the end of the xml" );
......
......@@ -36,8 +36,6 @@ std::istream& operator>> ( std::istream & in, std::pair < T, U > & value ) {
 
#include "prompt/Prompt.h"
 
#include <factory/XmlDataFactory.hpp>
namespace TCLAP {
 
template < class T, class U >
......@@ -109,9 +107,6 @@ int main ( int argc, char * argv[] ) {
return p.getEnvironment ( ).getResult ( );
else
return 4;
} catch ( const exception::CommonException & exception ) {
factory::XmlDataFactory::toStdout ( exception );
return 1;
} catch ( const TCLAP::ArgException & exception ) {
common::Streams::out << exception.error ( ) << std::endl;
return 2;
......
......@@ -13,7 +13,6 @@
#include <lexer/Lexer.h>
#include <parser/Parser.h>
 
#include <factory/XmlDataFactory.hpp>
#include <global/GlobalData.h>
 
#include "HistoryRegister.h"
......@@ -46,9 +45,6 @@ public:
cli::Parser parser = cli::Parser ( cli::Lexer ( std::forward < T && > ( charSequence ) ) );
HistoryRegister historyRegister ( parser.getLexer ( ), allowHistory );
return parser.parse ( )->run ( m_environment );
} catch ( const exception::CommonException & exception ) {
factory::XmlDataFactory::toStdout ( exception );
return cli::Command::Result::EXCEPTION;
} catch ( const std::exception & exception ) {
common::Streams::err << "Exception caught: " << exception.what ( ) << std::endl;
return cli::Command::Result::EXCEPTION;
......
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