lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [5088] Permit querying product database with nondefault in


From: Greg Chicares
Subject: [lmi-commits] [5088] Permit querying product database with nondefault index
Date: Sun, 01 Aug 2010 15:14:43 +0000

Revision: 5088
          http://svn.sv.gnu.org/viewvc/?view=rev&root=lmi&revision=5088
Author:   chicares
Date:     2010-08-01 15:14:42 +0000 (Sun, 01 Aug 2010)
Log Message:
-----------
Permit querying product database with nondefault index

Modified Paths:
--------------
    lmi/trunk/database.cpp
    lmi/trunk/database.hpp
    lmi/trunk/input_test.cpp

Modified: lmi/trunk/database.cpp
===================================================================
--- lmi/trunk/database.cpp      2010-08-01 15:13:53 UTC (rev 5087)
+++ lmi/trunk/database.cpp      2010-08-01 15:14:42 UTC (rev 5088)
@@ -86,17 +86,52 @@
     return length_;
 }
 
+database_index product_database::index() const
+{
+    return index_;
+}
+
+/// Query database, using default index; return a scalar.
+///
+/// Throw if the database entity is not scalar.
+
 double product_database::Query(e_database_key k) const
 {
+    return Query(k, index_);
+}
+
+/// Query database; return a scalar.
+///
+/// Throw if the database entity is not scalar.
+///
+/// Return a double because it is convertible to the most common
+/// arithmetic types.
+///
+/// An idea like this:
+///   template<typename T, typename DBValue>
+///   void Query(T&, e_database_key) const;
+/// might prove useful someday.
+
+double product_database::Query(e_database_key k, database_index const& i) const
+{
     database_entity const& v = entity_from_key(k);
     LMI_ASSERT(1 == v.extent());
-    return *v[index_];
+    return *v[i];
 }
 
+/// Query database, using default index; write result into vector argument.
+
 void product_database::Query(std::vector<double>& dst, e_database_key k) const
 {
+    return Query(dst, k, index_);
+}
+
+/// Query database; write result into vector argument.
+
+void product_database::Query(std::vector<double>& dst, e_database_key k, 
database_index const& i) const
+{
     database_entity const& v = entity_from_key(k);
-    double const*const z = v[index_];
+    double const*const z = v[i];
     if(1 == v.extent())
         {
         dst.assign(length_, *z);

Modified: lmi/trunk/database.hpp
===================================================================
--- lmi/trunk/database.hpp      2010-08-01 15:13:53 UTC (rev 5087)
+++ lmi/trunk/database.hpp      2010-08-01 15:14:42 UTC (rev 5088)
@@ -64,13 +64,12 @@
     ~product_database();
 
     int length() const;
+    database_index index() const;
 
-    // Return scalar: use double because it's convertible to int, bool, etc.
-    // Someday, consider doing something like:
-    //   template<typename T, typename DBValue>
-    //   void Query(T&, e_database_key) const;
     double Query(e_database_key) const;
+    double Query(e_database_key, database_index const&) const;
     void Query(std::vector<double>&, e_database_key) const;
+    void Query(std::vector<double>&, e_database_key, database_index const&) 
const;
 
     bool are_equivalent(e_database_key, e_database_key) const;
     bool varies_by_state(e_database_key) const;

Modified: lmi/trunk/input_test.cpp
===================================================================
--- lmi/trunk/input_test.cpp    2010-08-01 15:13:53 UTC (rev 5087)
+++ lmi/trunk/input_test.cpp    2010-08-01 15:14:42 UTC (rev 5088)
@@ -143,12 +143,18 @@
         ,"Assertion '1 == v.extent()' failed."
         );
 
+    // Use bind<R> where compilation errors would occur without <R>.
+    // The "recommended" solution forces the "right" overload by
+    // writing an explicit pointer to member:
+    //   http://lists.boost.org/boost-users/2007/06/28832.php
+    // but if that becomes necessary, then bind should be abandoned:
+    // writing individual functions by hand is simpler and clearer.
     std::cout
         << "\n  Database speed tests..."
-        << "\n  initialize()      : " << 
TimeAnAliquot(boost::bind(&product_database::initialize,      &db, 
"sample.database"))
-        << "\n  Query(vector)     : " << 
TimeAnAliquot(boost::bind(&product_database::Query,           &db, v, 
DB_MaturityAge))
-        << "\n  Query(scalar)     : " << 
TimeAnAliquot(boost::bind(&product_database::Query,           &db,    
DB_MaturityAge))
-        << "\n  entity_from_key() : " << 
TimeAnAliquot(boost::bind(&product_database::entity_from_key, &db,    
DB_MaturityAge))
+        << "\n  initialize()      : " << TimeAnAliquot(boost::bind        
(&product_database::initialize,      &db, "sample.database"))
+        << "\n  Query(vector)     : " << TimeAnAliquot(boost::bind<void  
>(&product_database::Query,           &db, v, DB_MaturityAge))
+        << "\n  Query(scalar)     : " << 
TimeAnAliquot(boost::bind<double>(&product_database::Query,           &db,    
DB_MaturityAge))
+        << "\n  entity_from_key() : " << TimeAnAliquot(boost::bind        
(&product_database::entity_from_key, &db,    DB_MaturityAge))
         << '\n'
         ;
 




reply via email to

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