lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [5611] Refactor, replacing a bool with an enum


From: Greg Chicares
Subject: [lmi-commits] [5611] Refactor, replacing a bool with an enum
Date: Tue, 04 Dec 2012 14:12:21 +0000

Revision: 5611
          http://svn.sv.gnu.org/viewvc/?view=rev&root=lmi&revision=5611
Author:   chicares
Date:     2012-12-04 14:12:20 +0000 (Tue, 04 Dec 2012)
Log Message:
-----------
Refactor, replacing a bool with an enum

Modified Paths:
--------------
    lmi/trunk/calendar_date.cpp
    lmi/trunk/calendar_date.hpp
    lmi/trunk/calendar_date_test.cpp
    lmi/trunk/dbdict.cpp
    lmi/trunk/input_harmonization.cpp
    lmi/trunk/mec_input.cpp
    lmi/trunk/oecumenic_enumerations.hpp

Modified: lmi/trunk/calendar_date.cpp
===================================================================
--- lmi/trunk/calendar_date.cpp 2012-12-04 10:55:17 UTC (rev 5610)
+++ lmi/trunk/calendar_date.cpp 2012-12-04 14:12:20 UTC (rev 5611)
@@ -453,7 +453,7 @@
 int notional_age
     (calendar_date const& birthdate
     ,calendar_date const& as_of_date
-    ,bool                 alb_anb
+    ,oenum_alb_or_anb     alb_anb
     )
 {
     typedef std::pair<calendar_date,calendar_date> date_pair;
@@ -499,7 +499,7 @@
 int attained_age
     (calendar_date const& birthdate
     ,calendar_date const& as_of_date
-    ,bool                 alb_anb
+    ,oenum_alb_or_anb     alb_anb
     )
 {
     if(as_of_date < birthdate)
@@ -675,10 +675,10 @@
 {
   public:
     birthdate_limit
-        (calendar_date as_of_date
-        ,int           limit_age
-        ,bool          alb_anb
-        ,root_bias     bias
+        (calendar_date    as_of_date
+        ,int              limit_age
+        ,oenum_alb_or_anb alb_anb
+        ,root_bias        bias
         )
         :as_of_date_       (as_of_date)
         ,limit_age_        (limit_age)
@@ -726,13 +726,13 @@
         }
 
   private:
-    calendar_date as_of_date_;
-    int           limit_age_;
-    bool          alb_anb_;
-    root_bias     bias_;
-    int           a_priori_minimum_;
-    int           a_priori_maximum_;
-    double        offset_;
+    calendar_date    as_of_date_;
+    int              limit_age_;
+    oenum_alb_or_anb alb_anb_;
+    root_bias        bias_;
+    int              a_priori_minimum_;
+    int              a_priori_maximum_;
+    double           offset_;
 };
 } // Unnamed namespace.
 
@@ -741,7 +741,7 @@
 calendar_date minimum_birthdate
     (int                  minimum_age
     ,calendar_date const& as_of_date
-    ,bool                 alb_anb
+    ,oenum_alb_or_anb     alb_anb
     )
 {
     return birthdate_limit(as_of_date, minimum_age, alb_anb, bias_lower)();
@@ -752,7 +752,7 @@
 calendar_date maximum_birthdate
     (int                  maximum_age
     ,calendar_date const& as_of_date
-    ,bool                 alb_anb
+    ,oenum_alb_or_anb     alb_anb
     )
 {
     return birthdate_limit(as_of_date, maximum_age, alb_anb, bias_higher)();

Modified: lmi/trunk/calendar_date.hpp
===================================================================
--- lmi/trunk/calendar_date.hpp 2012-12-04 10:55:17 UTC (rev 5610)
+++ lmi/trunk/calendar_date.hpp 2012-12-04 14:12:20 UTC (rev 5611)
@@ -26,6 +26,7 @@
 
 #include "config.hpp"
 
+#include "oecumenic_enumerations.hpp"   // oenum_alb_or_anb
 #include "so_attributes.hpp"
 
 #include <boost/operators.hpp>
@@ -203,7 +204,7 @@
 int attained_age
     (calendar_date const& birthdate
     ,calendar_date const& as_of_date
-    ,bool                 alb_anb
+    ,oenum_alb_or_anb     alb_anb
     );
 
 std::pair<int,int> years_and_months_since
@@ -229,13 +230,13 @@
 calendar_date minimum_birthdate
     (int                  age
     ,calendar_date const& as_of_date
-    ,bool                 alb_anb
+    ,oenum_alb_or_anb     alb_anb
     );
 
 calendar_date maximum_birthdate
     (int                  age
     ,calendar_date const& as_of_date
-    ,bool                 alb_anb
+    ,oenum_alb_or_anb     alb_anb
     );
 
 std::string month_name(int);

Modified: lmi/trunk/calendar_date_test.cpp
===================================================================
--- lmi/trunk/calendar_date_test.cpp    2012-12-04 10:55:17 UTC (rev 5610)
+++ lmi/trunk/calendar_date_test.cpp    2012-12-04 14:12:20 UTC (rev 5611)
@@ -54,8 +54,8 @@
         TestIntegralDuration();
         TestYearAndMonthDifferenceExhaustively();
         TestBirthdateLimits();
-        TestBirthdateLimitsExhaustively(false);
-        TestBirthdateLimitsExhaustively(true);
+        TestBirthdateLimitsExhaustively(oe_age_last_birthday);
+        TestBirthdateLimitsExhaustively(oe_age_nearest_birthday_ties_older);
         TestIo();
         TestSpeed();
         }
@@ -70,7 +70,7 @@
     static void TestIntegralDuration();
     static void TestYearAndMonthDifferenceExhaustively();
     static void TestBirthdateLimits();
-    static void TestBirthdateLimitsExhaustively(bool alb_anb);
+    static void TestBirthdateLimitsExhaustively(oenum_alb_or_anb alb_anb);
     static void TestIo();
     static void TestSpeed();
 };
@@ -421,13 +421,13 @@
 
     birth_date = add_years(as_of_date, -1, false);
     BOOST_TEST_EQUAL(birth_date, calendar_date(1995,  3,  1));
-    BOOST_TEST_UNEQUAL(1, attained_age(birth_date, as_of_date, false));
+    BOOST_TEST_UNEQUAL(1, attained_age(birth_date, as_of_date, 
oe_age_last_birthday));
 
     // A "curtate" calculation gives a correct answer.
 
     birth_date = add_years(as_of_date, -1, true);
     BOOST_TEST_EQUAL(birth_date, calendar_date(1995,  2, 28));
-    BOOST_TEST_EQUAL(1, attained_age(birth_date, as_of_date, false));
+    BOOST_TEST_EQUAL  (1, attained_age(birth_date, as_of_date, 
oe_age_last_birthday));
 
     // It is important not to overgeneralize and suppose that curtate
     // calculations somehow fit best with negative increments: that's
@@ -438,21 +438,15 @@
 
     birth_date = add_years(some_other_date, 39, false);
     BOOST_TEST_EQUAL(birth_date, calendar_date(1995,  3,  1));
-    BOOST_TEST_UNEQUAL(1, attained_age(birth_date, as_of_date, false));
+    BOOST_TEST_UNEQUAL(1, attained_age(birth_date, as_of_date, 
oe_age_last_birthday));
 
     birth_date = add_years(some_other_date, 39, true);
     BOOST_TEST_EQUAL(birth_date, calendar_date(1995,  2, 28));
-    BOOST_TEST_EQUAL(1, attained_age(birth_date, as_of_date, false));
+    BOOST_TEST_EQUAL  (1, attained_age(birth_date, as_of_date, 
oe_age_last_birthday));
 }
 
 void CalendarDateTest::TestAgeCalculations()
 {
-    // If the third argument to attained_age() is
-    //   true,  then calculate age nearest birthday (ANB);
-    //   false, then calculate age last birthday    (ALB).
-    bool const anb = true;
-    bool const alb = false;
-
     // Suppose
     //   1958-07-02 is my birthdate, and
     //   2003-01-01 is the effective date.
@@ -466,14 +460,14 @@
     calendar_date birth_date;
 
     birth_date     = calendar_date(1958,  7,  2);
-    BOOST_TEST_EQUAL(45, attained_age(birth_date, effective_date, anb));
-    BOOST_TEST_EQUAL(44, attained_age(birth_date, effective_date, alb));
+    BOOST_TEST_EQUAL(45, attained_age(birth_date, effective_date, 
oe_age_nearest_birthday_ties_older));
+    BOOST_TEST_EQUAL(44, attained_age(birth_date, effective_date, 
oe_age_last_birthday));
 
     // If birthdate is one day later, then ANB is one year less.
 
     birth_date     = calendar_date(1958,  7,  3);
-    BOOST_TEST_EQUAL(44, attained_age(birth_date, effective_date, anb));
-    BOOST_TEST_EQUAL(44, attained_age(birth_date, effective_date, alb));
+    BOOST_TEST_EQUAL(44, attained_age(birth_date, effective_date, 
oe_age_nearest_birthday_ties_older));
+    BOOST_TEST_EQUAL(44, attained_age(birth_date, effective_date, 
oe_age_last_birthday));
 
     // In a leap year, effective date can be an equal number of days
     // away from the two birthdays that bracket it. We arbitrarily
@@ -492,54 +486,54 @@
     effective_date = calendar_date(2004,  1,  1);
 
     birth_date     = calendar_date(1958,  7,  2);
-    BOOST_TEST_EQUAL(46, attained_age(birth_date, effective_date, anb));
-    BOOST_TEST_EQUAL(45, attained_age(birth_date, effective_date, alb));
+    BOOST_TEST_EQUAL(46, attained_age(birth_date, effective_date, 
oe_age_nearest_birthday_ties_older));
+    BOOST_TEST_EQUAL(45, attained_age(birth_date, effective_date, 
oe_age_last_birthday));
 
     // If birthdate is one day earlier,
     // then ANB is unambiguously forty-six.
 
     birth_date     = calendar_date(1958,  7,  1);
-    BOOST_TEST_EQUAL(46, attained_age(birth_date, effective_date, anb));
-    BOOST_TEST_EQUAL(45, attained_age(birth_date, effective_date, alb));
+    BOOST_TEST_EQUAL(46, attained_age(birth_date, effective_date, 
oe_age_nearest_birthday_ties_older));
+    BOOST_TEST_EQUAL(45, attained_age(birth_date, effective_date, 
oe_age_last_birthday));
 
     // If birthdate is one day later,
     // then ANB is unambiguously forty-five.
 
     birth_date     = calendar_date(1958,  7,  3);
-    BOOST_TEST_EQUAL(45, attained_age(birth_date, effective_date, anb));
-    BOOST_TEST_EQUAL(45, attained_age(birth_date, effective_date, alb));
+    BOOST_TEST_EQUAL(45, attained_age(birth_date, effective_date, 
oe_age_nearest_birthday_ties_older));
+    BOOST_TEST_EQUAL(45, attained_age(birth_date, effective_date, 
oe_age_last_birthday));
 
     // Test leap-year-day birthdate.
 
     birth_date     = calendar_date(1956,  2, 29);
 
     effective_date = calendar_date(2003,  8, 30);
-    BOOST_TEST_EQUAL(47, attained_age(birth_date, effective_date, anb));
-    BOOST_TEST_EQUAL(47, attained_age(birth_date, effective_date, alb));
+    BOOST_TEST_EQUAL(47, attained_age(birth_date, effective_date, 
oe_age_nearest_birthday_ties_older));
+    BOOST_TEST_EQUAL(47, attained_age(birth_date, effective_date, 
oe_age_last_birthday));
 
     effective_date = calendar_date(2003,  8, 31);
-    BOOST_TEST_EQUAL(48, attained_age(birth_date, effective_date, anb));
-    BOOST_TEST_EQUAL(47, attained_age(birth_date, effective_date, alb));
+    BOOST_TEST_EQUAL(48, attained_age(birth_date, effective_date, 
oe_age_nearest_birthday_ties_older));
+    BOOST_TEST_EQUAL(47, attained_age(birth_date, effective_date, 
oe_age_last_birthday));
 
     effective_date = calendar_date(2004,  2, 28);
-    BOOST_TEST_EQUAL(48, attained_age(birth_date, effective_date, anb));
-    BOOST_TEST_EQUAL(47, attained_age(birth_date, effective_date, alb));
+    BOOST_TEST_EQUAL(48, attained_age(birth_date, effective_date, 
oe_age_nearest_birthday_ties_older));
+    BOOST_TEST_EQUAL(47, attained_age(birth_date, effective_date, 
oe_age_last_birthday));
 
     effective_date = calendar_date(2004,  2, 29);
-    BOOST_TEST_EQUAL(48, attained_age(birth_date, effective_date, anb));
-    BOOST_TEST_EQUAL(48, attained_age(birth_date, effective_date, alb));
+    BOOST_TEST_EQUAL(48, attained_age(birth_date, effective_date, 
oe_age_nearest_birthday_ties_older));
+    BOOST_TEST_EQUAL(48, attained_age(birth_date, effective_date, 
oe_age_last_birthday));
 
     effective_date = calendar_date(2004,  3,  1);
-    BOOST_TEST_EQUAL(48, attained_age(birth_date, effective_date, anb));
-    BOOST_TEST_EQUAL(48, attained_age(birth_date, effective_date, alb));
+    BOOST_TEST_EQUAL(48, attained_age(birth_date, effective_date, 
oe_age_nearest_birthday_ties_older));
+    BOOST_TEST_EQUAL(48, attained_age(birth_date, effective_date, 
oe_age_last_birthday));
 
     effective_date = calendar_date(2005,  2, 28);
-    BOOST_TEST_EQUAL(49, attained_age(birth_date, effective_date, anb));
-    BOOST_TEST_EQUAL(48, attained_age(birth_date, effective_date, alb));
+    BOOST_TEST_EQUAL(49, attained_age(birth_date, effective_date, 
oe_age_nearest_birthday_ties_older));
+    BOOST_TEST_EQUAL(48, attained_age(birth_date, effective_date, 
oe_age_last_birthday));
 
     effective_date = calendar_date(2005,  3,  1);
-    BOOST_TEST_EQUAL(49, attained_age(birth_date, effective_date, anb));
-    BOOST_TEST_EQUAL(49, attained_age(birth_date, effective_date, alb));
+    BOOST_TEST_EQUAL(49, attained_age(birth_date, effective_date, 
oe_age_nearest_birthday_ties_older));
+    BOOST_TEST_EQUAL(49, attained_age(birth_date, effective_date, 
oe_age_last_birthday));
 
     // Test leap-year-day effective date, even though business custom
     // would probably forbid using it as the basis for a series of
@@ -548,18 +542,18 @@
     effective_date = calendar_date(2004,  2, 29);
 
     birth_date     = calendar_date(1958,  8, 30);
-    BOOST_TEST_EQUAL(46, attained_age(birth_date, effective_date, anb));
-    BOOST_TEST_EQUAL(45, attained_age(birth_date, effective_date, alb));
+    BOOST_TEST_EQUAL(46, attained_age(birth_date, effective_date, 
oe_age_nearest_birthday_ties_older));
+    BOOST_TEST_EQUAL(45, attained_age(birth_date, effective_date, 
oe_age_last_birthday));
 
     birth_date     = calendar_date(1958,  8, 31);
-    BOOST_TEST_EQUAL(45, attained_age(birth_date, effective_date, anb));
-    BOOST_TEST_EQUAL(45, attained_age(birth_date, effective_date, alb));
+    BOOST_TEST_EQUAL(45, attained_age(birth_date, effective_date, 
oe_age_nearest_birthday_ties_older));
+    BOOST_TEST_EQUAL(45, attained_age(birth_date, effective_date, 
oe_age_last_birthday));
 
     // Effective date mustn't precede birthdate--this should throw:
     birth_date     = calendar_date(2003,  1,  2);
     effective_date = calendar_date(2003,  1,  1);
     BOOST_TEST_THROW
-        (attained_age(birth_date, effective_date, anb)
+        (attained_age(birth_date, effective_date, 
oe_age_nearest_birthday_ties_older)
         ,std::runtime_error
         ,"As-of date (2003-01-01) precedes birthdate (2003-01-02)."
         );
@@ -765,43 +759,43 @@
 void CalendarDateTest::TestBirthdateLimits()
 {
     BOOST_TEST_EQUAL
-        (minimum_birthdate(99, calendar_date(1852,  9, 13), false)
+        (minimum_birthdate(99, calendar_date(1852,  9, 13), 
oe_age_last_birthday)
         ,                      calendar_date(1752,  9, 14)
         );
     BOOST_TEST_EQUAL
-        (maximum_birthdate( 0, calendar_date(1852,  9, 13), false)
+        (maximum_birthdate( 0, calendar_date(1852,  9, 13), 
oe_age_last_birthday)
         ,                      calendar_date(1852,  9, 13)
         );
 
     BOOST_TEST_EQUAL
-        (minimum_birthdate(99, calendar_date(9999, 12, 31), false)
+        (minimum_birthdate(99, calendar_date(9999, 12, 31), 
oe_age_last_birthday)
         ,                      calendar_date(9900,  1,  1)
         );
     BOOST_TEST_EQUAL
-        (maximum_birthdate( 0, calendar_date(9999, 12, 31), false)
+        (maximum_birthdate( 0, calendar_date(9999, 12, 31), 
oe_age_last_birthday)
         ,                      calendar_date(9999, 12, 31)
         );
 
     BOOST_TEST_EQUAL
-        (minimum_birthdate(44, calendar_date(2003,  1,  1), true)
+        (minimum_birthdate(44, calendar_date(2003,  1,  1), 
oe_age_nearest_birthday_ties_older)
         ,                      calendar_date(1958,  7,  3)
         );
     BOOST_TEST_EQUAL
-        (maximum_birthdate(45, calendar_date(2003,  1,  1), true)
+        (maximum_birthdate(45, calendar_date(2003,  1,  1), 
oe_age_nearest_birthday_ties_older)
         ,                      calendar_date(1958,  7,  2)
         );
 
     BOOST_TEST_EQUAL
-        (minimum_birthdate(45, calendar_date(2004,  1,  1), true)
+        (minimum_birthdate(45, calendar_date(2004,  1,  1), 
oe_age_nearest_birthday_ties_older)
         ,                      calendar_date(1958,  7,  3)
         );
     BOOST_TEST_EQUAL
-        (maximum_birthdate(46, calendar_date(2004,  1,  1), true)
+        (maximum_birthdate(46, calendar_date(2004,  1,  1), 
oe_age_nearest_birthday_ties_older)
         ,                      calendar_date(1958,  7,  2)
         );
 }
 
-void CalendarDateTest::TestBirthdateLimitsExhaustively(bool alb_anb)
+void CalendarDateTest::TestBirthdateLimitsExhaustively(oenum_alb_or_anb 
alb_anb)
 {
     for
         (calendar_date d  (ymd_t(19991231))
@@ -913,7 +907,7 @@
         x++;
         std::string s = x.str();
         x = add_years_and_months(x, 1, 1, true);
-        attained_age(y, x, false);
+        attained_age(y, x, oe_age_last_birthday);
     }
 
     void mete_construct()
@@ -947,7 +941,7 @@
     void mete_attained_age()
     {
         x = add_years_and_months(x, 1, 1, true);
-        attained_age(y, x, false);
+        attained_age(y, x, oe_age_last_birthday);
     }
 
 } // Unnamed namespace.

Modified: lmi/trunk/dbdict.cpp
===================================================================
--- lmi/trunk/dbdict.cpp        2012-12-04 10:55:17 UTC (rev 5610)
+++ lmi/trunk/dbdict.cpp        2012-12-04 14:12:20 UTC (rev 5611)
@@ -657,7 +657,7 @@
     Add(database_entity(DB_CurrCoiIsAnnual     , true));
     Add(database_entity(DB_GuarCoiIsAnnual     , true));
     Add(database_entity(DB_MdptCoiIsAnnual     , true));
-    Add(database_entity(DB_AgeLastOrNearest    , 0, "0 = ALB"));
+    Add(database_entity(DB_AgeLastOrNearest    , oe_age_last_birthday));
     Add(database_entity(DB_AllowRetirees       , true));
     Add(database_entity(DB_MinSpecAmt          , 100000.0));
     Add(database_entity(DB_AllowSubstdTable    , true));
@@ -959,7 +959,7 @@
     Add(database_entity(DB_WpTable, 8));
     Add(database_entity(DB_AdbTable, 9));
     Add(database_entity(DB_MaturityAge, 100));
-    Add(database_entity(DB_AgeLastOrNearest, 1, "1 = ANB (ties --> older)"));
+    Add(database_entity(DB_AgeLastOrNearest, 
oe_age_nearest_birthday_ties_older));
     Add(database_entity(DB_MinSpecAmt, 10000.0));
 
     Add(database_entity(DB_AllowGenAcct, 1.0));

Modified: lmi/trunk/input_harmonization.cpp
===================================================================
--- lmi/trunk/input_harmonization.cpp   2012-12-04 10:55:17 UTC (rev 5610)
+++ lmi/trunk/input_harmonization.cpp   2012-12-04 14:12:20 UTC (rev 5611)
@@ -302,7 +302,12 @@
             )
         );
 
-    bool const alb_anb = database_->Query(DB_AgeLastOrNearest);
+    oenum_alb_or_anb const alb_anb =
+        static_cast<oenum_alb_or_anb>
+            (static_cast<int>
+                (database_->Query(DB_AgeLastOrNearest)
+                )
+            );
     DateOfBirth.minimum_and_maximum
         (minimum_birthdate(IssueAge.maximum(), EffectiveDate.value(), alb_anb)
         ,maximum_birthdate(IssueAge.minimum(), EffectiveDate.value(), alb_anb)
@@ -906,7 +911,12 @@
         GeneralAccountRate = current_credited_rate(*database_);
         }
 
-    bool const alb_anb = database_->Query(DB_AgeLastOrNearest);
+    oenum_alb_or_anb const alb_anb =
+        static_cast<oenum_alb_or_anb>
+            (static_cast<int>
+                (database_->Query(DB_AgeLastOrNearest)
+                )
+            );
 
     int apparent_age = attained_age
         (DateOfBirth.value()

Modified: lmi/trunk/mec_input.cpp
===================================================================
--- lmi/trunk/mec_input.cpp     2012-12-04 10:55:17 UTC (rev 5610)
+++ lmi/trunk/mec_input.cpp     2012-12-04 14:12:20 UTC (rev 5611)
@@ -31,6 +31,7 @@
 
 #include "alert.hpp"
 #include "assert_lmi.hpp"
+#include "calendar_date.hpp"            // attained_age()
 #include "contains.hpp"
 #include "database.hpp"
 #include "dbnames.hpp"
@@ -364,7 +365,12 @@
             )
         );
 
-    bool const alb_anb = database_->Query(DB_AgeLastOrNearest);
+    oenum_alb_or_anb const alb_anb =
+        static_cast<oenum_alb_or_anb>
+            (static_cast<int>
+                (database_->Query(DB_AgeLastOrNearest)
+                )
+            );
     DateOfBirth.minimum_and_maximum
         (minimum_birthdate(IssueAge.maximum(), EffectiveDate.value(), alb_anb)
         ,maximum_birthdate(IssueAge.minimum(), EffectiveDate.value(), alb_anb)
@@ -483,7 +489,12 @@
     InforceContractYear  = ym1.first;
     InforceContractMonth = ym1.second;
 
-    bool const alb_anb = database_->Query(DB_AgeLastOrNearest);
+    oenum_alb_or_anb const alb_anb =
+        static_cast<oenum_alb_or_anb>
+            (static_cast<int>
+                (database_->Query(DB_AgeLastOrNearest)
+                )
+            );
 
     int apparent_age = attained_age
         (DateOfBirth.value()

Modified: lmi/trunk/oecumenic_enumerations.hpp
===================================================================
--- lmi/trunk/oecumenic_enumerations.hpp        2012-12-04 10:55:17 UTC (rev 
5610)
+++ lmi/trunk/oecumenic_enumerations.hpp        2012-12-04 14:12:20 UTC (rev 
5611)
@@ -30,6 +30,11 @@
 
 enum {methuselah = 969};
 
+enum oenum_alb_or_anb
+    {oe_age_last_birthday
+    ,oe_age_nearest_birthday_ties_older
+    };
+
 enum oenum_allocation_method
     {oe_input_allocation
     ,oe_override_allocation




reply via email to

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