powerd++  0.4.4
Public Member Functions | Friends | List of all members
sys::io::file< own, Features ... > Class Template Referencefinal

Specialise for FILE object owning file instances. More...

#include <io.hpp>

Inheritance diagram for sys::io::file< own, Features ... >:
[legend]
Collaboration diagram for sys::io::file< own, Features ... >:
[legend]

Public Member Functions

 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.
 
fileoperator= (file &&move)
 Move assign from a temporary. More...
 
template<feature ... Superset, class = is_superset_of_t<set<Superset ...>, set<Features ...>>>
fileoperator= (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...
 
fileclose ()
 Close the file. More...
 
- Public Member Functions inherited from sys::io::file_feature< file< own, Features ... >, Features ... >
 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...
 

Friends

template<ownership , feature ... >
class file
 Friend all file classes for move assignment.
 

Additional Inherited Members

- Protected Member Functions inherited from sys::io::file_feature< file< own, Features ... >, Features ... >
 operator file< own, Features ... > & ()
 Implicit cast up to inheriting file access type.
 
 file_feature (FILE *const handle)
 Construct from a FILE object pointer. More...
 
- Protected Attributes inherited from sys::io::file_feature< file< own, Features ... >, Features ... >
FILE * handle
 A pointer to the underlying FILE object.
 

Detailed Description

template<feature ... Features>
class sys::io::file< own, Features ... >

Specialise for FILE object owning file instances.

Ownership implies some semantics:

Template Parameters
FeaturesThe set of file access features to support

Constructor & Destructor Documentation

◆ file() [1/4]

template<feature ... Features>
sys::io::file< own, Features ... >::file ( file< own, Features ... > &&  move)
inline

Move construct from a temporary.

Parameters
moveThe rvalue file to acquire the FILE object from

◆ file() [2/4]

template<feature ... Features>
sys::io::file< own, Features ... >::file ( FILE *const  handle)
inlineexplicit

Take ownership of the given FILE object.

This can be used to take ownership of FILE objects provided by a legacy C interface.

Parameters
handleA pointer to a FILE object

◆ file() [3/4]

template<feature ... Features>
template<feature ... Superset, class = is_superset_of_t<set<Superset ...>, set<Features ...>>>
sys::io::file< own, Features ... >::file ( file< own, Superset ... > &&  move)
inline

Move construct from another owning file type instance.

The origin file type instance must support all features supported by this file type.

Template Parameters
SupersetThe feature set of the original FILE object owner
Parameters
moveThe 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
filenameThe name of the file
modeThe file access mode, must not contradict the feature set of this file type

Member Function Documentation

◆ close()

template<feature ... Features>
file& sys::io::file< own, Features ... >::close ( )
inline

Close the file.

Returns
A self reference

◆ get()

template<feature ... Features>
FILE* sys::io::file< own, Features ... >::get ( ) const
inline

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>
file& sys::io::file< own, Features ... >::operator= ( file< own, Features ... > &&  move)
inline

Move assign from a temporary.

Parameters
moveThe 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 ...>>>
file& sys::io::file< own, Features ... >::operator= ( file< own, Superset ... > &&  move)
inline

Move assign from another owning file type instance.

The origin file type instance must support all features supported by this file type.

Template Parameters
SupersetThe feature set of the original FILE object owner
Parameters
moveThe rvalue file to acquire the FILE object from
Returns
A self reference

◆ release()

template<feature ... Features>
FILE* sys::io::file< own, Features ... >::release ( )
inline

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: