From d0effe834f1600f233a772520c4eb3339f49571f Mon Sep 17 00:00:00 2001 From: Tomi Valkeinen Date: Sat, 3 Oct 2015 18:05:55 +0300 Subject: cleanup connector strings --- libkms++/connector.cpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'libkms++') diff --git a/libkms++/connector.cpp b/libkms++/connector.cpp index d00f3c7..0d6d4d7 100644 --- a/libkms++/connector.cpp +++ b/libkms++/connector.cpp @@ -9,12 +9,12 @@ using namespace std; -#define DEF_CONN(c) [DRM_MODE_CONNECTOR_##c] = #c - namespace kms { -static const char * connector_names[] = { + +static const map connector_names = { +#define DEF_CONN(c) { DRM_MODE_CONNECTOR_##c, #c } DEF_CONN(Unknown), DEF_CONN(VGA), DEF_CONN(DVII), @@ -32,13 +32,14 @@ static const char * connector_names[] = { DEF_CONN(eDP), DEF_CONN(VIRTUAL), DEF_CONN(DSI), +#undef DEF_CONN }; -static const char *connection_str[] = { - [0] = "", - [DRM_MODE_CONNECTED] = "Connected", - [DRM_MODE_DISCONNECTED] = "Disconnected", - [DRM_MODE_UNKNOWNCONNECTION] = "Unknown", +static const map connection_str = { + { 0, "" }, + { DRM_MODE_CONNECTED, "Connected" }, + { DRM_MODE_DISCONNECTED, "Disconnected" }, + { DRM_MODE_UNKNOWNCONNECTION, "Unknown" }, }; struct ConnectorPriv @@ -54,8 +55,8 @@ Connector::Connector(Card &card, uint32_t id, uint32_t idx) m_priv->drm_connector = drmModeGetConnector(this->card().fd(), this->id()); assert(m_priv->drm_connector); - auto name = connector_names[m_priv->drm_connector->connector_type]; - m_fullname = std::string(string(name) + std::to_string(m_priv->drm_connector->connector_type_id)); + const auto& name = connector_names.at(m_priv->drm_connector->connector_type); + m_fullname = name + to_string(m_priv->drm_connector->connector_type_id); } @@ -89,7 +90,7 @@ void Connector::print_short() const auto c = m_priv->drm_connector; printf("Connector %d, %s, %dx%dmm, %s\n", id(), m_fullname.c_str(), - c->mmWidth, c->mmHeight, connection_str[c->connection]); + c->mmWidth, c->mmHeight, connection_str.at(c->connection).c_str()); } Videomode Connector::get_default_mode() const -- cgit v1.2.3