AtomicFile: Minor cleanups

1) Remove AtomicFile::impl::find and use std::find_if directly.

2) Remove static functions that take a string for path. Allow the compiler to
construct the Path object as necessary.

Signed-off-by: Shaun Ruffell <sruffell@sruffell.net>
This commit is contained in:
Shaun Ruffell 2021-07-08 09:39:45 -05:00 committed by Thomas Lauf
parent 12696bf40c
commit 7ffb2421a2
2 changed files with 9 additions and 39 deletions

View file

@ -279,27 +279,19 @@ void AtomicFile::impl::finalize ()
}
}
////////////////////////////////////////////////////////////////////////////////
AtomicFile::impl::iterator AtomicFile::impl::find (const Path& path)
{
auto end = impl::atomic_files.end ();
auto cmp = [&path](const atomic_files_t::value_type& p)
{
return p->real_file == path;
};
auto it = std::find_if(impl::atomic_files.begin (), end, cmp);
return (it == end) ? end : it;
}
////////////////////////////////////////////////////////////////////////////////
AtomicFile::AtomicFile (const Path& path)
{
auto it = impl::find (path);
auto end = impl::atomic_files.end ();
auto it = std::find_if (impl::atomic_files.begin (), end,
[&path] (const impl::value_type& p)
{
return p->real_file == path;
});
if (it == impl::atomic_files.end ())
if (it == end)
{
pimpl = std::make_shared <impl> (path._data);
pimpl = std::make_shared <impl> (path);
impl::atomic_files.push_back (pimpl);
}
else
@ -400,18 +392,6 @@ void AtomicFile::write_raw (const std::string& content)
pimpl->write_raw (content);
}
////////////////////////////////////////////////////////////////////////////////
void AtomicFile::append (const std::string& path, const std::string& data)
{
return AtomicFile(path).append (data);
}
////////////////////////////////////////////////////////////////////////////////
void AtomicFile::write (const std::string& path, const std::string& data)
{
AtomicFile::write (Path (path), data);
}
////////////////////////////////////////////////////////////////////////////////
void AtomicFile::write (const Path& path, const std::string& data)
{
@ -434,14 +414,7 @@ void AtomicFile::write (const Path& path, const std::vector <std::string>& lines
////////////////////////////////////////////////////////////////////////////////
void AtomicFile::read (const Path& path, std::string& content)
{
AtomicFile file (path);
file.read (content);
}
////////////////////////////////////////////////////////////////////////////////
void AtomicFile::read (const std::string& path, std::string& content)
{
AtomicFile::read (Path (path), content);
AtomicFile (path).read (content);
}
void AtomicFile::read (const Path& path, std::vector <std::string>& lines)

View file

@ -56,14 +56,11 @@ public:
void append (const std::string& content);
void write_raw (const std::string& content);
static void append (const std::string& path, const std::string& data);
static void append (const Path& path, const std::string& data);
static void write (const std::string& path, const std::string& data);
static void write (const Path& path, const std::string& data);
static void write (const Path& path, const std::vector <std::string>& lines);
static void read (const std::string& path, std::string& content);
static void read (const Path& path, std::string& content);
static void read (const Path& path, std::vector <std::string>& lines);