Opened 9 years ago
#9614 new Feature Requests
Optional File Creation for boost::interprocess::file_lock
Reported by: | Owned by: | Ion Gaztañaga | |
---|---|---|---|
Milestone: | To Be Determined | Component: | interprocess |
Version: | Boost 1.54.0 | Severity: | Problem |
Keywords: | Cc: |
Description
An optional overload (default second argument?) for the constructor to create and open the file to use for the file_lock would be very useful.
Currently, when creating a file lock, I typically do something like:
std::ofstream tmpf(/path/to/lock/file); tmpf.close(); boost::interprocess:file_lock f_lock(/path/to/lock/file);
Say I have a class, such as:
class Foo { public: Foo(); private: boost::interprocess::file_lock f_lock; };
I have to do the following in the constructor:
Foo::Foo() { std::ofstream tmpf(/path/to/lock/file); tmpf.close(); boost::interprocess:file_lock tmp_lock(/path/to/lock/file); f_lock.swap(tmp_lock); }
This is cumbersome and limits usefulness in initializer lists. Tweaking the constructor to something like:
file_lock::file_lock(const char *path, bool create = false);
Would allow a constructor to do the following:
Foo::Foo() : f_lock(/path/to/file/lock, true) { }
Note:
See TracTickets
for help on using tickets.