Skip to content

Commit

Permalink
Update documentation for the updated interface
Browse files Browse the repository at this point in the history
  • Loading branch information
bugdea1er committed Jan 29, 2025
1 parent d0ea3b7 commit 801fab9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 27 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,17 @@ The location of temporary files generated by this library is determined by the `

5. **Logging:** Temporary files can also be used for logging purposes, where log data is written to a temporary file before being processed and stored in a more permanent location. This can be helpful for managing log data efficiently in high-traffic systems.

`tmp::file` extends the `std::iostream` class and uses an instance of `std::filebuf` internally. It is essentially `std::fstream` without open/close methods

```cpp
#include <tmp/file>
...
{
// Create a unique temporary file
auto tmpfile = tmp::file("org.example.product", ".txt");
auto tmpfile = tmp::file("org.example.product", ".bin", std::ios::in | std::ios::out);

// Write its contents and metadata
tmpfile.write(contents);
tmpfile.append(metadata);
tmpfile << contents << metadata;

// Validate the file with an external validator
if (validate(tmpfile)) {
Expand Down
21 changes: 11 additions & 10 deletions include/tmp/directory
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@

namespace tmp {

/// tmp::directory is a smart handle that owns and manages a temporary directory
/// and deletes it recursively when this handle goes out of scope
/// `tmp::directory` is a smart handle that owns and manages a temporary
/// directory and deletes it recursively when this handle goes out of scope
///
/// When a tmp::directory object is created, it creates a unique temporary
/// directory using the system's default location for temporary files
/// When a `tmp::directory` object is created, it creates a unique temporary
/// directory using the system default location for temporary files
///
/// The managed directory is deleted of when either of the following happens:
/// - the managing tmp::directory object is destroyed
/// - the managing tmp::directory object is assigned another path via operator=
/// - the managing `tmp::directory` object is destroyed
/// - the managing `tmp::directory` object is assigned another path
/// via `operator=`
///
/// The following example uses a tmp::directory object to create a temporary
/// directory; when the function returns, the tmp::directory object goes out of
/// scope and the temporary directory is deleted along with all of its contents:
/// The following example uses a `tmp::directory` object to create a temporary
/// directory; when the function returns, the `tmp::directory` object goes out
/// of scope and the temporary directory is recursively deleted:
///
/// @code{.cpp}
/// #include <tmp/directory>
Expand All @@ -31,7 +32,7 @@ namespace tmp {
/// std::ostream(tmpdir / "file.txt") << "Hello, world!";
///
/// // the temporary directory is deleted recursively when the
/// // tmp::directory object goes out of scope and is destroyed
/// // `tmp::directory` object goes out of scope and is destroyed
/// }
/// @endcode
class TMP_EXPORT directory : public entry {
Expand Down
6 changes: 3 additions & 3 deletions include/tmp/entry
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

namespace tmp {

/// tmp::entry is a smart handle that owns and manages a temporary path and
/// `tmp::entry` is a smart handle that owns and manages a temporary path and
/// deletes it recursively when this handle goes out of scope
///
/// The managed path is deleted of when either of the following happens:
/// - the managing tmp::entry object is destroyed
/// - the managing tmp::entry object is assigned another path via operator=
/// - the managing `tmp::entry` object is destroyed
/// - the managing `tmp::entry` object is assigned another path via `operator=`
///
/// Subclasses should provide a path to manage for this class;
/// any opening or closing operations should be managed by subclasses
Expand Down
26 changes: 15 additions & 11 deletions include/tmp/file
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,34 @@

namespace tmp {

/// tmp::file is a smart handle that owns and manages a temporary file and
/// `tmp::file` is a smart handle that owns and manages a temporary file and
/// deletes it when this handle goes out of scope
///
/// When a tmp::file object is created, it creates a unique temporary file using
/// the system's default location for temporary files and opens it for reading
/// and writing
/// When a `tmp::file` object is created, it creates a unique temporary file
/// using the system default location for temporary files and opens it
/// with the given `openmode`
///
/// The managed file is deleted of when either of the following happens:
/// - the managing tmp::file object is destroyed
/// - the managing tmp::file object is assigned another path via operator=
/// - the managing `tmp::file` object is destroyed
/// - the managing `tmp::file` object is assigned another path via `operator=`
///
/// The following example uses a tmp::file object to create a temporary file
/// and write a string to it; when the function returns, the tmp::file object
/// `tmp::file` extends the `std::iostream` class and uses an instance
/// of `std::filebuf` internally. It is essentially `std::fstream`
/// without open/close methods
///
/// The following example uses a `tmp::file` object to create a temporary file
/// and write a string to it; when the function returns, the `tmp::file` object
/// goes out of scope and the temporary file is deleted:
///
/// @code{.cpp}
/// #include <tmp/file>
///
/// auto func(std::string_view content) {
/// auto tmpfile = tmp::file("org.example.product", ".txt");
/// tmpfile.write(content);
/// auto tmpfile = tmp::file("org.example.product", ".bin", std::ios::out);
/// tmpfile << content << std::flush;
///
/// // the temporary file is deleted recursively when the
/// // tmp::file object goes out of scope and is destroyed
/// // `tmp::file` object goes out of scope and is destroyed
/// }
/// @endcode
class TMP_EXPORT file : public entry, public std::iostream {
Expand Down

0 comments on commit 801fab9

Please sign in to comment.