ActiveLib
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Attributes | List of all members
active::file::File Class Reference

Class to represent a file. More...

#include <File.h>

Inheritance diagram for active::file::File:
Inheritance graph
[legend]
Collaboration diagram for active::file::File:
Collaboration graph
[legend]

Public Types

enum  Anchor { start , current , end }
 File position anchors.
 
enum class  Permission {
  readOnly , writeOnly , overWrite , readWrite ,
  append
}
 File permissions.
 
using Unique = std::unique_ptr<File>
 Unique pointer.
 
using Shared = std::shared_ptr<File>
 Shared pointer.
 
using size_type = std::fstream::off_type
 File size or absolute position type.
 
using sizeOption = std::optional<size_type>
 Optional size - used for unspecified size or position.
 
using pos_type = std::fstream::pos_type
 File position type.
 
using posOption = std::optional<pos_type>
 Optional position.
 
- Public Types inherited from active::file::FSNode
using Unique = std::unique_ptr<FSNode>
 Unique pointer.
 
using Shared = std::shared_ptr<FSNode>
 Unique pointer.
 
- Public Types inherited from active::file::IOBase
using flag_type = std::ios_base::iostate
 The state flag representation type.
 

Public Member Functions

 File ()
 
 File (const Path &path, Permission perm=readWrite, bool isMissingCreated=false, bool canReplaceDirectory=false)
 
 File (const Directory &parent, const utility::String &name, Permission perm=readWrite, bool isMissingCreated=false, bool canReplaceDirectory=false)
 
 File (const File &source)
 
virtual ~File ()
 
virtual FileclonePtr () const override
 
void operator= (const File &source)
 
bool operator== (const File &ref) const
 
void open (std::optional< Permission > perm=std::nullopt) const
 
void close () const noexcept
 
bool isOpen () const noexcept
 
bool isWritable () const noexcept
 
pos_type getPosition () const
 
void setPosition (pos_type pos) const
 
void setPosition (size_type pos, Anchor anchor=Anchor::start) const
 
size_type size () const
 
size_type remaining () const
 
size_type read (utility::String &text, sizeOption howMany=std::nullopt, utility::TextEncoding encoding=UTF8) const
 
size_type read (utility::Memory &memory, sizeOption howMany=std::nullopt) const
 
virtual bool good () const noexcept override
 
virtual bool eof () const noexcept override
 
virtual bool fail () const noexcept override
 
virtual bool bad () const noexcept override
 
void resize (size_type fileSize)
 
void write (const utility::String &text, utility::String::sizeOption howMany=std::nullopt, utility::TextEncoding encoding=UTF8)
 
void write (const utility::Memory &data, sizeOption howMany=std::nullopt)
 
bool write (const File &file)
 
virtual void remove (bool isRecursive=true) override
 
void flush ()
 
virtual void clear (flag_type f=std::ios_base::goodbit) override
 
virtual void setState (flag_type f) noexcept override
 
- Public Member Functions inherited from active::file::FSNode
 FSNode () noexcept
 
 FSNode (const Path &path)
 
 FSNode (const FSNode &source) noexcept
 
virtual ~FSNode () noexcept=default
 
FSNodeoperator= (const FSNode &source)
 
bool operator== (const FSNode &ref) const noexcept
 
Path getPath () const noexcept
 
virtual bool exists () const
 
virtual bool isDirectory () const
 
utility::Time getModificationTime () const
 
virtual void setPath (const Path &path)
 
virtual void moveTo (const Path &path)
 
virtual void rename (const utility::String &name)
 
- Public Member Functions inherited from active::utility::Cloner
virtual ~Cloner ()=default
 
- Public Member Functions inherited from active::file::IOBase
 IOBase () noexcept
 
 IOBase (const IOBase &source) noexcept
 
virtual ~IOBase () noexcept=default
 
bool operator! () const noexcept
 
 operator void * () const noexcept
 
virtual flag_type state () const noexcept
 
virtual void unsetState (flag_type f)
 

Static Public Attributes

static const size_type defBufferSize = 0x4000UL
 The default buffer size for file i/o.
 
