summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--slicer/slicer/enum-test.cpp10
-rw-r--r--slicer/slicer/enumMap.h28
-rw-r--r--slicer/slicer/modelPartsTypes.h2
-rw-r--r--slicer/slicer/modelPartsTypes.impl.h12
4 files changed, 24 insertions, 28 deletions
diff --git a/slicer/slicer/enum-test.cpp b/slicer/slicer/enum-test.cpp
index 43e191a..04ca9df 100644
--- a/slicer/slicer/enum-test.cpp
+++ b/slicer/slicer/enum-test.cpp
@@ -16,9 +16,9 @@ namespace test {
static_assert(em.arr[1].nameStr == &two);
static_assert(em.arr[2].value == Es::three);
- static_assert(em.find<Slicer::EnumMapKey::Name>("one")->value == Es::one);
- static_assert(em.find<Slicer::EnumMapKey::Name>("three")->value == Es::three);
- static_assert(em.find<Slicer::EnumMapKey::Value>(Es::one)->name == "one");
- static_assert(em.find<Slicer::EnumMapKey::Value>(Es::three)->name == "three");
- static_assert(!em.find<Slicer::EnumMapKey::Name>("four"));
+ static_assert(em.find("one")->value == Es::one);
+ static_assert(em.find("three")->value == Es::three);
+ static_assert(em.find(Es::one)->name == "one");
+ static_assert(em.find(Es::three)->name == "three");
+ static_assert(!em.find("four"));
}
diff --git a/slicer/slicer/enumMap.h b/slicer/slicer/enumMap.h
index 8f63819..72c1511 100644
--- a/slicer/slicer/enumMap.h
+++ b/slicer/slicer/enumMap.h
@@ -6,11 +6,6 @@
#include <string_view>
namespace Slicer {
- enum class EnumMapKey {
- Value,
- Name,
- };
-
template<typename E> class EnumMap {
public:
struct Node {
@@ -19,20 +14,23 @@ namespace Slicer {
const std::string * nameStr {};
};
- template<EnumMapKey Key, typename T>
[[nodiscard]] constexpr inline const Node *
- find(const T & v) const noexcept
+ find(std::string_view v) const noexcept
{
for (auto b = begin; b != end; b++) {
- if constexpr (Key == EnumMapKey::Value) {
- if (b->value == v) {
- return b;
- }
+ if (b->name == v) {
+ return b;
}
- else if constexpr (Key == EnumMapKey::Name) {
- if (b->name == v) {
- return b;
- }
+ }
+ return nullptr;
+ }
+
+ [[nodiscard]] constexpr inline const Node *
+ find(E v) const noexcept
+ {
+ for (auto b = begin; b != end; b++) {
+ if (b->value == v) {
+ return b;
}
}
return nullptr;
diff --git a/slicer/slicer/modelPartsTypes.h b/slicer/slicer/modelPartsTypes.h
index de0bc29..2d959ea 100644
--- a/slicer/slicer/modelPartsTypes.h
+++ b/slicer/slicer/modelPartsTypes.h
@@ -232,7 +232,7 @@ namespace Slicer {
static const Metadata metadata;
static constexpr const EnumMap<T> & enumerations();
DLL_PUBLIC static const std::string & lookup(T);
- DLL_PUBLIC static T lookup(const std::string_view &);
+ DLL_PUBLIC static T lookup(std::string_view);
};
class DLL_PUBLIC ModelPartForSequenceBase : public ModelPart {
diff --git a/slicer/slicer/modelPartsTypes.impl.h b/slicer/slicer/modelPartsTypes.impl.h
index be23e1f..346a894 100644
--- a/slicer/slicer/modelPartsTypes.impl.h
+++ b/slicer/slicer/modelPartsTypes.impl.h
@@ -518,11 +518,11 @@ namespace Slicer {
return metadata;
}
- template<EnumMapKey Key, typename Ex, typename ExP, typename T, typename V>
+ template<typename Ex, typename ExP, typename T, typename V>
inline const auto *
ModelPartForEnumLookup(const EnumMap<T> & enumerations, const V & val)
{
- if (auto i = enumerations.template find<Key>(val)) {
+ if (auto i = enumerations.find(val)) {
return i;
}
throw Ex(ExP(val), typeid(T).name());
@@ -530,18 +530,16 @@ namespace Slicer {
template<typename T>
T
- ModelPartForEnum<T>::lookup(const std::string_view & val)
+ ModelPartForEnum<T>::lookup(std::string_view val)
{
- return ModelPartForEnumLookup<EnumMapKey::Name, InvalidEnumerationSymbol, std::string, T>(enumerations(), val)
- ->value;
+ return ModelPartForEnumLookup<InvalidEnumerationSymbol, std::string, T>(enumerations(), val)->value;
}
template<typename T>
const std::string &
ModelPartForEnum<T>::lookup(T val)
{
- return *ModelPartForEnumLookup<EnumMapKey::Value, InvalidEnumerationValue, ::Ice::Int, T>(enumerations(), val)
- ->nameStr;
+ return *ModelPartForEnumLookup<InvalidEnumerationValue, ::Ice::Int, T>(enumerations(), val)->nameStr;
}
template<typename T>