lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [4866] Permit annotations in '.rounding' files


From: Greg Chicares
Subject: [lmi-commits] [4866] Permit annotations in '.rounding' files
Date: Tue, 27 Apr 2010 13:59:12 +0000

Revision: 4866
          http://svn.sv.gnu.org/viewvc/?view=rev&root=lmi&revision=4866
Author:   chicares
Date:     2010-04-27 13:59:12 +0000 (Tue, 27 Apr 2010)
Log Message:
-----------
Permit annotations in '.rounding' files

Modified Paths:
--------------
    lmi/trunk/ChangeLog
    lmi/trunk/ihs_basicval.cpp
    lmi/trunk/my_rnd.cpp
    lmi/trunk/rounding_document.hpp
    lmi/trunk/rounding_rules.cpp
    lmi/trunk/rounding_rules.hpp
    lmi/trunk/rounding_view_editor.cpp
    lmi/trunk/rounding_view_editor.hpp

Modified: lmi/trunk/ChangeLog
===================================================================
--- lmi/trunk/ChangeLog 2010-04-26 13:42:53 UTC (rev 4865)
+++ lmi/trunk/ChangeLog 2010-04-27 13:59:12 UTC (rev 4866)
@@ -25077,3 +25077,14 @@
   value_cast_test.cpp
 Work around a libc QoI issue.
 
+20100427T1359Z <address@hidden> [755]
+
+  ihs_basicval.cpp
+  my_rnd.cpp
+  rounding_document.hpp
+  rounding_rules.cpp
+  rounding_rules.hpp
+  rounding_view_editor.cpp
+  rounding_view_editor.hpp
+Permit annotations in '.rounding' files.
+

Modified: lmi/trunk/ihs_basicval.cpp
===================================================================
--- lmi/trunk/ihs_basicval.cpp  2010-04-26 13:42:53 UTC (rev 4865)
+++ lmi/trunk/ihs_basicval.cpp  2010-04-27 13:59:12 UTC (rev 4866)
@@ -840,27 +840,35 @@
     SetMaxSurvivalDur();
 }
 
+namespace
+{
+void set_rounding_rule(round_to<double>& functor, rounding_parameters const& z)
+{
+    functor = round_to<double>(z.decimals(), z.style().value());
+}
+} // Unnamed namespace.
+
 void BasicValues::SetRoundingFunctors()
 {
-    round_specamt_            = RoundingRules_->datum("RoundSpecAmt"    );
-    round_death_benefit_      = RoundingRules_->datum("RoundDeathBft"   );
-    round_naar_               = RoundingRules_->datum("RoundNaar"       );
-    round_coi_rate_           = RoundingRules_->datum("RoundCoiRate"    );
-    round_coi_charge_         = RoundingRules_->datum("RoundCoiCharge"  );
-    round_gross_premium_      = RoundingRules_->datum("RoundGrossPrem"  );
-    round_net_premium_        = RoundingRules_->datum("RoundNetPrem"    );
-    round_interest_rate_      = RoundingRules_->datum("RoundIntRate"    );
-    round_interest_credit_    = RoundingRules_->datum("RoundIntCredit"  );
-    round_withdrawal_         = RoundingRules_->datum("RoundWithdrawal" );
-    round_loan_               = RoundingRules_->datum("RoundLoan"       );
-    round_corridor_factor_    = RoundingRules_->datum("RoundCorrFactor" );
-    round_surrender_charge_   = RoundingRules_->datum("RoundSurrCharge" );
-    round_irr_                = RoundingRules_->datum("RoundIrr"        );
-    round_min_specamt_        = RoundingRules_->datum("RoundMinSpecamt" );
-    round_max_specamt_        = RoundingRules_->datum("RoundMaxSpecamt" );
-    round_min_premium_        = RoundingRules_->datum("RoundMinPrem"    );
-    round_max_premium_        = RoundingRules_->datum("RoundMaxPrem"    );
-    round_interest_rate_7702_ = RoundingRules_->datum("RoundIntRate7702");
+    set_rounding_rule(round_specamt_           , 
RoundingRules_->datum("RoundSpecAmt"    ));
+    set_rounding_rule(round_death_benefit_     , 
RoundingRules_->datum("RoundDeathBft"   ));
+    set_rounding_rule(round_naar_              , 
RoundingRules_->datum("RoundNaar"       ));
+    set_rounding_rule(round_coi_rate_          , 
RoundingRules_->datum("RoundCoiRate"    ));
+    set_rounding_rule(round_coi_charge_        , 
RoundingRules_->datum("RoundCoiCharge"  ));
+    set_rounding_rule(round_gross_premium_     , 
RoundingRules_->datum("RoundGrossPrem"  ));
+    set_rounding_rule(round_net_premium_       , 
RoundingRules_->datum("RoundNetPrem"    ));
+    set_rounding_rule(round_interest_rate_     , 
RoundingRules_->datum("RoundIntRate"    ));
+    set_rounding_rule(round_interest_credit_   , 
RoundingRules_->datum("RoundIntCredit"  ));
+    set_rounding_rule(round_withdrawal_        , 
RoundingRules_->datum("RoundWithdrawal" ));
+    set_rounding_rule(round_loan_              , 
RoundingRules_->datum("RoundLoan"       ));
+    set_rounding_rule(round_corridor_factor_   , 
RoundingRules_->datum("RoundCorrFactor" ));
+    set_rounding_rule(round_surrender_charge_  , 
RoundingRules_->datum("RoundSurrCharge" ));
+    set_rounding_rule(round_irr_               , 
RoundingRules_->datum("RoundIrr"        ));
+    set_rounding_rule(round_min_specamt_       , 
RoundingRules_->datum("RoundMinSpecamt" ));
+    set_rounding_rule(round_max_specamt_       , 
RoundingRules_->datum("RoundMaxSpecamt" ));
+    set_rounding_rule(round_min_premium_       , 
RoundingRules_->datum("RoundMinPrem"    ));
+    set_rounding_rule(round_max_premium_       , 
RoundingRules_->datum("RoundMaxPrem"    ));
+    set_rounding_rule(round_interest_rate_7702_, 
RoundingRules_->datum("RoundIntRate7702"));
 }
 
 //============================================================================

