From a8b00a77c8a1b524427eb7377fe470bd5c80bb4a Mon Sep 17 00:00:00 2001 From: AllisonWang Date: Thu, 19 Jan 2017 05:45:58 +0000 Subject: [PATCH] Switched PayloadType to be an enum class --- src/include/type/types.h | 13 +++++++---- src/type/types.cpp | 49 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 5 deletions(-) diff --git a/src/include/type/types.h b/src/include/type/types.h index fa15beaeca5..5292b47bf6c 100644 --- a/src/include/type/types.h +++ b/src/include/type/types.h @@ -668,12 +668,15 @@ enum CopyType { // Payload Types //===--------------------------------------------------------------------===// -enum PayloadType { - PAYLOAD_TYPE_INVALID = INVALID_TYPE_ID, // invalid message type - PAYLOAD_TYPE_CLIENT_REQUEST = 1, // request - PAYLOAD_TYPE_CLIENT_RESPONSE = 2, // response - PAYLOAD_TYPE_STOP = 3 // stop loop +enum class PayloadType { + INVALID = INVALID_TYPE_ID, // invalid message type + CLIENT_REQUEST = 1, // request + CLIENT_RESPONSE = 2, // response + STOP = 3 // stop loop }; +std::string PayloadTypeToString(PayloadType type); +PayloadType StringToPayloadType(const std::string &str); +std::ostream &operator<<(std::ostream &os, const PayloadType &type); //===--------------------------------------------------------------------===// // Task Priority Types diff --git a/src/type/types.cpp b/src/type/types.cpp index 59e5070337d..31e9cbdb334 100644 --- a/src/type/types.cpp +++ b/src/type/types.cpp @@ -1268,6 +1268,55 @@ std::ostream& operator<<(std::ostream& os, const JoinType& type) { return os; } +//===--------------------------------------------------------------------===// +// PayloadType - String Utilities +//===--------------------------------------------------------------------===// + +std::string PayloadTypeToString(PayloadType type) { + switch (type) { + case PayloadType::INVALID: { + return ("INVALID"); + } + case PayloadType::CLIENT_REQUEST: { + return ("CLIENT_REQUEST"); + } + case PayloadType::CLIENT_RESPONSE: { + return ("CLIENT_RESPONSE"); + } + case PayloadType::STOP: { + return ("STOP"); + } + default: { + throw ConversionException( + StringUtil::Format("No string conversion for PayloadType value '%d'", + static_cast(type))); + } + } + return "INVALID"; +} + +PayloadType StringToPayloadType(const std::string &str) { + std::string upper_str = StringUtil::Upper(str); + if (upper_str == "INVALID") { + return PayloadType::INVALID; + } else if (upper_str == "CLIENT_REQUEST") { + return PayloadType::CLIENT_REQUEST; + } else if (upper_str == "CLIENT_RESPONSE") { + return PayloadType::CLIENT_RESPONSE; + } else if (upper_str == "STOP") { + return PayloadType::STOP; + } else { + throw ConversionException(StringUtil::Format( + "No PayloadType conversion from string '%s'", upper_str.c_str())); + } + return PayloadType::INVALID; +} + +std::ostream &operator<<(std::ostream &os, const PayloadType &type) { + os << PayloadTypeToString(type); + return os; +} + //===--------------------------------------------------------------------===// // ResultType - String Utilities //===--------------------------------------------------------------------===//