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 + /** Common definitions for file I/O objects.
  18 +
  19 + Provides open flags and seek origin constants shared
18   by @ref stream_file and @ref random_access_file. 20   by @ref stream_file and @ref random_access_file.
19   */ 21   */
20   struct file_base 22   struct file_base
21   { 23   {
22   /** Bitmask flags for opening a file. 24   /** Bitmask flags for opening a file.
23   25  
24   Flags are combined with bitwise OR to specify the 26   Flags are combined with bitwise OR to specify the
25   desired access mode and creation behavior. 27   desired access mode and creation behavior.
26   */ 28   */
27   enum flags : unsigned 29   enum flags : unsigned
28   { 30   {
29   /// Open for reading only. 31   /// Open for reading only.
30   read_only = 1, 32   read_only = 1,
31   33  
32   /// Open for writing only. 34   /// Open for writing only.
33   write_only = 2, 35   write_only = 2,
34   36  
35   /// Open for reading and writing. 37   /// Open for reading and writing.
36   read_write = read_only | write_only, 38   read_write = read_only | write_only,
37   39  
38   /// Append to the end of the file on each write. 40   /// Append to the end of the file on each write.
39   append = 4, 41   append = 4,
40   42  
41   /// Create the file if it does not exist. 43   /// Create the file if it does not exist.
42   create = 8, 44   create = 8,
43   45  
44   /// Fail if the file already exists (requires @ref create). 46   /// Fail if the file already exists (requires @ref create).
45   exclusive = 16, 47   exclusive = 16,
46   48  
47   /// Truncate the file to zero length on open. 49   /// Truncate the file to zero length on open.
48   truncate = 32, 50   truncate = 32,
49   51  
50   /// Synchronize data to disk on each write. 52   /// Synchronize data to disk on each write.
51   sync_all_on_write = 64 53   sync_all_on_write = 64
52   }; 54   };
53   55  
54   /** Origin for seek operations. */ 56   /** Origin for seek operations. */
55   enum seek_basis 57   enum seek_basis
56   { 58   {
57   /// Seek relative to the beginning of the file. 59   /// Seek relative to the beginning of the file.
58   seek_set, 60   seek_set,
59   61  
60   /// Seek relative to the current position. 62   /// Seek relative to the current position.
61   seek_cur, 63   seek_cur,
62   64  
63   /// Seek relative to the end of the file. 65   /// Seek relative to the end of the file.
64   seek_end 66   seek_end
65   }; 67   };
66   68  
HITCBC 67   117 friend constexpr flags operator|(flags a, flags b) noexcept 69   117 friend constexpr flags operator|(flags a, flags b) noexcept
68   { 70   {
69   return static_cast<flags>( 71   return static_cast<flags>(
HITCBC 70   117 static_cast<unsigned>(a) | static_cast<unsigned>(b)); 72   117 static_cast<unsigned>(a) | static_cast<unsigned>(b));
71   } 73   }
72   74  
HITCBC 73   2269 friend constexpr flags operator&(flags a, flags b) noexcept 75   2269 friend constexpr flags operator&(flags a, flags b) noexcept
74   { 76   {
75   return static_cast<flags>( 77   return static_cast<flags>(
HITCBC 76   2269 static_cast<unsigned>(a) & static_cast<unsigned>(b)); 78   2269 static_cast<unsigned>(a) & static_cast<unsigned>(b));
77   } 79   }
78   80  
79   friend constexpr flags& operator|=(flags& a, flags b) noexcept 81   friend constexpr flags& operator|=(flags& a, flags b) noexcept
80   { 82   {
81   return a = a | b; 83   return a = a | b;
82   } 84   }
83   85  
84   friend constexpr flags& operator&=(flags& a, flags b) noexcept 86   friend constexpr flags& operator&=(flags& a, flags b) noexcept
85   { 87   {
86   return a = a & b; 88   return a = a & b;
87   } 89   }
88   }; 90   };
89   91  
90   } // namespace boost::corosio 92   } // namespace boost::corosio
91   93  
92   #endif // BOOST_COROSIO_FILE_BASE_HPP 94   #endif // BOOST_COROSIO_FILE_BASE_HPP