Modified: lmi/trunk/my_rnd.cpp
===================================================================
--- lmi/trunk/my_rnd.cpp        2010-04-26 13:42:53 UTC (rev 4865)
+++ lmi/trunk/my_rnd.cpp        2010-04-27 13:59:12 UTC (rev 4866)
@@ -53,8 +53,8 @@
 #if 0
     // Template for adding another policy form.
     rounding_rules another;
-    another.round_specamt_         = round_to<double>(0, r_upward    );
-    another.round_death_benefit_   = round_to<double>(2, r_to_nearest);
+    another.round_specamt_         = rounding_parameters(0, r_upward    , "");
+    another.round_death_benefit_   = rounding_parameters(2, r_to_nearest, "");
     // ...
     another.save(AddDataDir("another.rounding"));
 #endif // 0

Modified: lmi/trunk/rounding_document.hpp
===================================================================
--- lmi/trunk/rounding_document.hpp     2010-04-26 13:42:53 UTC (rev 4865)
+++ lmi/trunk/rounding_document.hpp     2010-04-27 13:59:12 UTC (rev 4866)
@@ -42,7 +42,7 @@
     RoundingDocument();
     virtual ~RoundingDocument();
 
-    typedef std::map<std::string, round_to<double>*> values_type;
+    typedef std::map<std::string, rounding_parameters*> values_type;
     values_type&       values();
     values_type const& values() const;
 

Modified: lmi/trunk/rounding_rules.cpp
===================================================================
--- lmi/trunk/rounding_rules.cpp        2010-04-26 13:42:53 UTC (rev 4865)
+++ lmi/trunk/rounding_rules.cpp        2010-04-27 13:59:12 UTC (rev 4866)
@@ -32,8 +32,6 @@
 #include "alert.hpp"
 #include "assert_lmi.hpp"
 #include "data_directory.hpp" // AddDataDir()
-#include "mc_enum.hpp"
-#include "mc_enum_types.hpp"
 #include "xml_serialize.hpp"
 
 #include <boost/filesystem/convenience.hpp>
@@ -43,21 +41,24 @@
 
 namespace xml_serialize
 {
-template<> struct xml_io<round_to<double> >
+template<> struct xml_io<rounding_parameters>
 {
-    static void to_xml(xml::element& e, round_to<double> const& t)
+    static void to_xml(xml::element& e, rounding_parameters const& t)
     {
-        set_element(e, "decimals",                    t.decimals() );
-        set_element(e, "style"   , mce_rounding_style(t.style   ()));
+        set_element(e, "decimals", t.decimals());
+        set_element(e, "style"   , t.style   ());
+        set_element(e, "gloss"   , t.gloss   ());
     }
 
-    static void from_xml(xml::element const& e, round_to<double>& t)
+    static void from_xml(xml::element const& e, rounding_parameters& t)
     {
         int                decimals;
         mce_rounding_style style   ;
+        std::string        gloss   ;
         get_element(e, "decimals", decimals);
         get_element(e, "style"   , style   );
-        t = round_to<double>(decimals, style.value());
+        get_element(e, "gloss"   , gloss   );
+        t = rounding_parameters(decimals, style.value(), gloss);
     }
 };
 } // namespace xml_serialize
