lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master c9dd079 1/3: Add and test product_data copy c


From: Greg Chicares
Subject: [lmi-commits] [lmi] master c9dd079 1/3: Add and test product_data copy ctor
Date: Sun, 4 Nov 2018 03:10:23 -0500 (EST)

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

    Add and test product_data copy ctor
    
    Made this class copyable so that (movable) class BasicValues can own
    a product_data object directly rather than through a smart pointer.
    
    A move ctor would seem preferable, but would require making base class
    MemberSymbolTable movable, whereas a well-tested copy ctor for similar
    class Input is already available as an exemplar.
---
 product_data.cpp      |  8 ++++++++
 product_data.hpp      |  3 ++-
 product_file_test.cpp | 14 ++++++++++++++
 3 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/product_data.cpp b/product_data.cpp
index 7226706..84a0c83 100644
--- a/product_data.cpp
+++ b/product_data.cpp
@@ -148,6 +148,14 @@ product_data::product_data(std::string const& product_name)
     load(AddDataDir(path.string()));
 }
 
+product_data::product_data(product_data const& z)
+    :xml_serializable  <product_data> {}
+    ,MemberSymbolTable <product_data> {}
+{
+    ascribe_members();
+    MemberSymbolTable<product_data>::assign(z);
+}
+
 /// Destructor.
 ///
 /// Although it is explicitly defaulted, this destructor cannot be
diff --git a/product_data.hpp b/product_data.hpp
index a417b03..be85c66 100644
--- a/product_data.hpp
+++ b/product_data.hpp
@@ -81,6 +81,7 @@ class LMI_SO product_data final
     ,public MemberSymbolTable <product_data>
 {
     friend class PolicyDocument;
+    friend class product_file_test;
 
     typedef deserialized<product_data>::value_type value_type;
 
@@ -96,7 +97,7 @@ class LMI_SO product_data final
 
   private:
     product_data();
-    product_data(product_data const&) = delete;
+    product_data(product_data const&);
     product_data& operator=(product_data const&) = delete;
 
     void ascribe_members();
diff --git a/product_file_test.cpp b/product_file_test.cpp
index c89f70e..6e62f89 100644
--- a/product_file_test.cpp
+++ b/product_file_test.cpp
@@ -43,11 +43,13 @@ class product_file_test
         // Location of product files.
         global_settings::instance().set_data_directory("/opt/lmi/data");
         get_filenames();
+        test_copying();
         assay_speed();
         }
 
   private:
     static void get_filenames();
+    static void test_copying();
     static void assay_speed();
     static void read_database_file()   ;
     static void read_fund_file()       ;
@@ -78,6 +80,18 @@ void product_file_test::get_filenames()
     stratified_filename_ = AddDataDir(p.datum("TierFilename"    ));
 }
 
+void product_file_test::test_copying()
+{
+    product_data p(policy_filename_);
+
+    // Test copy ctor.
+    product_data q(p);
+    BOOST_TEST(database_filename_   == 
AddDataDir(q.datum("DatabaseFilename")));
+    BOOST_TEST(fund_filename_       == AddDataDir(q.datum("FundFilename"    
)));
+    BOOST_TEST(rounding_filename_   == 
AddDataDir(q.datum("RoundingFilename")));
+    BOOST_TEST(stratified_filename_ == AddDataDir(q.datum("TierFilename"    
)));
+}
+
 void product_file_test::read_database_file()
 {
     DBDictionary().Init(database_filename_);



reply via email to

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