lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [4869] Commute between database name and key (VS)


From: Greg Chicares
Subject: [lmi-commits] [4869] Commute between database name and key (VS)
Date: Thu, 29 Apr 2010 19:10:16 +0000

Revision: 4869
          http://svn.sv.gnu.org/viewvc/?view=rev&root=lmi&revision=4869
Author:   chicares
Date:     2010-04-29 19:10:15 +0000 (Thu, 29 Apr 2010)
Log Message:
-----------
Commute between database name and key (VS)

Modified Paths:
--------------
    lmi/trunk/dbnames.cpp
    lmi/trunk/dbnames.hpp

Modified: lmi/trunk/dbnames.cpp
===================================================================
--- lmi/trunk/dbnames.cpp       2010-04-28 12:31:24 UTC (rev 4868)
+++ lmi/trunk/dbnames.cpp       2010-04-29 19:10:15 UTC (rev 4869)
@@ -31,8 +31,11 @@
 
 #include "alert.hpp"
 #include "assert_lmi.hpp"
+#include "map_lookup.hpp"
 #include "miscellany.hpp"
 
+#include <map>
+
 namespace
 {
 bool check_order(std::vector<db_names> const& v)
@@ -86,6 +89,19 @@
 
     return v;
 }
+
+std::map<std::string,int> static_get_short_names()
+{
+    std::map<std::string,int> m;
+    static std::vector<db_names> const names = static_get_db_names();
+    typedef std::vector<db_names>::const_iterator vdbnci;
+    for(vdbnci i = names.begin(); i != names.end(); ++i)
+        {
+        m[i->ShortName] = i->Idx;
+        }
+    return m;
+}
+
 } // Unnamed namespace.
 
 std::vector<db_names> const& GetDBNames()
@@ -93,3 +109,16 @@
     return static_get_db_names();
 }
 
+int db_key_from_name(std::string const& name)
+{
+    static std::map<std::string,int> const m = static_get_short_names();
+    return map_lookup(m, name);
+}
+
+std::string db_name_from_key(int key)
+{
+    static std::vector<db_names> const names = static_get_db_names();
+    LMI_ASSERT(0 <= key && key < DB_LAST);
+    return names[key].ShortName;
+}
+

Modified: lmi/trunk/dbnames.hpp
===================================================================
--- lmi/trunk/dbnames.hpp       2010-04-28 12:31:24 UTC (rev 4868)
+++ lmi/trunk/dbnames.hpp       2010-04-29 19:10:15 UTC (rev 4869)
@@ -28,6 +28,7 @@
 
 #include "so_attributes.hpp"
 
+#include <string>
 #include <vector>
 
 /// See 'dbnames.xpp' for the definition of each entity.
@@ -447,5 +448,8 @@
 
 std::vector<db_names> const& LMI_SO GetDBNames();
 
+int         db_key_from_name(std::string const&);
+std::string db_name_from_key(int);
+
 #endif // dbnames_hpp
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]