Skip to content

Commit

Permalink
A function to convert the FuzzyLevel to a string (#86)
Browse files Browse the repository at this point in the history
Signed-off-by: tempate <[email protected]>
  • Loading branch information
Tempate authored Dec 18, 2023
1 parent 2b24f99 commit 276d3ec
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
6 changes: 5 additions & 1 deletion cpp_utils/include/cpp_utils/types/Fuzzy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ class Fuzzy
//! Get the Fuzzy Level internal value.
FuzzyLevelType get_level() const noexcept;

//! Get the FuzzyLevel's internal value as a string.
std::string get_level_as_str() const noexcept;

/////////////////////////
// SET METHODS
/////////////////////////
Expand Down Expand Up @@ -218,7 +221,8 @@ class Fuzzy

//! \c Fuzzy to stream serializator
template <typename T>
CPP_UTILS_DllAPI std::ostream& operator <<(
CPP_UTILS_DllAPI
std::ostream& operator <<(
std::ostream& os,
const Fuzzy<T>& f);

Expand Down
38 changes: 37 additions & 1 deletion cpp_utils/include/cpp_utils/types/impl/Fuzzy.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,42 @@ FuzzyLevelType Fuzzy<T>::get_level() const noexcept
return fuzzy_level_;
}

template <typename T>
std::string Fuzzy<T>::get_level_as_str() const noexcept
{
// Ideally, we would overload the << operator for FuzzyLevelType, but we can't since it's a namespace to a short.
std::string fuzzy_level;

switch (fuzzy_level_)
{
case FuzzyLevelValues::fuzzy_level_unset:
fuzzy_level = "UNSET";
break;

case FuzzyLevelValues::fuzzy_level_default:
fuzzy_level = "DEFAULT";
break;

case FuzzyLevelValues::fuzzy_level_fuzzy:
fuzzy_level = "FUZZY";
break;

case FuzzyLevelValues::fuzzy_level_set:
fuzzy_level = "SET";
break;

case FuzzyLevelValues::fuzzy_level_hard:
fuzzy_level = "HARD";
break;

default:
// TODO: error?
break;
}

return fuzzy_level;
}

/////////////////////////
// SET METHODS
/////////////////////////
Expand Down Expand Up @@ -187,7 +223,7 @@ std::ostream& operator <<(
std::ostream& os,
const Fuzzy<T>& f)
{
os << "Fuzzy{Level(" << f.get_level() << ") " << f.get_reference() << "}";
os << "Fuzzy{Level(" << f.get_level_as_str() << ") " << f.get_reference() << "}";
return os;
}

Expand Down

0 comments on commit 276d3ec

Please sign in to comment.