[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [4898] Revamp database-index class
From: |
Greg Chicares |
Subject: |
[lmi-commits] [4898] Revamp database-index class |
Date: |
Mon, 03 May 2010 22:53:20 +0000 |
Revision: 4898
http://svn.sv.gnu.org/viewvc/?view=rev&root=lmi&revision=4898
Author: chicares
Date: 2010-05-03 22:53:19 +0000 (Mon, 03 May 2010)
Log Message:
-----------
Revamp database-index class
Modified Paths:
--------------
lmi/trunk/ChangeLog
lmi/trunk/database.cpp
lmi/trunk/database.hpp
lmi/trunk/dbindex.hpp
lmi/trunk/dbvalue.cpp
lmi/trunk/dbvalue.hpp
lmi/trunk/ihs_database.cpp
Modified: lmi/trunk/ChangeLog
===================================================================
--- lmi/trunk/ChangeLog 2010-05-03 18:08:23 UTC (rev 4897)
+++ lmi/trunk/ChangeLog 2010-05-03 22:53:19 UTC (rev 4898)
@@ -25358,3 +25358,13 @@
ihs_database.cpp
Remove a disused member.
+20100503T2253Z <address@hidden> [723]
+
+ database.cpp
+ database.hpp
+ dbindex.hpp
+ dbvalue.cpp
+ dbvalue.hpp
+ ihs_database.cpp
+Revamp database-index class.
+
Modified: lmi/trunk/database.cpp
===================================================================
--- lmi/trunk/database.cpp 2010-05-03 18:08:23 UTC (rev 4897)
+++ lmi/trunk/database.cpp 2010-05-03 22:53:19 UTC (rev 4898)
@@ -97,28 +97,22 @@
//============================================================================
void TDatabase::Init()
{
- Idx.Gender () = Gender ;
- Idx.Class () = Class ;
- Idx.Smoker () = Smoker ;
- Idx.IssueAge () = IssueAge ;
- Idx.UWBasis () = UWBasis ;
- Idx.State () = State ;
-
- length_ = static_cast<int>(*GetEntry(DB_EndtAge)[Idx]) - IssueAge;
+ index_ = database_index(Gender, Class, Smoker, IssueAge, UWBasis, State);
+ length_ = static_cast<int>(*GetEntry(DB_EndtAge)[index_]) - IssueAge;
}
//===========================================================================
double TDatabase::Query(int k) const
{
ConstrainScalar(k); // TODO ?? Is the extra overhead acceptable?
- return *GetEntry(k)[Idx];
+ return *GetEntry(k)[index_];
}
//===========================================================================
void TDatabase::Query(std::vector<double>& dst, int k) const
{
TDBValue const& v = GetEntry(k);
- double const*const z = v[Idx];
+ double const*const z = v[index_];
dst.resize(length_);
if(1 == v.GetNDims())
{
Modified: lmi/trunk/database.hpp
===================================================================
--- lmi/trunk/database.hpp 2010-05-03 18:08:23 UTC (rev 4897)
+++ lmi/trunk/database.hpp 2010-05-03 22:53:19 UTC (rev 4898)
@@ -82,10 +82,10 @@
void Init();
void Init(std::string const& NewFilename);
- TDBIndex Idx;
- std::string Filename;
+ database_index index_;
+ std::string Filename;
- int length_;
+ int length_;
mcenum_gender Gender; // gender
mcenum_class Class; // underwriting class
Modified: lmi/trunk/dbindex.hpp
===================================================================
--- lmi/trunk/dbindex.hpp 2010-05-03 18:08:23 UTC (rev 4897)
+++ lmi/trunk/dbindex.hpp 2010-05-03 22:53:19 UTC (rev 4898)
@@ -1,4 +1,4 @@
-// Product database lookup index.
+// Product-database lookup index.
//
// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2005, 2006, 2007, 2008, 2009,
2010 Gregory W. Chicares.
//
@@ -26,47 +26,45 @@
#include "config.hpp"
+#include "mc_enum_type_enums.hpp"
+
#include <vector>
-// Database lookup index
+/// Product-database lookup index.
+///
+/// Implicitly-declared special member functions do the right thing.
-class TDBIndex
+class database_index
{
public:
- enum{MaxIndex = 6};
+ enum{number_of_indices = 6};
- TDBIndex()
- :idx(6)
- {
- }
+ database_index()
+ :idx_(number_of_indices)
+ {}
-/*
- TDBIndex
- (mcenum_gender a_Gender // gender
- ,mcenum_class a_Class // underwriting class
- ,mcenum_smoking a_Smoker // smoker class
- ,int a_IssueAge // issue age
- ,mcenum_uw_basis a_UWBasis // underwriting basis
- ,mcenum_state a_State // state of jurisdiction
- );
-*/
+ database_index
+ (mcenum_gender gender
+ ,mcenum_class uw_class
+ ,mcenum_smoking smoker
+ ,int issue_age
+ ,mcenum_uw_basis uw_basis
+ ,mcenum_state state
+ )
+ :idx_(number_of_indices)
+ {
+ idx_[0] = gender ;
+ idx_[1] = uw_class ;
+ idx_[2] = smoker ;
+ idx_[3] = issue_age;
+ idx_[4] = uw_basis ;
+ idx_[5] = state ;
+ }
-// TODO ?? These data aren't very well encapsulated.
- double& Gender () {return idx[0];}
- double& Class () {return idx[1];}
- double& Smoker () {return idx[2];}
- double& IssueAge() {return idx[3];}
- double& UWBasis () {return idx[4];}
- double& State () {return idx[5];}
+ std::vector<int> const& index_vector() const {return idx_;}
- std::vector<double> const& GetIdx() const {return idx;}
-
private:
-// TODO ?? Erase these?
- TDBIndex(TDBIndex const&);
- TDBIndex& operator=(TDBIndex const&);
-
- std::vector<double> idx;
+ std::vector<int> idx_;
};
#endif // dbindex_hpp
Modified: lmi/trunk/dbvalue.cpp
===================================================================
--- lmi/trunk/dbvalue.cpp 2010-05-03 18:08:23 UTC (rev 4897)
+++ lmi/trunk/dbvalue.cpp 2010-05-03 22:53:19 UTC (rev 4898)
@@ -249,9 +249,9 @@
}
//============================================================================
-double const* TDBValue::operator[](TDBIndex const& idx) const
+double const* TDBValue::operator[](database_index const& idx) const
{
- std::vector<double> index(idx.GetIdx());
+ std::vector<int> const& index(idx.index_vector());
LMI_ASSERT(0 < axis_lengths_.size());
int z = 0;
@@ -261,7 +261,7 @@
if(1 != axis_lengths_[j])
{
LMI_ASSERT(index[j] < axis_lengths_[j]);
- z = z * axis_lengths_[j] + static_cast<int>(index[j]);
+ z = z * axis_lengths_[j] + index[j];
}
}
z *= axis_lengths_.back();
Modified: lmi/trunk/dbvalue.hpp
===================================================================
--- lmi/trunk/dbvalue.hpp 2010-05-03 18:08:23 UTC (rev 4897)
+++ lmi/trunk/dbvalue.hpp 2010-05-03 22:53:19 UTC (rev 4898)
@@ -65,7 +65,7 @@
// Separate enumerators here facilitate compile-time assertions
// in the database GUI, q.v.--an array could not be indexed to
// produce an arithmetic constant expression [5.19/3].
- enum {e_number_of_axes = 1 + TDBIndex::MaxIndex};
+ enum {e_number_of_axes = 1 + database_index::number_of_indices};
enum {e_max_dim_gender = 3};
enum {e_max_dim_class = 4};
enum {e_max_dim_smoking = 3};
@@ -95,7 +95,7 @@
);
~TDBValue();
- double const* operator[](TDBIndex const& idx) const;
+ double const* operator[](database_index const& idx) const;
double& operator[](std::vector<int> const& idx);
int GetKey() const;
Modified: lmi/trunk/ihs_database.cpp
===================================================================
--- lmi/trunk/ihs_database.cpp 2010-05-03 18:08:23 UTC (rev 4897)
+++ lmi/trunk/ihs_database.cpp 2010-05-03 22:53:19 UTC (rev 4898)
@@ -118,7 +118,10 @@
break;
}
- Idx.State() = State;
+ // It may seem excessive to do this when only 'State' has changed,
+ // but it'll become unnecessary when we handle state of jurisdiction
+ // as an input field instead of trying to determine it here.
+ index_ = database_index(Gender, Class, Smoker, IssueAge, UWBasis, State);
}
//============================================================================
@@ -141,12 +144,7 @@
//============================================================================
void TDatabase::Init()
{
- Idx.Gender () = Gender ;
- Idx.Class () = Class ;
- Idx.Smoker () = Smoker ;
- Idx.IssueAge () = IssueAge ;
- Idx.UWBasis () = UWBasis ;
- Idx.State () = State ;
+ index_ = database_index(Gender, Class, Smoker, IssueAge, UWBasis, State);
// New code added to Query(int) uses length_ to test
// for validity. We can't go through that validity check when
@@ -154,7 +152,7 @@
// endowment age. But once we have length_, we can make sure
// endowment age doesn't vary by duration.
// length_ = Query(DB_EndtAge) - IssueAge;
- length_ = static_cast<int>(*GetEntry(DB_EndtAge)[Idx]) - IssueAge;
+ length_ = static_cast<int>(*GetEntry(DB_EndtAge)[index_]) - IssueAge;
if(length_ <= 0)
{
fatal_error() << "Endowment age precedes issue age." << LMI_FLUSH;
@@ -166,14 +164,14 @@
double TDatabase::Query(int k) const
{
ConstrainScalar(k); // TODO ?? Is the extra overhead acceptable?
- return *GetEntry(k)[Idx];
+ return *GetEntry(k)[index_];
}
//===========================================================================
void TDatabase::Query(std::vector<double>& dst, int k) const
{
TDBValue const& v = GetEntry(k);
- double const*const z = v[Idx];
+ double const*const z = v[index_];
// TODO ?? Can this be right?
if(1 == v.GetNDims())
{
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [lmi-commits] [4898] Revamp database-index class,
Greg Chicares <=