cleanup connector strings
authorTomi Valkeinen <tomi.valkeinen@iki.fi>
Sat, 3 Oct 2015 15:05:55 +0000 (18:05 +0300)
committerTomi Valkeinen <tomi.valkeinen@iki.fi>
Sat, 3 Oct 2015 15:05:55 +0000 (18:05 +0300)
libkms++/connector.cpp

index d00f3c756c8a50fc196fdb2ec221adc584ae44db..0d6d4d753c49885df61d1d0559628e0502eeb9cf 100644 (file)
@@ -9,12 +9,12 @@
 
 using namespace std;
 
 
 using namespace std;
 
-#define DEF_CONN(c) [DRM_MODE_CONNECTOR_##c] = #c
-
 namespace kms
 {
 
 namespace kms
 {
 
-static const char * connector_names[] = {
+
+static const map<int, string> connector_names = {
+#define DEF_CONN(c) { DRM_MODE_CONNECTOR_##c, #c }
        DEF_CONN(Unknown),
        DEF_CONN(VGA),
        DEF_CONN(DVII),
        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),
        DEF_CONN(eDP),
        DEF_CONN(VIRTUAL),
        DEF_CONN(DSI),
+#undef DEF_CONN
 };
 
 };
 
-static const char *connection_str[] = {
-       [0] = "<unknown>",
-       [DRM_MODE_CONNECTED] = "Connected",
-       [DRM_MODE_DISCONNECTED] = "Disconnected",
-       [DRM_MODE_UNKNOWNCONNECTION] = "Unknown",
+static const map<int, string> connection_str = {
+       { 0, "<unknown>" },
+       { DRM_MODE_CONNECTED, "Connected" },
+       { DRM_MODE_DISCONNECTED, "Disconnected" },
+       { DRM_MODE_UNKNOWNCONNECTION, "Unknown" },
 };
 
 struct ConnectorPriv
 };
 
 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);
 
        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(),
        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
 }
 
 Videomode Connector::get_default_mode() const