Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
InterpretCommand.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <ast/Command.h>
10
12#include <fstream>
13
14namespace cli {
15
16class InterpretCommand : public Command {
17 std::string m_fileName;
18
19public:
20 InterpretCommand ( std::string libraryName ) : m_fileName ( std::move ( libraryName ) ) {
21 }
22
23 CommandResult run ( Environment & environment ) const override {
24 std::ifstream ifs ( m_fileName );
25
26 if ( ! ifs.is_open ( ) )
27 throw exception::CommonException ( "File '" + m_fileName + "' not found." );
28
29 CommandResult state = environment.execute ( std::make_shared < cli::IstreamLineInterface < std::ifstream > > ( cli::IstreamLineInterface < std::ifstream > ( std::move ( ifs ) ) ) );
30
33
34 return state;
35 }
36};
37
38} /* namespace cli */
39
Definition: Command.h:14
Definition: Environment.h:29
cli::CommandResult execute(const std::shared_ptr< cli::LineInterface > &lineInterface)
Definition: Environment.cpp:49
Definition: InterpretCommand.h:16
InterpretCommand(std::string libraryName)
Definition: InterpretCommand.h:20
CommandResult run(Environment &environment) const override
Definition: InterpretCommand.h:23
Definition: IstreamLineInterface.h:20
Basic exception from which all other exceptions are derived.
Definition: CommonException.h:21
Definition: Arg.h:11
CommandResult
Definition: CommandResult.h:10
Definition: FordFulkerson.hpp:16