[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master bd30a5c 4/6: Change class cache_file_reads<>'
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master bd30a5c 4/6: Change class cache_file_reads<>'s key type |
Date: |
Fri, 22 Jan 2021 21:55:54 -0500 (EST) |
branch: master
commit bd30a5cba27fe4c60c72aba681279cbef537b8a2
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Change class cache_file_reads<>'s key type
---
cache_file_reads.hpp | 9 +++++----
cache_file_reads_test.cpp | 9 +++++----
2 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/cache_file_reads.hpp b/cache_file_reads.hpp
index 930bcde..5591730 100644
--- a/cache_file_reads.hpp
+++ b/cache_file_reads.hpp
@@ -27,6 +27,7 @@
#include "assert_lmi.hpp"
#include <boost/filesystem/operations.hpp>
+#include <boost/filesystem/path.hpp>
#include <ctime> // time_t
#include <map>
@@ -41,7 +42,7 @@ namespace detail
/// Motivation: It is costly to deserialize objects from xml, so cache
/// them for reuse. The cache persists until the program terminates.
///
-/// Requires: T::T(std::string const& filename), though not T::T().
+/// Requires: T::T(fs::path const& filename), though not T::T().
///
/// For each filename, the cache stores one instance, which is
/// replaced by reloading the file if its write time has changed.
@@ -67,7 +68,7 @@ class file_cache
return z;
}
- retrieved_type retrieve_or_reload(std::string const& filename)
+ retrieved_type retrieve_or_reload(fs::path const& filename)
{
// Throws if !exists(filename).
std::time_t const write_time = fs::last_write_time(filename);
@@ -105,7 +106,7 @@ class file_cache
std::time_t write_time;
};
- std::map<std::string,record> cache_;
+ std::map<fs::path,record> cache_;
};
} // namespace detail
@@ -124,7 +125,7 @@ class cache_file_reads
/// Postcondition: returned pointer is not null; otherwise,
/// file_cache::retrieve_or_reload() throws.
- static retrieved_type read_via_cache(std::string const& filename)
+ static retrieved_type read_via_cache(fs::path const& filename)
{
return detail::file_cache<T>::instance().retrieve_or_reload(filename);
}
diff --git a/cache_file_reads_test.cpp b/cache_file_reads_test.cpp
index 16283a2..9120a56 100644
--- a/cache_file_reads_test.cpp
+++ b/cache_file_reads_test.cpp
@@ -29,6 +29,7 @@
#include "timer.hpp"
#include <boost/filesystem/exception.hpp>
+#include <boost/filesystem/path.hpp>
#include <fstream>
@@ -36,9 +37,9 @@ class X
:public cache_file_reads<X>
{
public:
- X(std::string const& filename)
+ X(fs::path const& filename)
{
- std::ifstream ifs(filename, ios_in_binary());
+ std::ifstream ifs(filename.string(), ios_in_binary());
istream_to_string(ifs, s_);
}
@@ -70,8 +71,8 @@ class cache_file_reads_test
void cache_file_reads_test::test_preconditions()
{
- // X(filename) is required.
- X x0("sample.ill");;
+ // X(fs::path const&) is required.
+ X x0("sample.ill");
// The cache is accessible with or without an object.
BOOST_TEST_EQUAL
- [lmi-commits] [lmi] master updated (19222f8 -> a111350), Greg Chicares, 2021/01/22
- [lmi-commits] [lmi] master bd30a5c 4/6: Change class cache_file_reads<>'s key type,
Greg Chicares <=
- [lmi-commits] [lmi] master a111350 6/6: C++17ize, Greg Chicares, 2021/01/22
- [lmi-commits] [lmi] master b1d57e5 5/6: Establish another soon-to-become-useful invariant, Greg Chicares, 2021/01/22
- [lmi-commits] [lmi] master 84086c5 1/6: Note a spelling error in a literal quote, Greg Chicares, 2021/01/22
- [lmi-commits] [lmi] master 0fc4f3f 3/6: Correct a misapprehension, Greg Chicares, 2021/01/22
- [lmi-commits] [lmi] master 8252fb3 2/6: Establish an invariant that will become useful ere long, Greg Chicares, 2021/01/22