Skip to content

Commit

Permalink
Switched PayloadType to be an enum class
Browse files Browse the repository at this point in the history
  • Loading branch information
allisonwang committed Jan 19, 2017
1 parent e187418 commit a8b00a7
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/include/type/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
49 changes: 49 additions & 0 deletions src/type/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(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
//===--------------------------------------------------------------------===//
Expand Down

0 comments on commit a8b00a7

Please sign in to comment.