From 2f646bc5ec0b0b2c2fca15756496ab6212ac5ee3 Mon Sep 17 00:00:00 2001 From: Martin Felis Date: Fri, 25 Mar 2022 10:59:12 +0100 Subject: [PATCH] Simpler conversion SocketType <-> Strings. --- src/AnimGraphResource.cc | 27 ++++----------------------- src/AnimGraphResource.h | 9 +++++++-- 2 files changed, 11 insertions(+), 25 deletions(-) diff --git a/src/AnimGraphResource.cc b/src/AnimGraphResource.cc index 40c0c3a..84ce576 100644 --- a/src/AnimGraphResource.cc +++ b/src/AnimGraphResource.cc @@ -16,31 +16,12 @@ using json = nlohmann::json; // Socket <-> json // std::string sSocketTypeToStr(SocketType pin_type) { - std::string result = "unknown"; - switch (pin_type) { - case SocketType::SocketTypeBool: - result = "Bool"; - break; - case SocketType::SocketTypeAnimation: - result = "Animation"; - break; - case SocketType::SocketTypeFloat: - result = "Float"; - break; - case SocketType::SocketTypeVec3: - result = "Vec3"; - break; - case SocketType::SocketTypeQuat: - result = "Quat"; - break; - case SocketType::SocketTypeString: - result = "String"; - break; - default: - result = "Unknown"; + if (pin_type < SocketType::SocketTypeUndefined + || pin_type >= SocketType::SocketTypeLast) { + return "Unknown"; } - return result; + return SocketTypeNames[static_cast(pin_type)]; } json sSocketToJson(const Socket& socket) { diff --git a/src/AnimGraphResource.h b/src/AnimGraphResource.h index ac0e96f..18471ec 100644 --- a/src/AnimGraphResource.h +++ b/src/AnimGraphResource.h @@ -49,13 +49,18 @@ SplitOutputAttributeId(int attribute_id, int* node_id, int* output_index) { enum class SocketType { - SocketTypeUndefined, + SocketTypeUndefined = 0, SocketTypeBool, SocketTypeAnimation, SocketTypeFloat, SocketTypeVec3, SocketTypeQuat, - SocketTypeString + SocketTypeString, + SocketTypeLast +}; + +static const char* SocketTypeNames[] = { + "", "Bool", "Animation", "Float", "Vec3", "Quat", "String" }; enum SocketFlags { SocketFlagAffectsTime = 1 };