@@ -68,7 +69,7 @@
 ///   any_member::str()
 /// which is not useful here.
 
-template<> std::string value_cast<std::string>(round_to<double> const&)
+template<> std::string value_cast<std::string>(rounding_parameters const&)
 {
     fatal_error() << "Invalid function call." << LMI_FLUSH;
     throw "Unreachable--silences a compiler diagnostic.";
@@ -80,34 +81,85 @@
 ///   any_member::operator=(std::string const&)
 /// which is not useful here.
 
-template<> round_to<double> value_cast<round_to<double> >(std::string const&)
+template<> rounding_parameters value_cast<rounding_parameters>(std::string 
const&)
 {
     fatal_error() << "Invalid function call." << LMI_FLUSH;
     throw "Unreachable--silences a compiler diagnostic.";
 }
 
+/// Private default ctor, for friends only.
+
+rounding_parameters::rounding_parameters()
+    :decimals_ (0              )
+    ,style_    (r_indeterminate)
+    ,gloss_    (""             )
+{
+}
+
+/// Construct from components.
+///
+/// The type of the 'style' argument is 'rounding_style', rather than
+/// 'mce_rounding_style'; the former is easier to work with, though
+/// the latter might have been expected here because it is the type of
+/// the corresponding member datum.
+
+rounding_parameters::rounding_parameters
+    (int                decimals
+    ,rounding_style     style
+    ,std::string const& gloss
+    )
+    :decimals_ (decimals)
+    ,style_    (style   )
+    ,gloss_    (gloss   )
+{
+}
+
+rounding_parameters::~rounding_parameters()
+{
+}
+
+bool rounding_parameters::operator==(rounding_parameters const& z) const
+{
+    return z.decimals_ == decimals_ && z.style_ == style_ && z.gloss_ == 
gloss_;
+}
+
+int rounding_parameters::decimals() const
+{
+    return decimals_;
+}
+
+mce_rounding_style const& rounding_parameters::style() const
+{
+    return style_;
+}
+
+std::string const& rounding_parameters::gloss() const
+{
+    return gloss_;
+}
+
 /// Private default ctor.
 
 rounding_rules::rounding_rules()
-    :round_specamt_           (0, r_upward    )
-    ,round_death_benefit_     (2, r_to_nearest)
-    ,round_naar_              (2, r_to_nearest)
-    ,round_coi_rate_          (8, r_downward  )
-    ,round_coi_charge_        (2, r_to_nearest)
-    ,round_gross_premium_     (2, r_to_nearest)
-    ,round_net_premium_       (2, r_to_nearest)
-    ,round_interest_rate_     (0, r_not_at_all)
-    ,round_interest_credit_   (2, r_to_nearest)
-    ,round_withdrawal_        (2, r_to_nearest)
-    ,round_loan_              (2, r_to_nearest)
-    ,round_corridor_factor_   (2, r_to_nearest)
-    ,round_surrender_charge_  (2, r_to_nearest)
-    ,round_irr_               (5, r_downward  )
-    ,round_min_specamt_       (0, r_upward    )
-    ,round_max_specamt_       (0, r_downward  )
-    ,round_min_premium_       (2, r_upward    )
-    ,round_max_premium_       (2, r_downward  )
-    ,round_interest_rate_7702_(0, r_not_at_all)
+    :round_specamt_           (0, r_upward    , "")
+    ,round_death_benefit_     (2, r_to_nearest, "")
+    ,round_naar_              (2, r_to_nearest, "")
+    ,round_coi_rate_          (8, r_downward  , "")
+    ,round_coi_charge_        (2, r_to_nearest, "")
+    ,round_gross_premium_     (2, r_to_nearest, "")
+    ,round_net_premium_       (2, r_to_nearest, "")
+    ,round_interest_rate_     (0, r_not_at_all, "")
+    ,round_interest_credit_   (2, r_to_nearest, "")
+    ,round_withdrawal_        (2, r_to_nearest, "")
+    ,round_loan_              (2, r_to_nearest, "")
+    ,round_corridor_factor_   (2, r_to_nearest, "")
+    ,round_surrender_charge_  (2, r_to_nearest, "")
+    ,round_irr_               (5, r_downward  , "")
+    ,round_min_specamt_       (0, r_upward    , "")
+    ,round_max_specamt_       (0, r_downward  , "")
+    ,round_min_premium_       (2, r_upward    , "")
+    ,round_max_premium_       (2, r_downward  , "")
+    ,round_interest_rate_7702_(0, r_not_at_all, "")
 {
     ascribe_members();
 }
@@ -125,6 +177,18 @@
 {
     ascribe_members();
 
+    // Settings such as these (called in all ctors):
+    //   round_interest_rate_7702_.style_.allow(0, false); // r_indeterminate
+    //   round_interest_rate_7702_.style_.allow(1, false); // r_toward_zero
+    //   round_interest_rate_7702_.style_.allow(2, false); // r_to_nearest
+    //   round_interest_rate_7702_.style_.allow(3, true ); // r_upward
+    //   round_interest_rate_7702_.style_.allow(4, false); // r_downward
+    //   round_interest_rate_7702_.style_.allow(5, false); // r_current
+    //   round_interest_rate_7702_.style_.allow(6, true ); // r_not_at_all
+    // wouldn't affect class RoundingDocument or class RoundingButtons,
+    // which don't use lmi's mvc framework. The assertions written after
+    // load() is called provide adequate though inconvenient safety.
+
     load(filename);
 
     LMI_ASSERT(r_not_at_all == round_min_specamt_       .style() || r_upward   
== round_min_specamt_       .style());
@@ -140,9 +204,9 @@
 
 /// Member datum nominated by the given name.
 
-round_to<double> const& rounding_rules::datum(std::string const& name)
+rounding_parameters const& rounding_rules::datum(std::string const& name)
 {
-    return *member_cast<round_to<double> >(operator[](name));
+    return *member_cast<rounding_parameters>(operator[](name));
 }
 
 /// Enregister certain data members for access via any_member<>[].
@@ -193,7 +257,7 @@
     ,int                 // file_version
     )
 {
-    round_to<double>& r = *member_cast<round_to<double> >(operator[](name));
+    rounding_parameters& r = 
*member_cast<rounding_parameters>(operator[](name));
     xml_serialize::from_xml(e, r);
 }
 
@@ -202,7 +266,7 @@
     ,std::string const&  name
     ) const
 {
-    round_to<double> const& r = *member_cast<round_to<double> 
>(operator[](name));
+    rounding_parameters const& r = 
*member_cast<rounding_parameters>(operator[](name));
     xml_serialize::set_element(parent, name, r);
 }
 