- Static Public Attributes inherited from active::file::FSNode
static const utility::String pathDelimiter
 The path delimiter expression for the current platform.
 

Additional Inherited Members

- Protected Member Functions inherited from active::file::FSNode
bool isMine () const noexcept
 
void setMine (bool state) noexcept
 
- Protected Member Functions inherited from active::file::IOBase
void setCompleteState (flag_type state)
 
void clear (flag_type f=std::ios_base::goodbit) const
 
void setState (flag_type f) const
 
virtual void unsetState (flag_type f) const
 

Detailed Description

Class to represent a file.

Constructor & Destructor Documentation

◆ File() [1/4]

File::File ( )

Constructor

Here is the caller graph for this function:

◆ File() [2/4]

File::File ( const Path & path,
Permission perm = readWrite,
bool isMissingCreated = false,
bool canReplaceDirectory = false )

Constructor

Parameters
pathThe full path to the file
permAccess permission
isMissingCreatedTrue if the file should be created when missing
canReplaceDirectoryTrue if the file can be created and replace an existing directory with the same name
Exceptions
std::ios_base::failureThrown if isMissingCreated = true and the file cannot be created
Here is the call graph for this function:

◆ File() [3/4]

File::File ( const Directory & parent,
const utility::String & name,
Permission perm = readWrite,
bool isMissingCreated = false,
bool canReplaceDirectory = false )

Constructor

Parameters
parentThe parent directory
nameThe file name
permAccess permission
isMissingCreatedTrue if the file should be created when missing
canReplaceDirectoryTrue if the file can be created and replace an existing directory with the same name
Exceptions
std::ios_base::failureThrown if isMissingCreated = true and the file cannot be created

◆ File() [4/4]

File::File ( const File & source)

Copy constructor

Parameters
sourceThe object to copy

◆ ~File()

File::~File ( )
virtual

Destructor

Here is the call graph for this function:

Member Function Documentation

◆ bad()

virtual bool active::file::File::bad ( ) const
inlineoverridevirtualnoexcept

Determine if the stream is bad

Returns
True if the stream is bad

Reimplemented from active::file::IOBase.

◆ clear()

virtual void active::file::File::clear ( flag_type f = std::ios_base::goodbit)
inlineoverridevirtual

Set the stream state flags

Parameters
fThe stream state flags
Exceptions
std::ios_base::failureThrown on error

Reimplemented from active::file::IOBase.

◆ clonePtr()

virtual File * active::file::File::clonePtr ( ) const
inlineoverridevirtual

Clone method

Returns
A clone of this object

Implements active::utility::Cloner.

Here is the call graph for this function:

◆ close()

void File::close ( ) const
noexcept

Close the file

Here is the call graph for this function:
Here is the caller graph for this function:

◆ eof()

virtual bool active::file::File::eof ( ) const
inlineoverridevirtualnoexcept

Determine if end of input has been seen

Returns
True if end of input has been seen

Reimplemented from active::file::IOBase.

◆ fail()

virtual bool active::file::File::fail ( ) const
inlineoverridevirtualnoexcept

Determine if the next operation will fail

Returns
True if the next operation will fail

Reimplemented from active::file::IOBase.

◆ flush()

void File::flush ( )

Flush any cached data to the file

Exceptions
std::ios_base::failureThrown on error

◆ getPosition()

File::pos_type File::getPosition ( ) const

Get the read/write position in the file

Exceptions
std::ios_base::failureThrown on error
Returns
The file position (nullopt if file not open)
Here is the caller graph for this function:

◆ good()

virtual bool active::file::File::good ( ) const
inlineoverridevirtualnoexcept

Determine if the last operation was successful, i.e. eof, fail and bad bits are all 0)

Returns
True if the last operation was successful

Reimplemented from active::file::IOBase.

◆ isOpen()

bool File::isOpen ( ) const
noexcept

Test if the file is open

Returns
True if the file is open
Here is the caller graph for this function:

◆ isWritable()

bool active::file::File::isWritable ( ) const
inlinenoexcept

Determine if the file is writable

Returns
True if the file is writable

