Skip to content

Commit

Permalink
Refactor (TextResourceWriter): Add member function 'writeNumericArray'
Browse files Browse the repository at this point in the history
  • Loading branch information
smlu committed Jul 9, 2020
1 parent 027680f commit 211d314
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions libraries/libim/content/text/text_resource_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <libim/utils/utils.h>
#include <libim/types/flags.h>

#include <array>
#include <cmath>
#include <sstream>
#include <string_view>
Expand Down Expand Up @@ -112,12 +113,12 @@ namespace libim::content::text {
}
}

template<typename T, std::size_t S, typename Tag>
TextResourceWriter& writeKeyValue(std::string_view key, const AbstractVector<T, S, Tag>& v, std::size_t indent = 0)
template<typename T, std::size_t S, typename = std::enable_if_t<std::is_arithmetic_v<T>>>
TextResourceWriter& writeKeyValue(std::string_view key, const std::array<T, S>& a, std::size_t indent = 0)
{
write(key);
this->indent(indent);
writeVector(v, 1);
writeNumericArray(a, 1);
return writeEol();
}

Expand Down Expand Up @@ -207,20 +208,26 @@ namespace libim::content::text {
return *this;
}

TextResourceWriter& writeRowIdx(std::size_t idx, std::size_t indent);
TextResourceWriter& writeSection(std::string_view section, bool overline = true);

template<typename T, std::size_t S, typename Tag>
TextResourceWriter& writeVector(const AbstractVector<T, S, Tag>& v, std::size_t indent = 4)
template<typename T, std::size_t S, typename = std::enable_if_t<std::is_arithmetic_v<T>>>
TextResourceWriter& writeNumericArray(const std::array<T, S>& a, std::size_t indent = 4)
{
for(const auto e : v)
for (const auto e : a)
{
this->indent(getNumberIndent(indent, e));
writeNumber<10, 8>(e);
}
return *this;
}

TextResourceWriter& writeRowIdx(std::size_t idx, std::size_t indent);
TextResourceWriter& writeSection(std::string_view section, bool overline = true);

template<typename T, std::size_t S, typename Tag>
inline TextResourceWriter& writeVector(const AbstractVector<T, S, Tag>& v, std::size_t indent = 4)
{
return writeNumericArray(v, indent);
}

void setIndentCh(char ch)
{
indch_ = ch;
Expand Down

0 comments on commit 211d314

Please # to comment.