Skip to content

Commit

Permalink
IOSS: Clean up fmt includes/use
Browse files Browse the repository at this point in the history
  • Loading branch information
gdsjaar committed May 21, 2024
1 parent 75040b4 commit 4f7ce20
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 81 deletions.
7 changes: 5 additions & 2 deletions packages/seacas/libraries/ioss/src/Ioss_StructuredBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
#include "Ioss_NodeBlock.h"
#include "Ioss_Property.h"
#include "Ioss_ZoneConnectivity.h"
#if !defined BUILT_IN_SIERRA
#include <fmt/ostream.h>
#endif
#include <array>
#include <cassert>
#include <fmt/core.h>
#include <fmt/ostream.h>
#include <iosfwd>
#include <stddef.h>
#include <stdint.h>
Expand Down Expand Up @@ -370,10 +371,12 @@ namespace Ioss {
};
} // namespace Ioss

#if !defined BUILT_IN_SIERRA
#if FMT_VERSION >= 90000
namespace fmt {
template <> struct formatter<Ioss::BoundaryCondition> : ostream_formatter
{
};
} // namespace fmt
#endif
#endif
4 changes: 4 additions & 0 deletions packages/seacas/libraries/ioss/src/Ioss_ZoneConnectivity.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
#include <array>
#include <cassert>
#include <cmath>
#if !defined BUILT_IN_SIERRA
#include <fmt/core.h>
#include <fmt/ostream.h>
#endif
#include <iosfwd>
#include <stdlib.h>
#include <string>
Expand Down Expand Up @@ -154,10 +156,12 @@ namespace Ioss {
IOSS_EXPORT std::ostream &operator<<(std::ostream &os, const ZoneConnectivity &zgc);
} // namespace Ioss

#if !defined BUILT_IN_SIERRA
#if FMT_VERSION >= 90000
namespace fmt {
template <> struct formatter<Ioss::ZoneConnectivity> : ostream_formatter
{
};
} // namespace fmt
#endif
#endif
91 changes: 91 additions & 0 deletions packages/seacas/libraries/ioss/src/heartbeat/Iohb_Layout.C
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
// See packages/seacas/LICENSE for details

#include "heartbeat/Iohb_Layout.h"
#include <fmt/format.h>
#include <fmt/ostream.h>
#include <fmt/ranges.h>
#include <string>

namespace Iohb {
Expand All @@ -21,4 +24,92 @@ namespace Iohb {
fmt::print(layout_, "{}{:>{}}", legendStarted ? separator_ : "", label, fieldWidth_);
legendStarted = true;
}

void Layout::output_common(const std::string &name)
{
if (count_++ > 0 && !separator_.empty()) {
fmt::print(layout_, "{}", separator_);
}

if (showLabels && !name.empty()) {
fmt::print(layout_, "{}=", name);
}
}

template void Layout::add(const std::string &name, const std::string &value);
template void Layout::add(const std::string &name, const int &value);
template void Layout::add(const std::string &name, const int64_t &value);
template void Layout::add(const std::string &name, const size_t &value);

// Ideally, this would be in the include file, but when building in Sierra, we
// need to keep all `fmt` includes out of the include file due to some TPLs
// having an embedded fmt which is a different version than used by IOSS.
template <typename T> void Layout::add(const std::string &name, const T &value)
{
output_common(name);
if (!showLabels && fieldWidth_ > 0) {
fmt::print(layout_, "{0:{1}}", value, fieldWidth_);
}
else {
fmt::print(layout_, "{}", value);
}
}

template <> void Layout::add(const std::string &name, const double &value)
{
output_common(name);
if (precision_ == -1) {
// Use lib::fmt full precision output -- as many digits as needed to fully represent the
// double
fmt::print(layout_, "{}", value);
}
else if (!showLabels && fieldWidth_ > 0) {
fmt::print(layout_, "{0:{1}.{2}e}", value, fieldWidth_, precision_);
}
else {
fmt::print(layout_, "{0:.{1}e}", value, precision_);
}
}

template void Layout::add(const std::string &name, const std::vector<int> &value);
template void Layout::add(const std::string &name, const std::vector<int64_t> &value);
template void Layout::add(const std::string &name, const std::vector<size_t> &value);

template <typename T> void Layout::add(const std::string &name, const std::vector<T> &value)
{
if (value.size() == 1) {
add(name, value[0]);
}
else {
output_common(name);
if (!showLabels && fieldWidth_ > 0) {
fmt::print(layout_, "{0:{1}}", fmt::join(value, separator_), fieldWidth_);
}
else {
fmt::print(layout_, "{}", fmt::join(value, separator_));
}
}
}

template <> void Layout::add(const std::string &name, const std::vector<double> &value)
{
if (value.size() == 1) {
add(name, value[0]);
}
else {
output_common(name);
if (precision_ == -1) {
// Use lib::fmt full precision output -- as many digits as needed to fully represent the
// double
fmt::print(layout_, "{}", fmt::join(value, separator_));
}
else if (!showLabels && fieldWidth_ > 0) {
fmt::print(layout_, "{0:{2}.{1}e}", fmt::join(value, separator_), precision_, fieldWidth_);
}
else {
fmt::print(layout_, "{0:.{1}e}", fmt::join(value, separator_), precision_);
}
}
}

} // namespace Iohb
79 changes: 0 additions & 79 deletions packages/seacas/libraries/ioss/src/heartbeat/Iohb_Layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@