Modified: lmi/trunk/rounding_rules.hpp
===================================================================
--- lmi/trunk/rounding_rules.hpp        2010-04-26 13:42:53 UTC (rev 4865)
+++ lmi/trunk/rounding_rules.hpp        2010-04-27 13:59:12 UTC (rev 4866)
@@ -27,8 +27,9 @@
 #include "config.hpp"
 
 #include "any_member.hpp"
+#include "mc_enum.hpp"
+#include "mc_enum_types.hpp"
 #include "obstruct_slicing.hpp"
-#include "round_to.hpp"
 #include "so_attributes.hpp"
 #include "xml_serializable.hpp"
 
@@ -36,6 +37,37 @@
 
 #include <string>
 
+/// Parameters of a rounding rule.
+///
+/// Implicitly-declared special member functions do the right thing.
+
+class rounding_parameters
+    :virtual private obstruct_slicing<rounding_parameters>
+{
+    friend class rounding_rules;
+
+  public:
+    rounding_parameters
+        (int                decimals
+        ,rounding_style     style
+        ,std::string const& gloss = std::string()
+        );
+    ~rounding_parameters();
+
+    bool operator==(rounding_parameters const&) const;
+
+    int                       decimals() const;
+    mce_rounding_style const& style   () const;
+    std::string const&        gloss   () const;
+
+  private:
+    rounding_parameters();
+
+    int                decimals_;
+    mce_rounding_style style_   ;
+    std::string        gloss_   ;
+};
+
 /// Product rounding rules.
 ///
 /// The principle is to round transactional changes to account value,
@@ -45,6 +77,8 @@
 /// rounding is a property of the transaction, and not of the variable
 /// it ultimately affects.
 ///
+/// Implicitly-declared special member functions do the right thing.
+///
 /// Notes on particular rounding functors.
 ///
 /// IRR must be rounded down in order to avoid overstating it, but its
