Skip to content

Commit

Permalink
Updates to compensate for [email protected] no longer implicitly using `operato…
Browse files Browse the repository at this point in the history
…r<<`

In some cases, we use an fmt::formatter class specialization to allow
fmt to use the `operator<<()`, while in other cases, we use `fmt::streamed()`
at the call site.
  • Loading branch information
kennyweiss committed Dec 29, 2022
1 parent e0d6a08 commit 8d7c49a
Show file tree
Hide file tree
Showing 17 changed files with 92 additions and 19 deletions.
6 changes: 6 additions & 0 deletions src/axom/inlet/InletVector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#define INLET_INLETVECTOR_HPP

#include "axom/primal/geometry/Vector.hpp"
#include "axom/fmt.hpp"

namespace axom
{
Expand Down Expand Up @@ -143,4 +144,9 @@ inline std::ostream& operator<<(std::ostream& os, const InletVector& v)
} // end namespace inlet
} // end namespace axom

/// Overload to format an inlet::InletVector using fmt
template <>
struct axom::fmt::formatter<axom::inlet::InletVector> : ostream_formatter
{ };

#endif // INLET_INLETVECTOR_HPP
6 changes: 6 additions & 0 deletions src/axom/primal/geometry/BoundingBox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -718,4 +718,10 @@ std::ostream& operator<<(std::ostream& os, const BoundingBox<T, NDIMS>& bb)
} // namespace primal
} // namespace axom

/// Overload to format a primal::BoundingBox using fmt
template <typename T, int NDIMS>
struct axom::fmt::formatter<axom::primal::BoundingBox<T, NDIMS>>
: ostream_formatter
{ };

#endif // AXOM_PRIMAL_BOUNDINGBOX_HPP_
10 changes: 8 additions & 2 deletions src/axom/primal/geometry/Point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
#include "axom/primal/geometry/NumericArray.hpp"

// C/C++ includes
#include <cstring> // For memcpy()
#include <ostream> // For print() and operator <<
#include <cstring>
#include <ostream>
#include "axom/fmt.hpp"

namespace axom
{
Expand Down Expand Up @@ -333,4 +334,9 @@ std::ostream& operator<<(std::ostream& os, const Point<T, NDIMS>& pt)
} // namespace primal
} // namespace axom

/// Overload to format a primal::Point using fmt
template <typename T, int NDIMS>
struct axom::fmt::formatter<axom::primal::Point<T, NDIMS>> : ostream_formatter
{ };

#endif // AXOM_PRIMAL_POINT_HPP_
5 changes: 5 additions & 0 deletions src/axom/primal/geometry/Segment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,9 @@ std::ostream& operator<<(std::ostream& os, const Segment<T, NDIMS>& seg)
} // namespace primal
} // namespace axom

/// Overload to format a primal::Segment using fmt
template <typename T, int NDIMS>
struct axom::fmt::formatter<axom::primal::Segment<T, NDIMS>> : ostream_formatter
{ };

#endif // AXOM_PRIMAL_SEGMENT_HPP_
6 changes: 6 additions & 0 deletions src/axom/primal/geometry/Sphere.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "axom/primal/geometry/OrientationResult.hpp"

#include "axom/slic/interface/slic.hpp"
#include "axom/fmt.hpp"

namespace axom
{
Expand Down Expand Up @@ -239,4 +240,9 @@ std::ostream& operator<<(std::ostream& os, const Sphere<T, NDIMS>& s)
} // namespace primal
} // namespace axom

/// Overload to format a primal::Sphere using fmt
template <typename T, int NDIMS>
struct axom::fmt::formatter<axom::primal::Sphere<T, NDIMS>> : ostream_formatter
{ };

#endif // AXOM_PRIMAL_SPHERE_HPP_
6 changes: 6 additions & 0 deletions src/axom/primal/geometry/Tetrahedron.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,10 @@ std::ostream& operator<<(std::ostream& os, const Tetrahedron<T, NDIMS>& tet)
} // namespace primal
} // namespace axom

/// Overload to format a primal::Tetrahedron using fmt
template <typename T, int NDIMS>
struct axom::fmt::formatter<axom::primal::Tetrahedron<T, NDIMS>>
: ostream_formatter
{ };

#endif // AXOM_PRIMAL_TETRAHEDRON_HPP_
6 changes: 6 additions & 0 deletions src/axom/primal/geometry/Triangle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "axom/config.hpp"
#include "axom/core.hpp"
#include "axom/slic/interface/slic.hpp"
#include "axom/fmt.hpp"

