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

take out result interpretation for cli from environment

parent 8f78bcae
No related branches found
No related tags found
1 merge request!117Merge jt
#ifndef _CLI_RESULT_INTERPRET_H_
#define _CLI_RESULT_INTERPRET_H_
#include <memory>
namespace cli {
class ResultInterpret {
public:
static int cli ( std::shared_ptr < abstraction::Value > result ) {
if ( result ) {
std::shared_ptr < abstraction::ValueHolderInterface < int > > ptr1 = std::dynamic_pointer_cast < abstraction::ValueHolderInterface < int > > ( result );
if ( ptr1 )
return ptr1->getValue ( );
std::shared_ptr < abstraction::ValueHolderInterface < unsigned > > ptr2 = std::dynamic_pointer_cast < abstraction::ValueHolderInterface < unsigned > > ( result );
if ( ptr2 )
return ptr2->getValue ( );
std::shared_ptr < abstraction::ValueHolderInterface < bool > > ptr3 = std::dynamic_pointer_cast < abstraction::ValueHolderInterface < bool > > ( result );
if ( ptr3 )
return static_cast < int > ( ! ptr3->getValue ( ) );
throw exception::CommonException ( "Invalid result type. Provided: " + result->getType ( ) );
} else {
return 0;
}
}
};
} /* namespace cli */
#endif /* _CLI_RESULT_INTERPRET_H_ */
......@@ -111,22 +111,8 @@ public:
m_result = std::move ( value );
}
 
int getResult ( ) const {
if ( m_result ) {
std::shared_ptr < abstraction::ValueHolderInterface < int > > ptr1 = std::dynamic_pointer_cast < abstraction::ValueHolderInterface < int > > ( m_result );
if ( ptr1 )
return ptr1->getValue ( );
std::shared_ptr < abstraction::ValueHolderInterface < unsigned > > ptr2 = std::dynamic_pointer_cast < abstraction::ValueHolderInterface < unsigned > > ( m_result );
if ( ptr2 )
return ptr2->getValue ( );
std::shared_ptr < abstraction::ValueHolderInterface < bool > > ptr3 = std::dynamic_pointer_cast < abstraction::ValueHolderInterface < bool > > ( m_result );
if ( ptr3 )
return static_cast < int > ( ! ptr3->getValue ( ) );
throw exception::CommonException ( "Invalid result type. Provided: " + m_result->getType ( ) );
} else {
return 0;
}
std::shared_ptr < abstraction::Value > getResult ( ) const {
return m_result;
}
 
cli::CommandResult execute ( std::shared_ptr < cli::LineInterface > lineInterface );
......
......@@ -14,6 +14,8 @@
 
#include <readline/StringLineInterface.h>
 
#include <common/ResultInterpret.h>
#define PIPE_RD 0
#define PIPE_WR 1
 
......@@ -69,7 +71,7 @@ int aqlTest ( int fd, const ext::vector < std::string > & queries, unsigned seed
throw std::runtime_error ( "TimeoutAqlTest: child output write() failure (child to parent communication)" );
}
 
return environment.getResult ( ); /* 0 = OK */
return cli::ResultInterpret::cli ( environment.getResult ( ) ); /* 0 = OK */
} catch ( const std::exception & ) {
std::ostringstream oss;
alib::ExceptionHandler::handle ( oss );
......
......@@ -45,6 +45,8 @@ std::istream& operator>> ( std::istream & in, std::pair < T, U > & value ) {
 
#include <prompt/ReadlinePromptHistory.h>
 
#include <common/ResultInterpret.h>
namespace TCLAP {
 
template < class T, class U >
......@@ -161,7 +163,7 @@ int main ( int argc, char * argv[] ) {
/* --------------------------------------------------------------------------------------------------------- */
 
if ( res == cli::CommandResult::QUIT )
return Prompt::getPrompt ( ).getEnvironment ( ).getResult ( );
return cli::ResultInterpret::cli ( Prompt::getPrompt ( ).getEnvironment ( ).getResult ( ) );
else if ( res == cli::CommandResult::EOT )
return 0;
else
......
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