Repository navigation
Extensible Enum #100
Copy link
Copy link
Closed
Labels
Azure.CoreClientThis issue points to a problem in the data-plane of the library.This issue points to a problem in the data-plane of the library.feature-requestThis issue requires a new behavior in the product in order be resolved.This issue requires a new behavior in the product in order be resolved.
Milestone
Description
Pattern proposal for extensible enum: https://godbolt.org/z/BauE8C
#include <string>
char AsciiToUpper(const char c) noexcept {
class AsciiToUpperTable {
char m_map[256];
public:
constexpr AsciiToUpperTable() noexcept : m_map() {
for (int idx = 0; idx < 256; ++idx) {
m_map[idx] = static_cast<char>(static_cast<unsigned char>(idx));
}
for (int idx = 'a'; idx < 'z'; ++idx) {
m_map[idx] = idx + ('a' - 'A');
}
}
char operator[](const char c) const noexcept { return m_map[static_cast<unsigned char>(c)]; }
};
static constexpr AsciiToUpperTable toUpperTable;
return toUpperTable[c];
}
inline bool CaseInSensStringCompareCpp11(const std::string& str1, const std::string &str2) noexcept {
return std::equal(str1.begin(), str1.end(), str2.begin(), str2.end(),
[](const char lhs, const char rhs) noexcept { return AsciiToUpper(lhs) == AsciiToUpper(rhs); });
}
// This goes in a .cpp file:
/// <summary>
/// <see cref="JsonWebKey"/> key types.
/// </summary>
class KeyType {
std::string mValue;
public:
/// <summary>
/// Initializes a new instance of the <see cref="KeyType"/> structure.
/// </summary>
/// <param name="value"></param>
KeyType(const std::string& value) : mValue(value) { }
KeyType(const char* value) : mValue(value) { }
/// <summary>
/// Determines if two <see cref="KeyType"/> values are the same.
/// </summary>
/// <param name="a">The first <see cref="KeyType"/> to compare.</param>
/// <param name="b">The second <see cref="KeyType"/> to compare.</param>
/// <returns>True if <paramref name="a"/> and <paramref name="b"/> are the same; otherwise, false.</returns>
bool operator==(const KeyType& other) const noexcept { return CaseInSensStringCompareCpp11(mValue, other.mValue); }
/// <summary>
/// Determines if two <see cref="KeyType"/> values are different.
/// </summary>
/// <param name="a">The first <see cref="KeyType"/> to compare.</param>
/// <param name="b">The second <see cref="KeyType"/> to compare.</param>
/// <returns>True if <paramref name="a"/> and <paramref name="b"/> are different; otherwise, false.</returns>
bool operator!=(const KeyType& other) const noexcept { return !(*this == other); }
const std::string& Get() const noexcept { return mValue; }
/// <summary>
/// Elliptic curve cryptographic algorithm.
/// </summary>
const static KeyType Ec;
/// <summary>
/// Elliptic curve cryptographic algorithm backed by HSM.
/// </summary>
const static KeyType EcHsm;
/// <summary>
/// RSA cryptographic algorithm.
/// </summary>
const static KeyType Rsa;
/// <summary>
/// RSA cryptographic algorithm backed by HSM.
/// </summary>
const static KeyType RsaHsm;
/// <summary>
/// AES cryptographic algorithm.
/// </summary>
const static KeyType Oct;
};
// These go in a .cpp file:
const KeyType KeyType::Ec = "EC";
const KeyType KeyType::EcHsm = "EC-HSM";
const KeyType KeyType::Rsa = "RSA";
const KeyType KeyType::RsaHsm = "RSA-HSM";
const KeyType KeyType::Oct = "oct";
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Azure.CoreClientThis issue points to a problem in the data-plane of the library.This issue points to a problem in the data-plane of the library.feature-requestThis issue requires a new behavior in the product in order be resolved.This issue requires a new behavior in the product in order be resolved.
Activity
[-][FEATURE REQ] Extensible Enum[/-][+]Extensible Enum[/+]RickWinter commentedon Jul 23, 2020
Anton Kolesnyk (@antkmsft) you mentioned you were adding an extensible enum with your logging work. Here is a proposed pattern for the extensible enum
RickWinter commentedon Dec 15, 2020
Guidelines are updated with the design