#include "axom/primal/constants.hpp"
#include "axom/primal/geometry/Point.hpp"
Expand Down Expand Up @@ -420,4 +421,9 @@ std::ostream& operator<<(std::ostream& os, const Triangle<T, NDIMS>& tri)
} // namespace primal
} // namespace axom

/// Overload to format a primal::Triangle using fmt
template <typename T, int NDIMS>
struct axom::fmt::formatter<axom::primal::Triangle<T, NDIMS>> : ostream_formatter
{ };

#endif // AXOM_PRIMAL_TRIANGLE_HPP_
6 changes: 6 additions & 0 deletions src/axom/primal/geometry/Vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "axom/core/numerics/Determinants.hpp"
#include "axom/core/numerics/matvecops.hpp"
#include "axom/core/utilities/Utilities.hpp"
#include "axom/fmt.hpp"

// Primal includes
#include "axom/primal/constants.hpp"
Expand Down Expand Up @@ -710,4 +711,9 @@ inline Vector<T, NDIMS> Vector<T, NDIMS>::make_vector(const T& x,
} // namespace primal
} // namespace axom

/// Overload to format a primal::Vector using fmt
template <typename T, int NDIMS>
struct axom::fmt::formatter<axom::primal::Vector<T, NDIMS>> : ostream_formatter
{ };

#endif // AXOM_PRIMAL_VECTOR_HPP_
6 changes: 6 additions & 0 deletions src/axom/quest/DistributedClosestPoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ enum class DistributedClosestPointRuntimePolicy
hip = 3
};

/// Utility function to allow formating a DistributedClosestPointRuntimePolicy
auto format_as(DistributedClosestPointRuntimePolicy pol)
{
return fmt::underlying(pol);
}

namespace internal
{
// Utility function to dump a conduit node on each rank, e.g. for debugging
Expand Down
6 changes: 3 additions & 3 deletions src/axom/quest/InOutOctree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ void InOutOctree<DIM>::insertMeshCells()
this->isInternal(blk),
fmt::format(
"Block {} was refined, so it should be marked as internal.",
blk));
fmt::streamed(blk)));

/// Setup caches for data associated with children
BlockIndex childBlk[BlockIndex::NUM_CHILDREN];
Expand Down Expand Up @@ -898,7 +898,7 @@ void InOutOctree<DIM>::colorOctreeLeaves()
"First problem block is: {}",
lev,
uncoloredBlocks.size(),
BlockIndex(uncoloredBlocks[0], lev)));
fmt::streamed(BlockIndex(uncoloredBlocks[0], lev))));
}

if(!levelLeafMap.empty())
Expand Down Expand Up @@ -1459,7 +1459,7 @@ bool InOutOctree<DIM>::within(const SpacePt& pt) const
false,
fmt::format("Error -- All leaf blocks must have a color. The color of "
"leafBlock {} was 'Undetermined' when querying point {}",
block,
fmt::streamed(block),
pt));
break;
}
Expand Down
6 changes: 6 additions & 0 deletions src/axom/quest/detail/inout/BlockData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,4 +419,10 @@ inline std::ostream& operator<<(std::ostream& os,

} // namespace quest
} // namespace axom

/// Overload to format a quest::InOutBlockData using fmt
template <>
struct axom::fmt::formatter<axom::quest::InOutBlockData> : ostream_formatter
{ };

#endif // AXOM_QUEST_INOUT_OCTREE_BLOCKDATA__HPP_
18 changes: 9 additions & 9 deletions src/axom/quest/detail/inout/InOutOctreeValidator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class InOutOctreeValidator
fmt::format(
"Error after coloring level {} leaf block {} was not colored.",
level,
BlockIndex(it.pt(), level)));
fmt::streamed(BlockIndex(it.pt(), level))));
}
}

Expand Down Expand Up @@ -109,7 +109,7 @@ class InOutOctreeValidator
" \n\n *** \n Leaf data: {} \n ***",
i,
pos,
vertBlock,
fmt::streamed(vertBlock),
m_octree.blockBoundingBox(vertBlock),
(m_octree.blockBoundingBox(vertBlock).contains(pos) ? "is" : "is NOT"),
leafData));
Expand All @@ -123,9 +123,9 @@ class InOutOctreeValidator
"\n\t -- actual block {} -- is leaf? {}"
"\n\t -- vertex set size: {}",
i,
m_octree.m_vertexToBlockMap[i],
fmt::streamed(m_octree.m_vertexToBlockMap[i]),
(m_octree[m_octree.m_vertexToBlockMap[i]].isLeaf() ? "yes" : "no"),
vertBlock,
fmt::streamed(vertBlock),
(m_octree[vertBlock].isLeaf() ? "yes" : "no"),
numVertices));
}
Expand Down Expand Up @@ -166,7 +166,7 @@ class InOutOctreeValidator
"\n ***",
cIdx,
fmt::join(cvRel, ", "),
vertBlock,
fmt::streamed(vertBlock),
vIdx,
leafData,
fmt::join(leafCells.begin(), leafCells.end(), ", ")));
Expand Down Expand Up @@ -218,7 +218,7 @@ class InOutOctreeValidator
" is not incident in vertex {}",
cIdx,
fmt::join(cvRel, ", "),
block,
fmt::streamed(block),
vIdx));

