100.00% Lines (4/4)
100.00% Functions (2/2)
| TLA | Baseline | Branch | ||||||
|---|---|---|---|---|---|---|---|---|
| Line | Hits | Code | Line | Hits | Code | |||
| 1 | // | 1 | // | |||||
| 2 | // Copyright (c) 2026 Michael Vandeberg | 2 | // Copyright (c) 2026 Michael Vandeberg | |||||
| 3 | // | 3 | // | |||||
| 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | |||||
| 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |||||
| 6 | // | 6 | // | |||||
| 7 | // Official repository: https://github.com/cppalliance/corosio | 7 | // Official repository: https://github.com/cppalliance/corosio | |||||
| 8 | // | 8 | // | |||||
| 9 | 9 | |||||||
| 10 | #ifndef BOOST_COROSIO_FILE_BASE_HPP | 10 | #ifndef BOOST_COROSIO_FILE_BASE_HPP | |||||
| 11 | #define BOOST_COROSIO_FILE_BASE_HPP | 11 | #define BOOST_COROSIO_FILE_BASE_HPP | |||||
| 12 | 12 | |||||||
| 13 | #include <boost/corosio/detail/config.hpp> | 13 | #include <boost/corosio/detail/config.hpp> | |||||
| 14 | 14 | |||||||
| 15 | namespace boost::corosio { | 15 | namespace boost::corosio { | |||||
| 16 | 16 | |||||||
| 17 | /** Groups the flag and seek-origin constants shared | 17 | /** Groups the flag and seek-origin constants shared | |||||
| 18 | by @ref stream_file and @ref random_access_file. | 18 | by @ref stream_file and @ref random_access_file. | |||||
| 19 | */ | 19 | */ | |||||
| 20 | struct file_base | 20 | struct file_base | |||||
| 21 | { | 21 | { | |||||
| 22 | /** Bitmask flags for opening a file. | 22 | /** Bitmask flags for opening a file. | |||||
| 23 | 23 | |||||||
| 24 | Flags are combined with bitwise OR to specify the | 24 | Flags are combined with bitwise OR to specify the | |||||
| 25 | desired access mode and creation behavior. | 25 | desired access mode and creation behavior. | |||||
| 26 | */ | 26 | */ | |||||
| 27 | enum flags : unsigned | 27 | enum flags : unsigned | |||||
| 28 | { | 28 | { | |||||
| 29 | /// Open for reading only. | 29 | /// Open for reading only. | |||||
| 30 | read_only = 1, | 30 | read_only = 1, | |||||
| 31 | 31 | |||||||
| 32 | /// Open for writing only. | 32 | /// Open for writing only. | |||||
| 33 | write_only = 2, | 33 | write_only = 2, | |||||
| 34 | 34 | |||||||
| 35 | /// Open for reading and writing. | 35 | /// Open for reading and writing. | |||||
| 36 | read_write = read_only | write_only, | 36 | read_write = read_only | write_only, | |||||
| 37 | 37 | |||||||
| 38 | /// Append to the end of the file on each write. | 38 | /// Append to the end of the file on each write. | |||||
| 39 | append = 4, | 39 | append = 4, | |||||
| 40 | 40 | |||||||
| 41 | /// Create the file if it does not exist. | 41 | /// Create the file if it does not exist. | |||||
| 42 | create = 8, | 42 | create = 8, | |||||
| 43 | 43 | |||||||
| 44 | /// Fail if the file already exists (requires @ref create). | 44 | /// Fail if the file already exists (requires @ref create). | |||||
| 45 | exclusive = 16, | 45 | exclusive = 16, | |||||
| 46 | 46 | |||||||
| 47 | /// Truncate the file to zero length on open. | 47 | /// Truncate the file to zero length on open. | |||||
| 48 | truncate = 32, | 48 | truncate = 32, | |||||
| 49 | 49 | |||||||
| 50 | /// Synchronize data to disk on each write. | 50 | /// Synchronize data to disk on each write. | |||||
| 51 | sync_all_on_write = 64 | 51 | sync_all_on_write = 64 | |||||
| 52 | }; | 52 | }; | |||||
| 53 | 53 | |||||||
| 54 | /** Origin for seek operations. */ | 54 | /** Origin for seek operations. */ | |||||
| 55 | enum seek_basis | 55 | enum seek_basis | |||||
| 56 | { | 56 | { | |||||
| 57 | /// Seek relative to the beginning of the file. | 57 | /// Seek relative to the beginning of the file. | |||||
| 58 | seek_set, | 58 | seek_set, | |||||
| 59 | 59 | |||||||
| 60 | /// Seek relative to the current position. | 60 | /// Seek relative to the current position. | |||||
| 61 | seek_cur, | 61 | seek_cur, | |||||
| 62 | 62 | |||||||
| 63 | /// Seek relative to the end of the file. | 63 | /// Seek relative to the end of the file. | |||||
| 64 | seek_end | 64 | seek_end | |||||
| 65 | }; | 65 | }; | |||||
| 66 | 66 | |||||||
| HITCBC | 67 | 117 | friend constexpr flags operator|(flags a, flags b) noexcept | 67 | 125 | friend constexpr flags operator|(flags a, flags b) noexcept | ||
| 68 | { | 68 | { | |||||
| 69 | return static_cast<flags>( | 69 | return static_cast<flags>( | |||||
| HITCBC | 70 | 117 | static_cast<unsigned>(a) | static_cast<unsigned>(b)); | 70 | 125 | static_cast<unsigned>(a) | static_cast<unsigned>(b)); | ||
| 71 | } | 71 | } | |||||
| 72 | 72 | |||||||
| HITCBC | 73 | 2269 | friend constexpr flags operator&(flags a, flags b) noexcept | 73 | 2329 | friend constexpr flags operator&(flags a, flags b) noexcept | ||
| 74 | { | 74 | { | |||||
| 75 | return static_cast<flags>( | 75 | return static_cast<flags>( | |||||
| HITCBC | 76 | 2269 | static_cast<unsigned>(a) & static_cast<unsigned>(b)); | 76 | 2329 | static_cast<unsigned>(a) & static_cast<unsigned>(b)); | ||
| 77 | } | 77 | } | |||||
| 78 | 78 | |||||||
| 79 | friend constexpr flags& operator|=(flags& a, flags b) noexcept | 79 | friend constexpr flags& operator|=(flags& a, flags b) noexcept | |||||
| 80 | { | 80 | { | |||||
| 81 | return a = a | b; | 81 | return a = a | b; | |||||
| 82 | } | 82 | } | |||||
| 83 | 83 | |||||||
| 84 | friend constexpr flags& operator&=(flags& a, flags b) noexcept | 84 | friend constexpr flags& operator&=(flags& a, flags b) noexcept | |||||
| 85 | { | 85 | { | |||||
| 86 | return a = a & b; | 86 | return a = a & b; | |||||
| 87 | } | 87 | } | |||||
| 88 | }; | 88 | }; | |||||
| 89 | 89 | |||||||
| 90 | } // namespace boost::corosio | 90 | } // namespace boost::corosio | |||||
| 91 | 91 | |||||||
| 92 | #endif // BOOST_COROSIO_FILE_BASE_HPP | 92 | #endif // BOOST_COROSIO_FILE_BASE_HPP | |||||