@@ -69,7 +103,7 @@
     explicit rounding_rules(std::string const& filename);
     ~rounding_rules();
 
-    round_to<double> const& datum(std::string const& name);
+    rounding_parameters const& datum(std::string const& name);
 
     // Legacy functions to support creating product files programmatically.
     static void write_rounding_files();
@@ -95,25 +129,25 @@
         ,std::string const&  name
         ) const;
 
-    round_to<double> round_specamt_           ;
-    round_to<double> round_death_benefit_     ;
-    round_to<double> round_naar_              ;
-    round_to<double> round_coi_rate_          ;
-    round_to<double> round_coi_charge_        ;
-    round_to<double> round_gross_premium_     ;
-    round_to<double> round_net_premium_       ;
-    round_to<double> round_interest_rate_     ;
-    round_to<double> round_interest_credit_   ;
-    round_to<double> round_withdrawal_        ;
-    round_to<double> round_loan_              ;
-    round_to<double> round_corridor_factor_   ;
-    round_to<double> round_surrender_charge_  ;
-    round_to<double> round_irr_               ;
-    round_to<double> round_min_specamt_       ;
-    round_to<double> round_max_specamt_       ;
-    round_to<double> round_min_premium_       ;
-    round_to<double> round_max_premium_       ;
-    round_to<double> round_interest_rate_7702_;
+    rounding_parameters round_specamt_           ;
+    rounding_parameters round_death_benefit_     ;
+    rounding_parameters round_naar_              ;
+    rounding_parameters round_coi_rate_          ;
+    rounding_parameters round_coi_charge_        ;
+    rounding_parameters round_gross_premium_     ;
+    rounding_parameters round_net_premium_       ;
+    rounding_parameters round_interest_rate_     ;
+    rounding_parameters round_interest_credit_   ;
+    rounding_parameters round_withdrawal_        ;
+    rounding_parameters round_loan_              ;
+    rounding_parameters round_corridor_factor_   ;
+    rounding_parameters round_surrender_charge_  ;
+    rounding_parameters round_irr_               ;
+    rounding_parameters round_min_specamt_       ;
+    rounding_parameters round_max_specamt_       ;
+    rounding_parameters round_min_premium_       ;
+    rounding_parameters round_max_premium_       ;
+    rounding_parameters round_interest_rate_7702_;
 };
 
 #endif // rounding_rules_hpp

Modified: lmi/trunk/rounding_view_editor.cpp
===================================================================
--- lmi/trunk/rounding_view_editor.cpp  2010-04-26 13:42:53 UTC (rev 4865)
+++ lmi/trunk/rounding_view_editor.cpp  2010-04-27 13:59:12 UTC (rev 4866)
@@ -287,16 +287,16 @@
     SetStyle(style);
 }
 
-void RoundingButtons::SetValue(round_to<double> const& value)
+void RoundingButtons::SetValue(rounding_parameters const& value)
 {
     previous_value_ = value;
     SetNumber(value.decimals());
-    SetStyle(value.style());
+    SetStyle(value.style().value());
 }
 
-round_to<double> RoundingButtons::GetValue() const
+rounding_parameters RoundingButtons::GetValue() const
 {
-    return round_to<double>(GetNumber(), GetStyle());
+    return rounding_parameters(GetNumber(), GetStyle(), "");
 }
 
 void RoundingButtons::SetNumber(int number)

Modified: lmi/trunk/rounding_view_editor.hpp
===================================================================
--- lmi/trunk/rounding_view_editor.hpp  2010-04-26 13:42:53 UTC (rev 4865)
+++ lmi/trunk/rounding_view_editor.hpp  2010-04-27 13:59:12 UTC (rev 4866)
@@ -26,7 +26,7 @@
 
 #include "config.hpp"
 
-#include "round_to.hpp"
+#include "rounding_rules.hpp"
 
 #include <wx/panel.h>
 #include <wx/xrc/xmlres.h>
@@ -65,8 +65,8 @@
     void Modify(bool modified = true);
     void DiscardEdits();
 
-    void             SetValue(round_to<double> const& value);
-    round_to<double> GetValue() const;
+    void                SetValue(rounding_parameters const& value);
+    rounding_parameters GetValue() const;
 
   private:
     void SetNumber(int number);
@@ -90,7 +90,7 @@
 
     // initial or last saved value (IsModified() returns true iff current
     // value is different from this)
-    round_to<double> previous_value_;
+    rounding_parameters previous_value_;
 
     rounding_style style_;
     wxBitmapButton* button_not_at_all_;





reply via email to

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