From 726b0d09575cdeb491e814d4f2f3231bd49df462 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Kvalsvik?= Date: Tue, 24 May 2016 12:40:40 +0200 Subject: [PATCH] Implement InputStack with std::stack Save some implementation by using std::stack as interface and implementation for InputStack. Remove the vector pair of file and file* and just use file directly. --- opm/parser/eclipse/Parser/Parser.cpp | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/opm/parser/eclipse/Parser/Parser.cpp b/opm/parser/eclipse/Parser/Parser.cpp index 8818fac3c..800a275cb 100644 --- a/opm/parser/eclipse/Parser/Parser.cpp +++ b/opm/parser/eclipse/Parser/Parser.cpp @@ -178,24 +178,18 @@ struct file { boost::filesystem::path path; }; -class InputStack { +class InputStack : public std::stack< file, std::vector< file > > { public: - bool empty() const { return this->file_stack.empty(); } - file& peek() { return *this->file_stack.back(); } - const file& peek() const { return *this->file_stack.back(); } - void pop() { this->file_stack.pop_back(); }; void push( std::string&& input, boost::filesystem::path p = "" ); private: std::list< std::string > string_storage; - std::list< file > file_storage; - std::vector< file* > file_stack; + using base = std::stack< file, std::vector< file > >; }; void InputStack::push( std::string&& input, boost::filesystem::path p ) { this->string_storage.push_back( std::move( input ) ); - this->file_storage.emplace_back( p, this->string_storage.back() ); - this->file_stack.push_back( &this->file_storage.back() ); + this->emplace( p, this->string_storage.back() ); } class ParserState { @@ -233,17 +227,17 @@ class ParserState { const boost::filesystem::path& ParserState::current_path() const { - return this->input_stack.peek().path; + return this->input_stack.top().path; } size_t ParserState::line() const { - return this->input_stack.peek().lineNR; + return this->input_stack.top().lineNR; } bool ParserState::done() const { while( !this->input_stack.empty() && - this->input_stack.peek().input.empty() ) + this->input_stack.top().input.empty() ) const_cast< ParserState* >( this )->input_stack.pop(); return this->input_stack.empty(); @@ -252,8 +246,8 @@ bool ParserState::done() const { string_view ParserState::getline() { string_view line; - Opm::getline( this->input_stack.peek().input, line ); - this->input_stack.peek().lineNR++; + Opm::getline( this->input_stack.top().input, line ); + this->input_stack.top().lineNR++; return line; }