8#ifndef H_ALIB_FILES_TEXTFILE
9#define H_ALIB_FILES_TEXTFILE
36 Path tFilePath(filePath);
40 ALIB_WARNING(
"FILES/TEXTFILE",
"Error <{}: \"{}\"> opening input file \"{}\"",
44 ALIB_MESSAGE(
"FILES/TEXTFILE",
"file \"{}\" opened for reading", filePath)
62 file.
AsCursor().AssemblePath(filePath);
87template <
typename TNString= NString,
typename TAllocator= MonoAllocator>
116 constexpr integer Size() const noexcept {
return int(Vector::size()); }
126 template<
typename TIntegral>
128 constexpr StoredType&
At(TIntegral idx)
noexcept {
return Vector::at(
size_t(idx)); }
134 template<
typename TIntegral>
136 constexpr const StoredType&
At(TIntegral idx)
const noexcept {
return Vector::at(
size_t(idx)); }
144 if ( reader.
Status != system::SystemErrors::OK )
148 while ( (line= reader.
NextLine()).IsNotNull() )
151 ALIB_MESSAGE(
"FILES/TEXTFILE",
"File \"{}\", {} lines read", filePath, Vector::size() )
153 return system::SystemErrors::OK;
162 file.
AsCursor().AssemblePath(filePath);
163 return Read(filePath);
173 Path tFilePath(filePath);
175 std::ofstream oFile( nTFilePath.Terminate() );
176 if ( !oFile.is_open() ) {
178 ALIB_WARNING(
"FILES/TEXTFILE",
"Error <{}: \"{}\"> opening output file \"{}\"",
179 errno, result, filePath)
182 ALIB_MESSAGE(
"FILES/TEXTFILE",
"file \"{}\" opened for writing", filePath)
184 for(
auto& line : *
this )
185 oFile << line << std::endl;
187 ALIB_MESSAGE(
"FILES/TEXTFILE",
"File \"{}\", {} lines written", filePath, Vector::size() )
189 return system::SystemErrors::OK;
constexpr const StoredType & At(TIntegral idx) const noexcept
TTextFile(MonoAllocator &ma)
TAllocator AllocatorType
Type definition publishing template parameter TAllocator.
StdVectorMA< TNString > Vector
Type definition publishing the base container type.
system::SystemErrors Read(const CString &filePath)
constexpr StoredType & At(TIntegral idx) noexcept
MonoAllocator & allocator
ALIB_DLL system::SystemErrors Write(const String &filePath)
system::SystemErrors Read(files::File file)
constexpr integer Size() const noexcept
#define ALIB_MESSAGE(domain,...)
#define ALIB_STRINGS_TO_NARROW( src, dest, bufSize)
#define ALIB_WARNING(domain,...)
constexpr String NULL_STRING
A nulled string of the default character type.
files::TextFileLineReader TextFileLineReader
Type alias in namespace alib.
std::vector< T, StdMA< T > > StdVectorMA
Type alias in namespace alib.
strings::TCString< character > CString
Type alias in namespace alib.
lang::integer integer
Type alias in namespace alib.
monomem::TMonoAllocator< lang::HeapAllocator > MonoAllocator
system::Path Path
Type alias in namespace alib.
strings::compatibility::std::TIStreamLine< alib::character > IStreamLine
Type alias in namespace alib.
strings::TString< character > String
Type alias in namespace alib.
NLocalString< 4096 > NString4K
Type alias name for TLocalString<nchar,8192>.
system::SystemErrors SystemErrors
Type alias in namespace alib.
files::TTextFile< NString > TextFile
Type alias in namespace alib.
strings::TSubstring< character > Substring
Type alias in namespace alib.
NString4K Line
The line buffer.
std::ifstream IFStream
The input stream opened on construction.
TextFileLineReader(files::File file)
alib::IStreamLine ReadOp
An AString-appendable object used for reading.
system::SystemErrors Status
TextFileLineReader(const CString &filePath)
void construct(const CString &filePath)