#pragma once

#include <fmt/format.h>
#include <fmt/ostream.h>
#include <fmt/ranges.h>
#include <sstream>
#include <string>
#include <vector>
Expand Down Expand Up @@ -43,80 +40,4 @@ namespace Iohb {
bool legendStarted{false};
};

inline void Layout::output_common(const std::string &name)
{
if (count_++ > 0 && !separator_.empty()) {
fmt::print(layout_, "{}", separator_);
}

if (showLabels && !name.empty()) {
fmt::print(layout_, "{}=", name);
}
}

template <typename T> inline void Layout::add(const std::string &name, const T &value)
{
output_common(name);
if (!showLabels && fieldWidth_ > 0) {
fmt::print(layout_, "{0:{1}}", value, fieldWidth_);
}
else {
fmt::print(layout_, "{}", value);
}
}

template <> inline void Layout::add(const std::string &name, const double &value)
{
output_common(name);
if (precision_ == -1) {
// Use lib::fmt full precision output -- as many digits as needed to fully represent the
// double
fmt::print(layout_, "{}", value);
}
else if (!showLabels && fieldWidth_ > 0) {
fmt::print(layout_, "{0:{1}.{2}e}", value, fieldWidth_, precision_);
}
else {
fmt::print(layout_, "{0:.{1}e}", value, precision_);
}
}

template <typename T>
inline void Layout::add(const std::string &name, const std::vector<T> &value)
{
if (value.size() == 1) {
add(name, value[0]);
}
else {
output_common(name);
if (!showLabels && fieldWidth_ > 0) {
fmt::print(layout_, "{0:{1}}", fmt::join(value, separator_), fieldWidth_);
}
else {
fmt::print(layout_, "{}", fmt::join(value, separator_));
}
}
}

template <> inline void Layout::add(const std::string &name, const std::vector<double> &value)
{
if (value.size() == 1) {
add(name, value[0]);
}
else {
output_common(name);
if (precision_ == -1) {
// Use lib::fmt full precision output -- as many digits as needed to fully represent the
// double
fmt::print(layout_, "{}", fmt::join(value, separator_));
}
else if (!showLabels && fieldWidth_ > 0) {
fmt::print(layout_, "{0:{2}.{1}e}", fmt::join(value, separator_), precision_, fieldWidth_);
}
else {
fmt::print(layout_, "{0:.{1}e}", fmt::join(value, separator_), precision_);
}
}
}

} // namespace Iohb

0 comments on commit 4f7ce20

Please sign in to comment.