[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] odd/product2 7b66116: Experiment with another way of
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] odd/product2 7b66116: Experiment with another way of generating product databases |
Date: |
Mon, 28 Jan 2019 12:03:20 -0500 (EST) |
branch: odd/product2
commit 7b6611612416387599f10fdaf16fd3ae257020fe
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Experiment with another way of generating product databases
---
dbdict.cpp | 9 ++++-
dbdict.hpp | 10 ++++--
generate_product_files.cpp | 90 ++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 106 insertions(+), 3 deletions(-)
diff --git a/dbdict.cpp b/dbdict.cpp
index ea66e6e..5c2f5d7 100644
--- a/dbdict.cpp
+++ b/dbdict.cpp
@@ -89,6 +89,7 @@ database_entity value_cast<database_entity>(std::string
const&)
DBDictionary::DBDictionary()
{
ascribe_members();
+ InitDB();
}
DBDictionary::DBDictionary(std::string const& filename)
@@ -501,7 +502,13 @@ void DBDictionary::write_proem
::write_proem(document, file_leaf_name);
}
-/// Set a value. (The historical name "Add" is now misleading.)
+/// Set a value. (The historical name "Add" is now misleading.) 'set()'
instead?
+/// The classic sgi documentation for std::map said:
+/// operator[] is extremely simple: m[k] is equivalent to
+/// (*((m.insert(value_type(k, data_type()))).first)).second.
+/// 'Add' was the name of a similar function in a pre-STL container
+/// library. 'insert' is obviously a poor name here; 'operator[]'
+/// might be too cute.
void DBDictionary::Add(database_entity const& e)
{
diff --git a/dbdict.hpp b/dbdict.hpp
index abfa12c..2544002 100644
--- a/dbdict.hpp
+++ b/dbdict.hpp
@@ -34,7 +34,7 @@
/// Cached product database.
-class LMI_SO DBDictionary final
+class LMI_SO DBDictionary
:public xml_serializable <DBDictionary>
,public MemberSymbolTable <DBDictionary>
,public cache_file_reads <DBDictionary>
@@ -57,6 +57,9 @@ class LMI_SO DBDictionary final
void InitAntediluvian();
+ protected:
+ virtual void specify() {}
+
private:
DBDictionary(DBDictionary const&) = delete;
DBDictionary& operator=(DBDictionary const&) = delete;
@@ -67,11 +70,14 @@ class LMI_SO DBDictionary final
database_entity& datum(std::string const&);
+ protected:
+ public:
void WriteDB(std::string const& filename) const;
void Add(database_entity const&);
+ private:
void InitDB();
- // A temporary expedient.
+ // A temporary expedient soon to be banished forevermore.
void Nyarlathotep();
// xml_serializable required implementation.
diff --git a/generate_product_files.cpp b/generate_product_files.cpp
index 65ef6a0..6c5a876 100644
--- a/generate_product_files.cpp
+++ b/generate_product_files.cpp
@@ -32,10 +32,100 @@
#include <iostream>
#include <ostream>
+// Experimental:
+#include "data_directory.hpp"
+#include "dbnames.hpp"
+
+class E0 : public DBDictionary { public: void specify() override; };
+class E1 : public E0 { public: void specify() override; };
+
+void E0::specify()
+{
+ Add(database_entity(DB_GuarMonthlyPolFee , 7.65));
+ Add(database_entity(DB_CurrMonthlyPolFee , 4.32));
+}
+
+void E1::specify()
+{
+ // Calling this is crucial, but unfortunately possible to forget:
+ E0::specify();
+ // Perhaps it should be a ctor instead?
+
+// Add(database_entity(DB_CurrMonthlyPolFee , 4.32));
+ Add({DB_CurrMonthlyPolFee , 4.32, "Four thirty-two."});
+
+ // Forbid substandard table ratings with simplified or guaranteed issue.
+ int dim_uw_basis[e_number_of_axes] = {1, 1, 1, 1, 5, 1, 1};
+ // med para nonmed SI GI
+ double allow_substd_table[] = {true, true, true, false, false};
+ Add({DB_AllowSubstdTable, e_number_of_axes, dim_uw_basis,
allow_substd_table});
+// Also try one with a gloss...
+ Add({DB_AllowSubstdTable, e_number_of_axes, dim_uw_basis,
allow_substd_table, "Gloss..."});
+}
+
+class F0 : public DBDictionary { public: F0(); };
+class F1 : public F0 { public: F1(); };
+
+F0::F0()
+{
+ Add(database_entity(DB_GuarMonthlyPolFee , 7.65));
+ Add(database_entity(DB_CurrMonthlyPolFee , 4.32));
+}
+
+F1::F1()
+{
+// F0::F0(); // called implicitly
+
+// Add(database_entity(DB_CurrMonthlyPolFee , 4.32));
+ Add({DB_CurrMonthlyPolFee , 4.32, "Four thirty-two."});
+
+ // Forbid substandard table ratings with simplified or guaranteed issue.
+ int dim_uw_basis[e_number_of_axes] = {1, 1, 1, 1, 5, 1, 1};
+ // med para nonmed SI GI
+ double allow_substd_table[] = {true, true, true, false, false};
+ Add({DB_AllowSubstdTable, e_number_of_axes, dim_uw_basis,
allow_substd_table});
+// Also try one with a gloss...
+ Add({DB_AllowSubstdTable, e_number_of_axes, dim_uw_basis,
allow_substd_table, "Gloss..."});
+}
+
+// free fn: convenient, but can't use inheritance
+void specimen9()
+{
+ DBDictionary z;
+ z.Add(database_entity(DB_GuarMonthlyPolFee , 7.65));
+ z.Add({DB_CurrMonthlyPolFee , 4.32, "Four thirty-two."});
+
+ // Forbid substandard table ratings with simplified or guaranteed issue.
+ int dim_uw_basis[e_number_of_axes] = {1, 1, 1, 1, 5, 1, 1};
+ // med para nonmed SI GI
+ double allow_substd_table[] = {true, true, true, false, false};
+ z.Add({DB_AllowSubstdTable, e_number_of_axes, dim_uw_basis,
allow_substd_table});
+// Also try one with a gloss...
+ z.Add({DB_AllowSubstdTable, e_number_of_axes, dim_uw_basis,
allow_substd_table, "Yup!"});
+
+ z.WriteDB(AddDataDir("specimen9.database"));
+}
+
int try_main(int, char*[])
{
initialize_filesystem();
+// Experimental:
+ specimen9();
+
+ E0 e0;
+// e0.InitDB(); // instead, do this in base-class default ctor
+ e0.specify();
+ e0.WriteDB(AddDataDir("specimen0.database"));
+
+ E1 e1;
+ e1.specify();
+ e1.WriteDB(AddDataDir("specimen1.database"));
+
+ F0().WriteDB(AddDataDir("specimen0f.database"));
+
+ F1().WriteDB(AddDataDir("specimen1f.database"));
+
std::cout << "Generating product files." << std::endl;
DBDictionary ::write_database_files ();