ALib C++ Framework
by
Library Version: 2511 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
alib::files::TTextFile< TNString, TAllocator, TLocalBufferSize > Class Template Reference

Description:

template<typename TNString = NString, typename TAllocator = MonoAllocator, size_t TLocalBufferSize = 1024>
class alib::files::TTextFile< TNString, TAllocator, TLocalBufferSize >

A rather simple text file reader and writer.

See also
Reading is performed using helper type class TextFileLineReader, which be used as a standalone helper, i.e. in cases where a text file is read but does not need to be stored in a vector.
Template Parameters
TNStringThe string-type. This may also be a type derived from NString which contains further fields available with each line of the file.
TAllocatorThe allocator type to use.
TLocalBufferSizeThe size of the local buffer. If lines are wider and the local buffer is exceeded, it will be replaced by an heap-allocated buffer, which is then reused for any further line.
Defaults to 1024.

Definition at line 103 of file ALib.Files.TextFile.H.

#include <ALib.Files.TextFile.H>

Inheritance diagram for alib::files::TTextFile< TNString, TAllocator, TLocalBufferSize >:
alib::lang::AllocatorMember< MonoAllocator >

Public Type Index:

using AllocatorType = TAllocator
 Type definition publishing template parameter TAllocator.
using StoredType = TNString
using Vector = StdVectorMA<TNString>
 Type definition publishing the base container type.
Public Type Index: inherited from alib::lang::AllocatorMember< MonoAllocator >
using AllocatorType
 Exposes the allocator type.

Public Method Index:

 TTextFile (MonoAllocator &ma)
template<typename TIntegral>
constexpr const StoredTypeAt (TIntegral idx) const noexcept
template<typename TIntegral>
constexpr StoredTypeAt (TIntegral idx) noexcept
std::errc Read (const CString &filePath)
std::errc Read (files::File file)
constexpr integer Size () const noexcept
std::errc Write (const String &filePath)
Public Method Index: inherited from alib::lang::AllocatorMember< MonoAllocator >
 AllocatorMember ()
AllocatorInterface< MonoAllocatorAI () const noexcept
MonoAllocatorGetAllocator () const noexcept

Protected Field Index:

MonoAllocatorallocator
 The given allocator.
Protected Field Index: inherited from alib::lang::AllocatorMember< MonoAllocator >
MonoAllocatorallocator
 The allocator stored.

Type Definition Details:

◆ AllocatorType

template<typename TNString = NString, typename TAllocator = MonoAllocator, size_t TLocalBufferSize = 1024>
using alib::files::TTextFile< TNString, TAllocator, TLocalBufferSize >::AllocatorType = TAllocator

Type definition publishing template parameter TAllocator.

Definition at line 112 of file ALib.Files.TextFile.H.

◆ StoredType

template<typename TNString = NString, typename TAllocator = MonoAllocator, size_t TLocalBufferSize = 1024>
using alib::files::TTextFile< TNString, TAllocator, TLocalBufferSize >::StoredType = TNString

Type definition publishing the type in the std::vector that this type is derived of. (As is defined with template parameter TNString.)

Definition at line 117 of file ALib.Files.TextFile.H.

◆ Vector

template<typename TNString = NString, typename TAllocator = MonoAllocator, size_t TLocalBufferSize = 1024>
using alib::files::TTextFile< TNString, TAllocator, TLocalBufferSize >::Vector = StdVectorMA<TNString>

Type definition publishing the base container type.

Definition at line 120 of file ALib.Files.TextFile.H.

Field Details:

◆ allocator

template<typename TNString = NString, typename TAllocator = MonoAllocator, size_t TLocalBufferSize = 1024>
MonoAllocator& alib::files::TTextFile< TNString, TAllocator, TLocalBufferSize >::allocator
protected

The given allocator.

Definition at line 108 of file ALib.Files.TextFile.H.

Constructor(s) / Destructor Details:

◆ TTextFile()

template<typename TNString = NString, typename TAllocator = MonoAllocator, size_t TLocalBufferSize = 1024>
alib::files::TTextFile< TNString, TAllocator, TLocalBufferSize >::TTextFile ( MonoAllocator & ma)
inline

Constructor.

Parameters
maThe allocator to use.

Definition at line 124 of file ALib.Files.TextFile.H.

Method Details:

◆ At() [1/2]

template<typename TNString = NString, typename TAllocator = MonoAllocator, size_t TLocalBufferSize = 1024>
template<typename TIntegral>
const StoredType & alib::files::TTextFile< TNString, TAllocator, TLocalBufferSize >::At ( TIntegral idx) const
inlineconstexprnoexcept

const-version of At.

Template Parameters
TIntegralThe integral type that the index is provided by.
Parameters
idxThe index to retrieve an element for.
Returns
A const reference to the element stored at the given idx.

Definition at line 151 of file ALib.Files.TextFile.H.

◆ At() [2/2]

template<typename TNString = NString, typename TAllocator = MonoAllocator, size_t TLocalBufferSize = 1024>
template<typename TIntegral>
StoredType & alib::files::TTextFile< TNString, TAllocator, TLocalBufferSize >::At ( TIntegral idx)
inlineconstexprnoexcept

Returns the element in the vector at the given position.
Note that this is the same as calling inherited std::vector::at(), but this method accepts any integral type for parameter idx.
Furthermore, this method raises an ALib Assertion in debug-builds, instead of throwing an exception.

Template Parameters
TIntegralThe integral type that the index is provided by.
Parameters
idxThe index to retrieve an element for.
Returns
A reference to the element stored at the given idx.

Definition at line 143 of file ALib.Files.TextFile.H.

◆ Read() [1/2]

template<typename TNString = NString, typename TAllocator = MonoAllocator, size_t TLocalBufferSize = 1024>
std::errc alib::files::TTextFile< TNString, TAllocator, TLocalBufferSize >::Read ( const CString & filePath)
inline

Reads the file into this vector of lines.

Parameters
filePathThe path of the file.
Returns
std::errc(0) if all went well, otherwise an error code.

Definition at line 156 of file ALib.Files.TextFile.H.

◆ Read() [2/2]

template<typename TNString = NString, typename TAllocator = MonoAllocator, size_t TLocalBufferSize = 1024>
std::errc alib::files::TTextFile< TNString, TAllocator, TLocalBufferSize >::Read ( files::File file)
inline

Reads the file into this vector of lines.

Parameters
fileThe file to read.
Returns
std::errc(0) if all went well, otherwise an error code.

Definition at line 173 of file ALib.Files.TextFile.H.

◆ Size()

template<typename TNString = NString, typename TAllocator = MonoAllocator, size_t TLocalBufferSize = 1024>
integer alib::files::TTextFile< TNString, TAllocator, TLocalBufferSize >::Size ( ) const
inlineconstexprnoexcept

Returns the vector's size as ALib's signed integral type.

Returns
The number of lines in this source file.

Definition at line 131 of file ALib.Files.TextFile.H.

◆ Write()

template<typename TNString = NString, typename TAllocator = MonoAllocator, size_t TLocalBufferSize = 1024>
std::errc alib::files::TTextFile< TNString, TAllocator, TLocalBufferSize >::Write ( const String & filePath)
inline

Writes this text file to the given filePath.

Parameters
filePathThe path of the file.
Returns
std::errc(0) if all went well, otherwise an error code.

Definition at line 183 of file ALib.Files.TextFile.H.


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