lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [6433] Allow pasting YYYYMMDD dates into a census


From: Greg Chicares
Subject: [lmi-commits] [6433] Allow pasting YYYYMMDD dates into a census
Date: Thu, 10 Dec 2015 20:22:23 +0000

Revision: 6433
          http://svn.sv.gnu.org/viewvc/?view=rev&root=lmi&revision=6433
Author:   chicares
Date:     2015-12-10 20:22:22 +0000 (Thu, 10 Dec 2015)
Log Message:
-----------
Allow pasting YYYYMMDD dates into a census

Modified Paths:
--------------
    lmi/trunk/calendar_date.hpp
    lmi/trunk/census_view.cpp

Modified: lmi/trunk/calendar_date.hpp
===================================================================
--- lmi/trunk/calendar_date.hpp 2015-12-08 15:52:31 UTC (rev 6432)
+++ lmi/trunk/calendar_date.hpp 2015-12-10 20:22:22 UTC (rev 6433)
@@ -72,8 +72,8 @@
     int value_;
 };
 
-ymd_t JdnToYmd(jdn_t);
-jdn_t YmdToJdn(ymd_t);
+ymd_t LMI_SO JdnToYmd(jdn_t);
+jdn_t LMI_SO YmdToJdn(ymd_t);
 
 /// Class calendar_date represents a gregorian-calendar date in the
 /// range [1752-09-14, 9999-12-31]. Date calculations are probably

Modified: lmi/trunk/census_view.cpp
===================================================================
--- lmi/trunk/census_view.cpp   2015-12-08 15:52:31 UTC (rev 6432)
+++ lmi/trunk/census_view.cpp   2015-12-10 20:22:22 UTC (rev 6433)
@@ -45,6 +45,7 @@
 #include "safely_dereference_as.hpp"
 #include "single_choice_popup_menu.hpp"
 #include "timer.hpp"
+#include "value_cast.hpp"
 #include "wx_new.hpp"
 #include "wx_utility.hpp"               // class ClipboardEx
 
@@ -1632,6 +1633,38 @@
         return;
         }
 
+    // Use a modifiable copy of case defaults as an exemplar for new
+    // cells to be created by pasting. Modifications are conditionally
+    // written back to case defaults later.
+    Input exemplar(case_parms()[0]);
+
+    // Force 'UseDOB' prn. Pasting it as a column never makes sense.
+    if(contains(headers, "UseDOB"))
+        {
+        warning() << "'UseDOB' is unnecessary and will be ignored." << 
std::flush;
+        }
+    bool const dob_pasted = contains(headers, "DateOfBirth");
+    bool const age_pasted = contains(headers, "IssueAge");
+    if(dob_pasted && age_pasted)
+        {
+        fatal_error()
+            << "Cannot paste both 'DateOfBirth' and 'IssueAge'."
+            << LMI_FLUSH
+            ;
+        }
+    else if(dob_pasted)
+        {
+        exemplar["UseDOB"] = "Yes";
+        }
+    else if(age_pasted)
+        {
+        exemplar["UseDOB"] = "No";
+        }
+    else
+        {
+        ; // Do nothing: neither age nor DOB pasted.
+        }
+
     // Read each subsequent line into an input object representing one cell.
     int current_line = 0;
     while(std::getline(iss_census, line, '\n'))
@@ -1640,7 +1673,7 @@
 
         iss_census >> std::ws;
 
-        Input current_cell(case_parms()[0]);
+        Input current_cell(exemplar);
 
         std::istringstream iss_line(line);
         std::string token;
@@ -1682,6 +1715,32 @@
 
         for(unsigned int j = 0; j < headers.size(); ++j)
             {
+            if(exact_cast<tnr_date>(current_cell[headers[j]]))
+                {
+                static long int const jdn_min = 
calendar_date::gregorian_epoch_jdn;
+                static long int const jdn_max = 
calendar_date::last_yyyy_date_jdn;
+                static long int const ymd_min = 
JdnToYmd(jdn_t(jdn_min)).value();
+                static long int const ymd_max = 
JdnToYmd(jdn_t(jdn_max)).value();
+                long int z = value_cast<long int>(values[j]);
+                if(jdn_min <= z && z <= jdn_max)
+                    {
+                    ; // Do nothing: JDN is the default expectation.
+                    }
+                else if(ymd_min <= z && z <= ymd_max)
+                    {
+                    z = YmdToJdn(ymd_t(z)).value();
+                    values[j] = value_cast<std::string>(z);
+                    }
+                else
+                    {
+                    fatal_error()
+                        << "Invalid date " << values[j]
+                        << " for '" << headers[j] << "'"
+                        << " on line " << current_line << "."
+                        << LMI_FLUSH
+                        ;
+                    }
+                }
             current_cell[headers[j]] = values[j];
             }
         current_cell.Reconcile();
@@ -1700,9 +1759,11 @@
 
     if(!document().IsModified() && !document().GetDocumentSaved())
         {
-        cell_parms().clear();
+        case_parms ().clear();
+        case_parms ().push_back(exemplar);
         class_parms().clear();
-        class_parms().push_back(case_parms()[0]);
+        class_parms().push_back(exemplar);
+        cell_parms ().clear();
         }
 
     std::back_insert_iterator<std::vector<Input> > iip(cell_parms());
@@ -1712,7 +1773,7 @@
     Update();
     status() << std::flush;
 
-    LMI_ASSERT(!case_parms ().empty());
+    LMI_ASSERT(1 == case_parms().size());
     LMI_ASSERT(!cell_parms ().empty());
     LMI_ASSERT(!class_parms().empty());
 }




reply via email to

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