lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [6434] Refactor to improve maintainability


From: Greg Chicares
Subject: [lmi-commits] [6434] Refactor to improve maintainability
Date: Thu, 10 Dec 2015 21:58:18 +0000

Revision: 6434
          http://svn.sv.gnu.org/viewvc/?view=rev&root=lmi&revision=6434
Author:   chicares
Date:     2015-12-10 21:58:17 +0000 (Thu, 10 Dec 2015)
Log Message:
-----------
Refactor to improve maintainability

Modified Paths:
--------------
    lmi/trunk/ChangeLog
    lmi/trunk/any_member.hpp
    lmi/trunk/any_member_test.cpp
    lmi/trunk/census_view.cpp

Modified: lmi/trunk/ChangeLog
===================================================================
--- lmi/trunk/ChangeLog 2015-12-10 20:22:22 UTC (rev 6433)
+++ lmi/trunk/ChangeLog 2015-12-10 21:58:17 UTC (rev 6434)
@@ -37674,3 +37674,21 @@
   ihs_basicval.cpp
 Conditionalize compensation calculation.
 
+20151208T1552Z <address@hidden> [456]
+
+  ihs_acctval.cpp
+Ignore immaterial premium shortfalls.
+
+20151210T2022Z <address@hidden> [456]
+
+  calendar_date.hpp
+  census_view.cpp
+Allow pasting YYYYMMDD dates into a census.
+
+20151210T2158Z <address@hidden> [456]
+
+  any_member.hpp
+  any_member_test.cpp
+  census_view.cpp
+Refactor to improve maintainability.
+

Modified: lmi/trunk/any_member.hpp
===================================================================
--- lmi/trunk/any_member.hpp    2015-12-10 20:22:22 UTC (rev 6433)
+++ lmi/trunk/any_member.hpp    2015-12-10 21:58:17 UTC (rev 6434)
@@ -414,7 +414,8 @@
 /// to member of a class D that is derived from B, particularly in
 /// order to call a virtual function declared in B.
 ///
-/// If the MemberType argument is not an exact match, then it tries
+/// If the MemberType argument is not an exact match (ascertainable
+/// by exact_cast<MemberType>()), then this class template can try
 /// types derived from MemberType, using knowledge embedded in its
 /// reconstitute() member function. A specialization for a base class
 /// B can search derived types for an exact D ClassType::* match.
@@ -449,6 +450,25 @@
         }
 };
 
+/// Implementation of free function template is_reconstitutable_as().
+///
+/// Function template member_cast() throws if a requested conversion
+/// cannot be performed. This convenience function is useful for
+/// testing whether member_cast() can convert to a given base class
+/// without throwing.
+
+template<typename MemberType, typename ClassType>
+bool is_reconstitutable_as(any_member<ClassType>& member)
+{
+    return 0 != reconstitutor<MemberType,ClassType>::reconstitute(member);
+}
+
+template<typename MemberType, typename ClassType>
+bool is_reconstitutable_as(any_member<ClassType> const& member)
+{
+    return 
is_reconstitutable_as<MemberType>(const_cast<any_member<ClassType>&>(member));
+}
+
 /// Implementation of free function template exact_cast().
 ///
 /// Generally prefer free function template member_cast().
@@ -481,9 +501,9 @@
 ///
 /// Throws if the return value would be zero.
 ///
-/// This function template is not intended for testing convertibility,
-/// which can easily be done with member function type(). Instead, it
-/// is intended to perform a conversion that's known to be valid, and
+/// This function template is not intended for testing convertibility
+/// (use is_reconstitutable_as() for that purpose). Instead, it is
+/// intended to perform a conversion that's known to be valid, and
 /// it validates that precondition--so obtaining a null pointer is
 /// treated as failure, and throws an exception.
 

Modified: lmi/trunk/any_member_test.cpp
===================================================================
--- lmi/trunk/any_member_test.cpp       2015-12-10 20:22:22 UTC (rev 6433)
+++ lmi/trunk/any_member_test.cpp       2015-12-10 21:58:17 UTC (rev 6434)
@@ -499,6 +499,13 @@
 
     // Of course, member_cast() should work with the exact type, too.
     BOOST_TEST_EQUAL(1729, 
member_cast<derived_datum>(s["dd"])->virtual_function());
+
+    // Function template is_reconstitutable_as() ascertains whether
+    // the unknown original type is derived from a given base class.
+    BOOST_TEST(is_reconstitutable_as<base_datum>(s["dd"]));
+
+    // is_reconstitutable_as() should not work with the exact type.
+    BOOST_TEST(!is_reconstitutable_as<derived_datum>(s["dd"]));
     }
 
     {

Modified: lmi/trunk/census_view.cpp
===================================================================
--- lmi/trunk/census_view.cpp   2015-12-10 20:22:22 UTC (rev 6433)
+++ lmi/trunk/census_view.cpp   2015-12-10 21:58:17 UTC (rev 6434)
@@ -664,21 +664,19 @@
 
 renderer_type_convertor const& renderer_type_convertor::get(any_member<Input> 
const& value)
 {
-    any_member<Input>& nonconst_value = const_cast<any_member<Input>&>(value);
-
-    if(typeid(mce_yes_or_no Input::*) == value.type())
+    if(exact_cast<mce_yes_or_no>(value))
         {
         return get_impl<renderer_bool_convertor>();
         }
-    else if(0 != reconstitutor<mc_enum_base  
,Input>::reconstitute(nonconst_value))
+    else if(is_reconstitutable_as<mc_enum_base  >(value))
         {
         return get_impl<renderer_enum_convertor>();
         }
-    else if(0 != 
reconstitutor<datum_sequence,Input>::reconstitute(nonconst_value))
+    else if(is_reconstitutable_as<datum_sequence>(value))
         {
         return get_impl<renderer_sequence_convertor>();
         }
-    else if(0 != reconstitutor<tn_range_base 
,Input>::reconstitute(nonconst_value))
+    else if(is_reconstitutable_as<tn_range_base >(value))
         {
         tn_range_base const* as_range = member_cast<tn_range_base>(value);
         if(typeid(int) == as_range->value_type())
@@ -687,8 +685,11 @@
             return get_impl<renderer_double_range_convertor>();
         else if(typeid(calendar_date) == as_range->value_type())
             return get_impl<renderer_date_convertor>();
-        // else: fall through
         }
+    else
+        {
+        ; // Fall through.
+        }
 
     return get_impl<renderer_fallback_convertor>();
 }




reply via email to

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