|
ActiveLib
|
Class to represent a file. More...
#include <File.h>


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 File * | clonePtr () 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 |
| FSNode & | operator= (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 |
Class to represent a file.
| File::File | ( | ) |
Constructor

| File::File | ( | const Path & | path, |
| Permission | perm = readWrite, | ||
| bool | isMissingCreated = false, | ||
| bool | canReplaceDirectory = false ) |
Constructor
| path | The full path to the file |
| perm | Access permission |
| isMissingCreated | True if the file should be created when missing |
| canReplaceDirectory | True if the file can be created and replace an existing directory with the same name |
| std::ios_base::failure | Thrown if isMissingCreated = true and the file cannot be created |

| File::File | ( | const Directory & | parent, |
| const utility::String & | name, | ||
| Permission | perm = readWrite, | ||
| bool | isMissingCreated = false, | ||
| bool | canReplaceDirectory = false ) |
Constructor
| parent | The parent directory |
| name | The file name |
| perm | Access permission |
| isMissingCreated | True if the file should be created when missing |
| canReplaceDirectory | True if the file can be created and replace an existing directory with the same name |
| std::ios_base::failure | Thrown if isMissingCreated = true and the file cannot be created |
| File::File | ( | const File & | source | ) |
Copy constructor
| source | The object to copy |
|
virtual |
Destructor

|
inlineoverridevirtualnoexcept |
Determine if the stream is bad
Reimplemented from active::file::IOBase.
|
inlineoverridevirtual |
Set the stream state flags
| f | The stream state flags |
| std::ios_base::failure | Thrown on error |
Reimplemented from active::file::IOBase.
|
inlineoverridevirtual |
Clone method
Implements active::utility::Cloner.

|
noexcept |
Close the file


|
inlineoverridevirtualnoexcept |
Determine if end of input has been seen
Reimplemented from active::file::IOBase.
|
inlineoverridevirtualnoexcept |
Determine if the next operation will fail
Reimplemented from active::file::IOBase.
| void File::flush | ( | ) |
Flush any cached data to the file
| std::ios_base::failure | Thrown on error |
| File::pos_type File::getPosition | ( | ) | const |
Get the read/write position in the file
| std::ios_base::failure | Thrown on error |

|
inlineoverridevirtualnoexcept |
Determine if the last operation was successful, i.e. eof, fail and bad bits are all 0)
Reimplemented from active::file::IOBase.
|
noexcept |
Test if the file is open

|
inlinenoexcept |
Determine if the file is writable
| void File::open | ( | std::optional< Permission > | perm = std::nullopt | ) | const |
Open the file
| perm | Optional access permission - otherwise existing permissions are used |
| std::ios_base::failure | Thrown if the file cannot be opened |

| void File::operator= | ( | const File & | source | ) |
Assignment operator
| source | The object to copy |

| bool File::operator== | ( | const File & | ref | ) | const |
Equality operator
| ref | The object to compare |

| File::size_type File::read | ( | utility::Memory & | memory, |
| File::sizeOption | howMany = std::nullopt ) const |
Read from the file
| memory | The memory to read the data into |
| howMany | The number of bytes requested (nullopt = use allocated memory size) |
| std::ios_base::failure | Thrown on error |

| 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)
| text | The string to read the data into |
| howMany | The number of bytes to read (nullopt = entire file) |
| std::ios_base::failure | Thrown on error |
Move the read position if not all the bytes can be consumed by the string as valid chars

| File::size_type File::remaining | ( | ) | const |
Get the number of bytes remaining (from current position to eof)
| std::ios_base::failure | Thrown on error |


|
overridevirtual |
Remove the node path
| isRecursive | True if any subnodes should also be recursively removed |
| std::ios_base::failure | Thrown on error |
Reimplemented from active::file::FSNode.

| void File::resize | ( | size_type | fileSize | ) |
Resize the file
| fileSize | The new file size |
| std::ios_base::failure | Thrown on error |

| void File::setPosition | ( | pos_type | pos | ) | const |
Set the read/write position in the file to an absolute position
| pos | The file position |
| std::ios_base::failure | Thrown on error |

Set the read/write position in the file relative to a specified anchor (start, current, end) position
| pos | The relative file position |
| anchor | The anchor to set the position relative to |
| std::ios_base::failure | Thrown on error |
|
inlineoverridevirtualnoexcept |
Modify the stream state flags
| f | The flag to modify |
Reimplemented from active::file::IOBase.
| File::size_type File::size | ( | ) | const |
Get the file size
| std::ios_base::failure | Thrown on error |


| bool File::write | ( | const File & | file | ) |
Write the contents of another file to this
| file | The file to write |

| void File::write | ( | const utility::Memory & | data, |
| sizeOption | howMany = std::nullopt ) |
Write to the file from a block of memory
| data | The data to write |
| howMany | The data length (nullopt = write allocated memory size) |
| std::ios_base::failure | Thrown on error |

| void File::write | ( | const utility::String & | text, |
| utility::String::sizeOption | howMany = std::nullopt, | ||
| utility::TextEncoding | encoding = UTF8 ) |
Write to the file from a string
| text | The data to write |
| howMany | The number of characters to write (nullopt = full string) |
| encoding | The text encoding to write |
| std::ios_base::failure | Thrown on error |
