Specialise for FILE object owning file instances.
More...
#include <io.hpp>
|
| file (file const &)=delete |
| Must not copy construct for risk of multiple close() on the same file.
|
|
| file (file &&move) |
| Move construct from a temporary. More...
|
|
| file (FILE *const handle) |
| Take ownership of the given FILE object. More...
|
|
| file () |
| Default construct.
|
|
template<feature ... Superset, class = is_superset_of_t<set<Superset ...>, set<Features ...>>> |
| file (file< own, Superset ... > &&move) |
| Move construct from another owning file type instance. More...
|
|
| file (char const *const filename, char const *const mode) |
| Open a file by name. More...
|
|
| ~file () |
| Free all resources.
|
|
file & | operator= (file &&move) |
| Move assign from a temporary. More...
|
|
template<feature ... Superset, class = is_superset_of_t<set<Superset ...>, set<Features ...>>> |
file & | operator= (file< own, Superset ... > &&move) |
| Move assign from another owning file type instance. More...
|
|
FILE * | get () const |
| Provide the internal FILE object pointer. More...
|
|
FILE * | release () |
| Surrender ownership of the internal FILE object pointer. More...
|
|
file & | close () |
| Close the file. More...
|
|
| operator bool () const |
| Cast to boolean. More...
|
|
bool | eof () const |
| Return whether the file instance is in EOF state. More...
|
|
bool | error () const |
| Return whether the file instance is in an error state. More...
|
|
|
template<ownership , feature ... > |
class | file |
| Friend all file classes for move assignment.
|
|
template<feature ... Features>
class sys::io::file< own, Features ... >
Specialise for FILE object owning file instances.
Ownership implies some semantics:
- Offers a constructor that opens a file
- Cannot be copy constructed/assigned
- Can be move constructed/assigned from other owning file instances
- Can close()
- Implicit close() when going out of scope
- Template Parameters
-
Features | The set of file access features to support |
◆ file() [1/4]
template<feature ... Features>
Move construct from a temporary.
- Parameters
-
move | The rvalue file to acquire the FILE object from |
◆ file() [2/4]
template<feature ... Features>
Take ownership of the given FILE object.
This can be used to take ownership of FILE objects provided by a legacy C interface.
- Parameters
-
handle | A pointer to a FILE object |
◆ file() [3/4]
template<feature ... Features>
template<feature ... Superset, class = is_superset_of_t<set<Superset ...>, set<Features ...>>>
Move construct from another owning file type instance.
The origin file type instance must support all features supported by this file type.
- Template Parameters
-
Superset | The feature set of the original FILE object owner |
- Parameters
-
move | The rvalue file to acquire the FILE object from |
◆ file() [4/4]
template<feature ... Features>
sys::io::file< own, Features ... >::file |
( |
char const *const |
filename, |
|
|
char const *const |
mode |
|
) |
| |
|
inline |
Open a file by name.
Failure to open a file occurs silently, but can be detected by boolean checking the file instance.
The arguments of this constructor are forwarded to fopen(), provided the mode argument does not contradict the feature set of this file type.
It is recommended to always add the 'b' (binary) character to the mode string, because text mode behaves quirkily.
The feature::seek feature is not supported with 'a' (append), it is available with 'a+', but it behaves quirkily. Which means two different files of the same type may have different seek behaviour, depending on how the file was opened. Refer to the fopen() spec for the unsettling details.
- See also
- fopen()
- Parameters
-
filename | The name of the file |
mode | The file access mode, must not contradict the feature set of this file type |
◆ close()
template<feature ... Features>
Close the file.
- Returns
- A self reference
◆ get()
template<feature ... Features>
Provide the internal FILE object pointer.
Can be used to pass the file to legacy C interfaces.
- Returns
- A pointer to the managed FILE object
◆ operator=() [1/2]
template<feature ... Features>
Move assign from a temporary.
- Parameters
-
move | The rvalue file to acquire the FILE object from |
- Returns
- A self reference
◆ operator=() [2/2]
template<feature ... Features>
template<feature ... Superset, class = is_superset_of_t<set<Superset ...>, set<Features ...>>>
Move assign from another owning file type instance.
The origin file type instance must support all features supported by this file type.
- Template Parameters
-
Superset | The feature set of the original FILE object owner |
- Parameters
-
move | The rvalue file to acquire the FILE object from |
- Returns
- A self reference
◆ release()
template<feature ... Features>
Surrender ownership of the internal FILE object pointer.
Can be used to pass the file to legacy C interfaces.
- Returns
- A pointer to the managed FILE object
The documentation for this class was generated from the following file: