lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [4912] Reimplement product_database::GetEntry()


From: Greg Chicares
Subject: [lmi-commits] [4912] Reimplement product_database::GetEntry()
Date: Thu, 06 May 2010 13:51:15 +0000

Revision: 4912
          http://svn.sv.gnu.org/viewvc/?view=rev&root=lmi&revision=4912
Author:   chicares
Date:     2010-05-06 13:51:14 +0000 (Thu, 06 May 2010)
Log Message:
-----------
Reimplement product_database::GetEntry()

Modified Paths:
--------------
    lmi/trunk/ChangeLog
    lmi/trunk/database.cpp
    lmi/trunk/ihs_database.cpp
    lmi/trunk/input_test.cpp

Modified: lmi/trunk/ChangeLog
===================================================================
--- lmi/trunk/ChangeLog 2010-05-06 13:24:12 UTC (rev 4911)
+++ lmi/trunk/ChangeLog 2010-05-06 13:51:14 UTC (rev 4912)
@@ -25475,3 +25475,17 @@
   http://lists.nongnu.org/archive/html/lmi/2010-05/msg00004.html
 or thereabouts.
 
+20100506T1324Z <address@hidden> [718]
+
+  database.cpp
+  database.hpp
+  ihs_database.cpp
+Improve encapsulation; rename private members.
+
+20100506T1351Z <address@hidden> [718]
+
+  database.cpp
+  ihs_database.cpp
+  input_test.cpp
+Reimplement product_database::GetEntry().
+

Modified: lmi/trunk/database.cpp
===================================================================
--- lmi/trunk/database.cpp      2010-05-06 13:24:12 UTC (rev 4911)
+++ lmi/trunk/database.cpp      2010-05-06 13:51:14 UTC (rev 4912)
@@ -29,6 +29,7 @@
 #include "database.hpp"
 
 #include "alert.hpp"
+#include "assert_lmi.hpp"
 #include "dbdict.hpp"
 #include "dbnames.hpp"
 #include "yare_input.hpp"
@@ -133,24 +134,21 @@
 database_entity const& product_database::GetEntry(int k) const
 {
     dict_map const& d = DBDictionary::instance().GetDictionary();
+    LMI_ASSERT(d.size() == GetDBNames().size());
+    LMI_ASSERT(d.size() == DB_LAST);
+    LMI_ASSERT(0 == DB_FIRST);
+    LMI_ASSERT(DB_FIRST <= k && k < DB_LAST);
     dict_map::const_iterator i = d.find(k);
     if(i == d.end())
         {
         fatal_error()
-            << "Key "
+            << "Database entity '"
             << GetDBNames()[k].ShortName
-            << " not found. These keys were found:"
+            << "' not found."
+            << LMI_FLUSH
             ;
-        for(i = d.begin(); i != d.end(); ++i)
-            {
-            fatal_error() << " " << GetDBNames()[(*i).first].ShortName;
-            }
-        if(d.empty())
-            {
-            fatal_error() << " [none]. Dictionary is empty." << (*i).first;
-            }
-        fatal_error() << LMI_FLUSH;
         }
+
     return (*i).second;
 }
 

Modified: lmi/trunk/ihs_database.cpp
===================================================================
--- lmi/trunk/ihs_database.cpp  2010-05-06 13:24:12 UTC (rev 4911)
+++ lmi/trunk/ihs_database.cpp  2010-05-06 13:51:14 UTC (rev 4912)
@@ -216,27 +216,22 @@
 database_entity const& product_database::GetEntry(int k) const
 {
     dict_map const& d = DBDictionary::instance().GetDictionary();
+    LMI_ASSERT(d.size() == GetDBNames().size());
+    LMI_ASSERT(d.size() == DB_LAST);
+    LMI_ASSERT(0 == DB_FIRST);
+    LMI_ASSERT(DB_FIRST <= k && k < DB_LAST);
     dict_map::const_iterator i = d.find(k);
     if(i == d.end())
         {
-        std::string s("no name");
-        if(0 <= k && static_cast<unsigned int>(k) < GetDBNames().size())
-            {
-            s = GetDBNames()[k].ShortName;
-            }
         fatal_error()
-            << "Database element "
-            << k
-            << " ('" << s << "')"
-            << " not found."
+            << "Database entity '"
+            << GetDBNames()[k].ShortName
+            << "' not found."
             << LMI_FLUSH
             ;
-        return *new database_entity;
         }
-    else
-        {
-        return (*i).second;
-        }
+
+    return (*i).second;
 }
 
 /// Constrain the value extracted from the database to be scalar--i.e.,

Modified: lmi/trunk/input_test.cpp
===================================================================
--- lmi/trunk/input_test.cpp    2010-05-06 13:24:12 UTC (rev 4911)
+++ lmi/trunk/input_test.cpp    2010-05-06 13:51:14 UTC (rev 4912)
@@ -96,15 +96,19 @@
     product_database db(yi);
     std::vector<double> v;
 
-    db.GetEntry(-1);
+    BOOST_TEST_THROW
+        (db.GetEntry(-1)
+        ,std::runtime_error
+        ,"Assertion 'DB_FIRST <= k && k < DB_LAST' failed."
+        );
 
     std::cout
         << "\n  Database speed tests..."
-        << "\n  Init()           : " << 
TimeAnAliquot(boost::bind(&product_database::Init,            &db))
-        << "\n  ConstrainScalar(): " << 
TimeAnAliquot(boost::bind(&product_database::ConstrainScalar, &db, DB_EndtAge))
-        << "\n  Query(vector)    : " << 
TimeAnAliquot(boost::bind(&product_database::Query,           &db, v, 
DB_EndtAge))
-        << "\n  Query(scalar)    : " << 
TimeAnAliquot(boost::bind(&product_database::Query,           &db, DB_EndtAge))
-        << "\n  GetEntry()       : " << 
TimeAnAliquot(boost::bind(&product_database::GetEntry,        &db, DB_EndtAge))
+        << "\n  initialize()      : " << 
TimeAnAliquot(boost::bind(&product_database::initialize,       &db))
+        << "\n  constrain_scalar(): " << 
TimeAnAliquot(boost::bind(&product_database::constrain_scalar, &db, DB_EndtAge))
+        << "\n  Query(vector)     : " << 
TimeAnAliquot(boost::bind(&product_database::Query,            &db, v, 
DB_EndtAge))
+        << "\n  Query(scalar)     : " << 
TimeAnAliquot(boost::bind(&product_database::Query,            &db, DB_EndtAge))
+        << "\n  GetEntry()        : " << 
TimeAnAliquot(boost::bind(&product_database::GetEntry,         &db, DB_EndtAge))
         << '\n'
         ;
 }





reply via email to

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