Merge pull request #2479 from joakim-hove/actionx-output-sep

Actionx output sep
This commit is contained in:
Joakim Hove 2021-05-19 16:51:29 +02:00 committed by GitHub
commit cb5e4eff2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 16 deletions

View File

@ -28,6 +28,13 @@ namespace Opm {
class DeckOutput {
public:
struct format {
std::string item_sep = " "; // Separator between items on a row.
size_t columns = 16; // The maximum number of columns on a record.
std::string record_indent = " "; // The indentation when starting a new line.
std::string keyword_sep = "\n\n"; // The separation between keywords;
};
explicit DeckOutput(std::ostream& s, int precision = 10);
~DeckOutput();
void stash_default( );
@ -41,11 +48,7 @@ namespace Opm {
void endl();
void write_string(const std::string& s);
template <typename T> void write(const T& value);
std::string item_sep = " "; // Separator between items on a row.
size_t columns = 16; // The maximum number of columns on a record.
std::string record_indent = " "; // The indentation when starting a new line.
std::string keyword_sep = "\n\n"; // The separation between keywords;
format fmt;
private:
std::ostream& os;
size_t default_count;

View File

@ -289,7 +289,7 @@ namespace Opm {
keyword.write( output );
kw_index++;
if (kw_index < size())
output.write_string( output.keyword_sep );
output.write_string( output.fmt.keyword_sep );
}
}

View File

@ -120,14 +120,14 @@ namespace Opm {
void DeckOutput::write_sep( ) {
if (record_on && this->split_line) {
if ((row_count > 0) && ((row_count % columns) == 0))
if ((row_count > 0) && ((row_count % this->fmt.columns) == 0))
split_record();
}
if (row_count > 0)
os << item_sep;
os << this->fmt.item_sep;
else if (record_on)
os << record_indent;
os << this->fmt.record_indent;
}
void DeckOutput::start_record( ) {

View File

@ -22,6 +22,7 @@
#include <opm/parser/eclipse/Utility/Typetools.hpp>
#include <opm/parser/eclipse/Deck/DeckKeyword.hpp>
#include <opm/parser/eclipse/Deck/DeckOutput.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Action/ActionValue.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Action/ActionX.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Action/State.hpp>
@ -148,9 +149,11 @@ std::vector<std::string> ActionX::keyword_strings() const {
std::string keyword_string;
{
std::stringstream ss;
for (const auto& kw : this->keywords)
DeckOutput::format fmt;
for (const auto& kw : this->keywords) {
ss << kw;
ss << fmt.keyword_sep;
}
keyword_string = ss.str();
}

View File

@ -558,10 +558,10 @@ ABC";
std::stringstream s;
DeckOutput out(s);
out.record_indent = "==";
out.item_sep = "-";
out.columns = 2;
out.keyword_sep = "ABC";
out.fmt.record_indent = "==";
out.fmt.item_sep = "-";
out.fmt.columns = 2;
out.fmt.keyword_sep = "ABC";
out.start_keyword("KEYWORD");
out.start_record();
@ -577,7 +577,7 @@ ABC";
out.write<int>(10);
out.end_record();
out.end_keyword(true);
out.write_string( out.keyword_sep );
out.write_string( out.fmt.keyword_sep );
BOOST_CHECK_EQUAL( expected, s.str());
}