◆ open()

void File::open ( std::optional< Permission > perm = std::nullopt) const

Open the file

Parameters
permOptional access permission - otherwise existing permissions are used
Exceptions
std::ios_base::failureThrown if the file cannot be opened
Here is the call graph for this function:

◆ operator=()

void File::operator= ( const File & source)

Assignment operator

Parameters
sourceThe object to copy
Here is the call graph for this function:

◆ operator==()

bool File::operator== ( const File & ref) const

Equality operator

Parameters
refThe object to compare
Returns
True if ref is identical to this
Here is the call graph for this function:

◆ read() [1/2]

File::size_type File::read ( utility::Memory & memory,
File::sizeOption howMany = std::nullopt ) const

Read from the file

Parameters
memoryThe memory to read the data into
howManyThe number of bytes requested (nullopt = use allocated memory size)
Exceptions
std::ios_base::failureThrown on error
Returns
The number of bytes read
Here is the call graph for this function:

◆ read() [2/2]

File::size_type File::read ( utility::String & text,
sizeOption howMany = std::nullopt,
utility::TextEncoding encoding = UTF8 ) const

Read from the file into a string (from the current position)

Parameters
textThe string to read the data into
howManyThe number of bytes to read (nullopt = entire file)
Exceptions
std::ios_base::failureThrown on error
Returns
The number of bytes read

Move the read position if not all the bytes can be consumed by the string as valid chars

Here is the call graph for this function:

◆ remaining()

File::size_type File::remaining ( ) const

Get the number of bytes remaining (from current position to eof)

Exceptions
std::ios_base::failureThrown on error
Returns
The bytes remaining
Here is the call graph for this function:
Here is the caller graph for this function:

◆ remove()

void File::remove ( bool isRecursive = true)
overridevirtual

Remove the node path

Parameters
isRecursiveTrue if any subnodes should also be recursively removed
Exceptions
std::ios_base::failureThrown on error

Reimplemented from active::file::FSNode.

Here is the call graph for this function:

◆ resize()

void File::resize ( size_type fileSize)

Resize the file

Parameters
fileSizeThe new file size
Exceptions
std::ios_base::failureThrown on error
Here is the call graph for this function:

◆ setPosition() [1/2]

void File::setPosition ( pos_type pos) const

Set the read/write position in the file to an absolute position

Parameters
posThe file position
Exceptions
std::ios_base::failureThrown on error
Here is the caller graph for this function:

◆ setPosition() [2/2]

void File::setPosition ( size_type pos,
Anchor anchor = Anchor::start ) const

Set the read/write position in the file relative to a specified anchor (start, current, end) position

Parameters
posThe relative file position
anchorThe anchor to set the position relative to
Exceptions
std::ios_base::failureThrown on error

◆ setState()

virtual void active::file::File::setState ( flag_type f)
inlineoverridevirtualnoexcept

Modify the stream state flags

Parameters
fThe flag to modify

Reimplemented from active::file::IOBase.

◆ size()

File::size_type File::size ( ) const

Get the file size

Exceptions
std::ios_base::failureThrown on error
Returns
The file size
Here is the call graph for this function:
Here is the caller graph for this function:

◆ write() [1/3]

bool File::write ( const File & file)

Write the contents of another file to this

Parameters
fileThe file to write
Returns
True if the data was successfully written
Here is the call graph for this function:

◆ write() [2/3]

void File::write ( const utility::Memory & data,
sizeOption howMany = std::nullopt )

Write to the file from a block of memory

Parameters
dataThe data to write
howManyThe data length (nullopt = write allocated memory size)
Exceptions
std::ios_base::failureThrown on error
Here is the call graph for this function:

◆ write() [3/3]

void File::write ( const utility::String & text,
utility::String::sizeOption howMany = std::nullopt,
utility::TextEncoding encoding = UTF8 )

Write to the file from a string

Parameters
textThe data to write
howManyThe number of characters to write (nullopt = full string)
encodingThe text encoding to write
Exceptions
std::ios_base::failureThrown on error
Here is the call graph for this function:

The documentation for this class was generated from the following files: