lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master 0482a6a 4/4: Remove default keyword from Sequ


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 0482a6a 4/4: Remove default keyword from SequenceParser; reorder it in InputSequence
Date: Fri, 3 Feb 2017 01:24:16 +0000 (UTC)

branch: master
commit 0482a6a9a8e78696b8bc1a2a60ccfcb0e140c329
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Remove default keyword from SequenceParser; reorder it in InputSequence
    
    Removed data member 'default_keyword' from class SequenceParser, which
    didn't use it. This sheds some light on the curiosity noted in the
    2017-02-02T13:39:43 commit: that a sequence can be parsed successfully
    even if its 'default_keyword' is not an element of the set of allowed
    keywords. SequenceParser simply parses an expression into possibly
    disjoint intervals; it doesn't attempt to fill any gaps. InputSequence
    ctors call realize_vector(), which uses 'default_keyword' to initialize
    the 'keyword_result' vector (which has exactly one value for every year
    and therefore cannot have any gap) and then overwrites whatever values
    may have been specified for (possibly disjoint) intervals obtained from
    the parser.
    
    However, realize_vector() does not alter the intervals it obtains from
    the parser, except to set the last interval's 'end_mode' to e_maturity;
    in particular, it doesn't insert new intervals to fill any gaps. Neither
    can any other InputSequence member function, because they're all const.
    
    Furthermore, unit tests primarily validate the "linear" vectors set by
    realize_vector(), whereas the GUI uses interval_representation(), which
    returns the (practically unmodified) raw intervals; this presumably
    explains why a sequence such as
      1 [1, 2); 3 [3, 3]; 5 (4, 5]; 7;
    is validated by the unit test but rejected by the GUI.
    
    But those are concerns to address in the future. In this commit, simply
    removing 'default_keyword' from SequenceParser induced an inconsistency:
    it prevented the ctor arguments that InputSequence and SequenceParser
    share from constituting identical blocks, and therefore the last two
    arguments to the first InputSequence ctor were swapped. This swapping
    might seem extravagantly fastidious, yet on the other hand these classes
    seem to suffer not from too much attention to detail, but too little.
---
 input_realization.cpp    |    4 ++--
 input_seq_test.cpp       |   18 +++++++++---------
 input_sequence.cpp       |    7 ++-----
 input_sequence.hpp       |   11 ++++++-----
 input_sequence_entry.cpp |    2 +-
 5 files changed, 20 insertions(+), 22 deletions(-)

diff --git a/input_realization.cpp b/input_realization.cpp
index 4413805..0524b22 100644
--- a/input_realization.cpp
+++ b/input_realization.cpp
@@ -80,8 +80,8 @@ std::string realize_sequence_string
         ,input.inforce_year     ()
         ,input.effective_year   ()
         ,detail::extract_keys_from_string_map(keyword_dictionary)
-        ,default_keyword
         ,true
+        ,default_keyword
         );
     detail::convert_vector
         (v
@@ -112,8 +112,8 @@ std::string realize_sequence_string
         ,input.inforce_year     ()
         ,input.effective_year   ()
         ,detail::extract_keys_from_string_map(keyword_dictionary)
-        ,default_keyword
         ,false
+        ,default_keyword
         );
     detail::convert_vector(vn, s.linear_number_representation());
     detail::convert_vector
diff --git a/input_seq_test.cpp b/input_seq_test.cpp
index 6d1d95e..48f9f26 100644
--- a/input_seq_test.cpp
+++ b/input_seq_test.cpp
@@ -37,13 +37,13 @@ void check
     ,char const*                     m = ""
     ,std::vector<std::string> const& k = std::vector<std::string>()
     ,std::vector<std::string> const& c = std::vector<std::string>()
-    ,std::string const&              w = std::string()
     ,bool                            o = false
+    ,std::string const&              w = std::string()
     )
 {
     try
         {
-        InputSequence const seq(e, n, 90, 95, 0, 2002, k, w, o);
+        InputSequence const seq(e, n, 90, 95, 0, 2002, k, o, w);
 
         std::vector<double> const& v(seq.linear_number_representation());
         bool const bv = v == std::vector<double>(d, d + n);
@@ -130,8 +130,8 @@ int test_main(int, char*[])
     //     n: length
     //     e: expression
     //     k: extra keywords
-    //     w: default keyword
     //     o: keywords only
+    //     w: default keyword
 
     // An empty string is treated as zero.
     {
@@ -363,9 +363,9 @@ int test_main(int, char*[])
     check(__FILE__, __LINE__, d, n, e, "", k, c);
     // Toggle keywords-only switch on: same result.
     bool const o = true;
-    check(__FILE__, __LINE__, d, n, e, "", k, c, "", o);
+    check(__FILE__, __LINE__, d, n, e, "", k, c, o);
     // Toggle keywords-only switch explicitly off: same result.
-    check(__FILE__, __LINE__, d, n, e, "", k, c, "", false);
+    check(__FILE__, __LINE__, d, n, e, "", k, c, false);
     }
 
     // Test numbers mixed with (enumerative) extra keywords.
@@ -387,7 +387,7 @@ int test_main(int, char*[])
     std::string const e("q [0, 2); p [3, 4); 5 [4, 6); p; 7");
     strvec const k{"p", "q", "z"};
     std::string w("z");
-    check(__FILE__, __LINE__, d, n, e, "", k, c, w);
+    check(__FILE__, __LINE__, d, n, e, "", k, c, false, w);
     }
 
     // Test keywords-only switch with input it forbids.
@@ -408,7 +408,7 @@ int test_main(int, char*[])
     strvec const k{"p", "q", "z"};
     std::string w("z");
     bool const o = true;
-    check(__FILE__, __LINE__, d, n, e, m, k, c, w, o);
+    check(__FILE__, __LINE__, d, n, e, m, k, c, o, w);
     }
 
     // Test an expression with a gap between intervals, with the
@@ -421,7 +421,7 @@ int test_main(int, char*[])
     strvec const k{"p", "q", "z"};
     std::string w("z");
     bool const o = true;
-    check(__FILE__, __LINE__, d, n, e, "", k, c, w, o);
+    check(__FILE__, __LINE__, d, n, e, "", k, c, o, w);
     }
 
     // Test an expression with a gap between intervals, with the
@@ -439,7 +439,7 @@ int test_main(int, char*[])
     strvec const k{"p", "q", "z"};
     std::string w("u");
     bool const o = true;
-    check(__FILE__, __LINE__, d, n, e, "", k, c, w, o);
+    check(__FILE__, __LINE__, d, n, e, "", k, c, o, w);
     }
 
     // Duration keywords: {retirement, maturity}
diff --git a/input_sequence.cpp b/input_sequence.cpp
index fa3f493..cf6aec6 100644
--- a/input_sequence.cpp
+++ b/input_sequence.cpp
@@ -56,7 +56,6 @@ SequenceParser::SequenceParser
     ,int                             a_inforce_duration
     ,int                             a_effective_year
     ,std::vector<std::string> const& a_extra_keywords
-    ,std::string const&              a_default_keyword
     ,bool                            a_keywords_only
     )
     :input_stream                  (input_expression.c_str())
@@ -66,7 +65,6 @@ SequenceParser::SequenceParser
     ,inforce_duration              (a_inforce_duration)
     ,effective_year                (a_effective_year)
     ,extra_keywords                (a_extra_keywords)
-    ,default_keyword               (a_default_keyword)
     ,keywords_only                 (a_keywords_only)
     ,current_token_type            (e_startup)
     ,previous_duration_scalar_mode (e_inception)
@@ -96,8 +94,8 @@ InputSequence::InputSequence
     ,int                             a_inforce_duration
     ,int                             a_effective_year
     ,std::vector<std::string> const& a_extra_keywords
-    ,std::string const&              a_default_keyword
     ,bool                            a_keywords_only
+    ,std::string const&              a_default_keyword
     )
     :years_to_maturity             (a_years_to_maturity)
     ,issue_age                     (a_issue_age)
@@ -105,8 +103,8 @@ InputSequence::InputSequence
     ,inforce_duration              (a_inforce_duration)
     ,effective_year                (a_effective_year)
     ,extra_keywords                (a_extra_keywords)
-    ,default_keyword               (a_default_keyword)
     ,keywords_only                 (a_keywords_only)
+    ,default_keyword               (a_default_keyword)
 {
     SequenceParser parser
         (input_expression
@@ -116,7 +114,6 @@ InputSequence::InputSequence
         ,inforce_duration
         ,effective_year
         ,extra_keywords
-        ,default_keyword
         ,keywords_only
         );
 
diff --git a/input_sequence.hpp b/input_sequence.hpp
index 71e6fa2..58bbf62 100644
--- a/input_sequence.hpp
+++ b/input_sequence.hpp
@@ -181,7 +181,6 @@ class SequenceParser
         ,int                             a_inforce_duration
         ,int                             a_effective_year
         ,std::vector<std::string> const& a_extra_keywords
-        ,std::string const&              a_default_keyword
         ,bool                            a_keywords_only
         );
 
@@ -227,13 +226,14 @@ class SequenceParser
     void mark_diagnostic_context();
 
     std::istringstream input_stream;
+
+    // Copies of ctor args that are identical to class InputSequence's.
     int years_to_maturity;
     int issue_age;
     int retirement_age;
     int inforce_duration;
     int effective_year;
     std::vector<std::string> extra_keywords;
-    std::string default_keyword;
     bool keywords_only;
 
     token_type current_token_type;
@@ -243,7 +243,6 @@ class SequenceParser
     duration_mode previous_duration_scalar_mode;
     duration_mode current_duration_scalar_mode;
     ValueInterval current_interval;
-
     int last_input_duration;
 
     std::ostringstream diagnostics;
@@ -265,8 +264,8 @@ class LMI_SO InputSequence
         ,int                             a_effective_year
         ,std::vector<std::string> const& a_extra_keywords
             = std::vector<std::string>()
-        ,std::string const&              a_default_keyword = ""
         ,bool                            a_keywords_only = false
+        ,std::string const&              a_default_keyword = ""
         );
 
     InputSequence(std::vector<double> const&);
@@ -289,14 +288,16 @@ class LMI_SO InputSequence
   private:
     void realize_vector();
 
+    // Copies of ctor args that are identical to class SequenceParser's.
     int years_to_maturity;
     int issue_age;
     int retirement_age;
     int inforce_duration;
     int effective_year;
     std::vector<std::string> extra_keywords;
-    std::string default_keyword;
     bool keywords_only;
+    // Copy of a ctor arg that is unique to this class.
+    std::string default_keyword;
 
     std::string EXPEDIENTdiagnostics;
 
diff --git a/input_sequence_entry.cpp b/input_sequence_entry.cpp
index 7def453..43009f1 100644
--- a/input_sequence_entry.cpp
+++ b/input_sequence_entry.cpp
@@ -1554,8 +1554,8 @@ void InputSequenceEntry::DoOpenEditor()
         ,in.inforce_year     ()
         ,in.effective_year   ()
         ,keywords
-        ,ds.default_keyword()
         ,keywords_only
+        ,ds.default_keyword()
         );
 
     std::string const diagnostics = sequence.formatted_diagnostics(true);



reply via email to

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