lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] (no subject)


From: Greg Chicares
Subject: [lmi-commits] (no subject)
Date: Wed, 20 Jul 2016 14:29:27 +0000 (UTC)

branch: master
commit a5aa6dde6469fcf9d3faca481c9d271ce31d02db
Author: Gregory W. Chicares <address@hidden>
Date:   Tue Jul 19 16:50:01 2016 +0000

    Forbid periods in product names
    
    The modified unit test shows an example of the confusion that might
    ensue from the laxness of the original code. This line:
      product_database::initialize("sample.database")
    happened to read the file that it appears to read, by accident only.
    In fact, the extension was replaced, resulting in "sample.product",
    and the database indicated in that product file was opened. A line
    like this:
      product_database::initialize("sample2.database")
    would have read the same database file, although the file that its
    argument seems to name does not actually exist: it would have read
    "sample2.product", which uses "sample.database" without a "2".
---
 input_test.cpp   |    2 +-
 product_data.cpp |    9 ++++++++-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/input_test.cpp b/input_test.cpp
index 0e0a112..427e54d 100644
--- a/input_test.cpp
+++ b/input_test.cpp
@@ -154,7 +154,7 @@ void input_test::test_product_database()
     // writing individual functions by hand is simpler and clearer.
     std::cout
         << "\n  Database speed tests..."
-        << "\n  initialize()      : " << TimeAnAliquot(boost::bind        
(&product_database::initialize,      &db, "sample.database"))
+        << "\n  initialize()      : " << TimeAnAliquot(boost::bind        
(&product_database::initialize,      &db, "sample"         ))
         << "\n  Query(vector)     : " << TimeAnAliquot(boost::bind<void  
>(&product_database::Query,           &db, v, DB_MaturityAge))
         << "\n  Query(scalar)     : " << 
TimeAnAliquot(boost::bind<double>(&product_database::Query,           &db,    
DB_MaturityAge))
         << "\n  entity_from_key() : " << TimeAnAliquot(boost::bind        
(&product_database::entity_from_key, &db,    DB_MaturityAge))
diff --git a/product_data.cpp b/product_data.cpp
index c761e9a..6961988 100644
--- a/product_data.cpp
+++ b/product_data.cpp
@@ -137,13 +137,20 @@ product_data::product_data()
 /// The argument is a string (typically Input::ProductName) such as
 /// 'sample'. The appropriate extension and path are added here to
 /// produce a filepath.
+///
+/// Somewhat arbitrarily, forbid '.' in product names. There's no real
+/// need to allow that, and it would complicate the code. A product
+/// name like "ul.with.variable.funds" could too easily be mistaken
+/// for a '.funds' file. The boost filesystem portability guidelines
+/// suggest "Do not use more that one period in a file name", and
+/// extensions are added to product names to create file names.
 
 product_data::product_data(std::string const& product_name)
 {
     ascribe_members();
 
     fs::path path(product_name);
-    LMI_ASSERT(product_name == path.leaf());
+    LMI_ASSERT(product_name == fs::basename(path));
     path = fs::change_extension(path, ".policy");
     load(AddDataDir(path.string()));
 }



reply via email to

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