Skip to content

Commit

Permalink
Explicitly specify namespace and optimized enum to string processing
Browse files Browse the repository at this point in the history
  • Loading branch information
nyoungbq committed Jan 28, 2025
1 parent 2e7cc62 commit 3f7144f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 47 deletions.
43 changes: 4 additions & 39 deletions src/simplnx/DataStructure/Geometry/IGeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,12 @@ void IGeometry::setSpatialDimensionality(uint32 value)
m_SpacialDimensionality = value;
}

std::set<std::string> IGeometry::StringListFromGeometryType(const std::set<Type>& geomTypes)
std::set<std::string> IGeometry::StringListFromGeometryType(const std::set<IGeometry::Type>& geomTypes)
{
static const std::map<Type, std::string> k_TypeToStringMap = {{Type::Image, GeomTypeToString(Type::Image)},
{Type::RectGrid, GeomTypeToString(Type::RectGrid)},
{Type::Vertex, GeomTypeToString(Type::Vertex)},
{Type::Edge, GeomTypeToString(Type::Edge)},
{Type::Triangle, GeomTypeToString(Type::Triangle)},
{Type::Quad, GeomTypeToString(Type::Quad)},
{Type::Tetrahedral, GeomTypeToString(Type::Tetrahedral)},
{Type::Hexahedral, GeomTypeToString(Type::Hexahedral)}};

std::set<std::string> stringValues;
for(auto geomType : geomTypes)
{
stringValues.insert(k_TypeToStringMap.at(geomType));
stringValues.insert(IGeometry::k_GeomTypeStrings[to_underlying(geomType)]);
}
return stringValues;
}
Expand Down Expand Up @@ -104,35 +95,9 @@ void IGeometry::setUnits(LengthUnit units)
m_Units = units;
}

std::string IGeometry::GeomTypeToString(Type geomType)
std::string IGeometry::GeomTypeToString(IGeometry::Type geomType)
{
switch(geomType)
{
case Type::Image: {
return "Image";
}
case Type::RectGrid: {
return "RectGrid";
}
case Type::Vertex: {
return "Vertex";
}
case Type::Edge: {
return "Edge";
}
case Type::Triangle: {
return "Triangle";
}
case Type::Quad: {
return "Quad";
}
case Type::Tetrahedral: {
return "Tetrahedral";
}
case Type::Hexahedral: {
return "Hexahedral";
}
}
return IGeometry::k_GeomTypeStrings[to_underlying(geomType)];
}

std::string IGeometry::LengthUnitToString(LengthUnit unit)
Expand Down
26 changes: 18 additions & 8 deletions src/simplnx/DataStructure/Geometry/IGeometry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,28 @@ class SIMPLNX_EXPORT IGeometry : public BaseGroup
static inline constexpr StringLiteral k_VoxelSizes = "Voxel Sizes";
static inline constexpr StringLiteral k_TypeName = "IGeometry";

/* We are leveraging the bounded nature of the following enum to expedite processing
*
* Steps for modification:
* Tack new Type on the end of enum
* Specify it's underlying value explicitly (increment of one from previous highest value)
* Add the new typename to k_GeomTypeStrings
*
* DO NOT REORDER */
enum class Type : uint32
{
Image,
RectGrid,
Vertex,
Edge,
Triangle,
Quad,
Tetrahedral,
Hexahedral
Image = 0u,
RectGrid = 1u,
Vertex = 2u,
Edge = 3u,
Triangle = 4u,
Quad = 5u,
Tetrahedral = 6u,
Hexahedral = 7u
};

inline static constexpr std::array<StringLiteral, 8> k_GeomTypeStrings = {"Image", "RectGrid", "Vertex", "Edge", "Triangle", "Quad", "Tetrahedral", "Hexahedral"};

enum class LengthUnit : EnumType
{
Yoctometer,
Expand Down

0 comments on commit 3f7144f

Please sign in to comment.