// Check that this cell intersects the bounding box of the block
Expand All @@ -235,7 +235,7 @@ class InOutOctreeValidator
"\n\tLeaf vertex is: {}"
"\n\tLeaf cells: {} ({})",
cIdx,
block,
fmt::streamed(block),
blockBB,
m_octree.m_meshWrapper.cellPositions(cIdx),
fmt::join(cvRel, ", "),
Expand Down Expand Up @@ -281,9 +281,9 @@ class InOutOctreeValidator
"--- neighbor {} with data {}."
" Neighboring leaves that are not "
"gray must have the same color.",
block,
fmt::streamed(block),
data,
neighborBlk,
fmt::streamed(neighborBlk),
neighborData));
break;
case InOutBlockData::Gray: // intentional fallthrough
Expand Down
6 changes: 4 additions & 2 deletions src/axom/quest/examples/containment_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,8 @@ class ContainmentDriver
if(dimension() == 3)
{
axom::fmt::memory_buffer edgeHistStr;
axom::fmt::format_to(std::back_inserter(edgeHistStr), "Edge length histogram (lg-arithmic): ");
axom::fmt::format_to(std::back_inserter(edgeHistStr),
"Edge length histogram (lg-arithmic): ");
for(auto it = edgeLenHist.begin(); it != edgeLenHist.end(); ++it)
{
axom::fmt::format_to(std::back_inserter(edgeHistStr),
Expand All @@ -429,7 +430,8 @@ class ContainmentDriver
}

axom::fmt::memory_buffer cellHistStr;
axom::fmt::format_to(std::back_inserter(cellHistStr), "Cell areas histogram (lg-arithmic): ");
axom::fmt::format_to(std::back_inserter(cellHistStr),
"Cell areas histogram (lg-arithmic): ");
for(auto it = areaHist.begin(); it != areaHist.end(); ++it)
{
axom::fmt::format_to(std::back_inserter(cellHistStr),
Expand Down
6 changes: 6 additions & 0 deletions src/axom/quest/readers/C2CReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
#include "axom/core.hpp"
#include "axom/slic.hpp"
#include "axom/primal.hpp"
#include "axom/fmt.hpp"

/// Overload to format a c2c::Point using fmt
template <>
struct axom::fmt::formatter<c2c::Point> : ostream_formatter
{ };

namespace axom
{
Expand Down
1 change: 0 additions & 1 deletion src/axom/quest/readers/C2CReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#error C2CReader should only be included when Axom is configured with C2C
#endif

#include "axom/fmt.hpp"
#include "axom/mint.hpp"
#include "c2c/C2C.hpp"

Expand Down
6 changes: 6 additions & 0 deletions src/axom/slam/Utilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#define SLAM_UTILITIES_H_

#include "axom/core.hpp"
#include "axom/fmt.hpp"

#include <string>
#include <iostream>
Expand Down Expand Up @@ -168,4 +169,9 @@ T distance(const Point3<T>& pt1, const Point3<T>& pt2)
} // end namespace slam
} // end namespace axom

/// Overload to format an axom::slam::util::Point3 using fmt
template <typename DataType>
struct axom::fmt::formatter<axom::slam::util::Point3<DataType>> : ostream_formatter
{ };

#endif // SLAM_UTILITIES_H_
5 changes: 3 additions & 2 deletions src/axom/slam/mesh_struct/IA_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ std::vector<std::string> entries_as_vec(const RelOrMap& outer, const SetType& s)
std::vector<std::string> strs(sz);
for(auto pos : s.positions())
{
strs[pos] = s.isValidEntry(pos) ? fmt::format("{}: {}", pos, outer[pos])
: fmt::format("{}: {{}}", pos);
strs[pos] = s.isValidEntry(pos)
? fmt::format("{}: {}", axom::fmt::streamed(pos), outer[pos])
: fmt::format("{}: {{}}", axom::fmt::streamed(pos));
}

return strs;
Expand Down

0 comments on commit 8d7c49a

Please sign in to comment.