17template <
size_t TLocalBufferSize= 1024>
30 Line.DbgDisableBufferReplacementWarning();
32 Path tFilePath(filePath);
37 ALIB_WARNING(
"FILETREE/TEXTFILE",
"Error <{}: \"{}\"> opening input file \"{}\"",
38 errno, std::errc(errno), filePath)
41 ALIB_MESSAGE(
"FILETREE/TEXTFILE",
"file \"{}\" opened for reading", filePath)
71# define TEXTFILE_DEFAULT_ALLOCATOR MonoAllocator
73# define TEXTFILE_DEFAULT_ALLOCATOR HeapAllocator
92template <
typename TNString=
NString,
typename TAllocator= TEXTFILE_DEFAULT_ALLOCATOR,
93 size_t TLocalBufferSize= 1024>
95 ,
public std::vector<TNString, lang::StdAllocator<TNString, TEXTFILE_DEFAULT_ALLOCATOR>> {
109 using Vector= std::vector<TNString, lang::StdAllocator<TNString, TEXTFILE_DEFAULT_ALLOCATOR>>;
119 constexpr integer Size() const noexcept {
return int(Vector::size()); }
129 template<
typename TIntegral>
131 constexpr StoredType&
At(TIntegral idx)
noexcept {
return Vector::at(
size_t(idx)); }
137 template<
typename TIntegral>
139 constexpr const StoredType&
At(TIntegral idx)
const noexcept {
return Vector::at(
size_t(idx)); }
146 if ( reader.
Status != std::errc(0) )
150 while ( (line= reader.
NextLine()).IsNotNull() ) {
151 if constexpr (std::is_same_v<StoredType, TNString>)
159 ALIB_MESSAGE(
"FILETREE/TEXTFILE",
"File \"{}\", {} lines read", filePath, Vector::size() )
170 Path tFilePath(filePath);
172 std::ofstream oFile( nTFilePath.Terminate() );
173 if ( !oFile.is_open() ) {
174 auto result= std::errc(errno);
175 ALIB_WARNING(
"FILETREE/TEXTFILE",
"Error <{}: \"{}\"> opening output file \"{}\"",
176 errno, result, filePath)
179 ALIB_MESSAGE(
"FILETREE/TEXTFILE",
"file \"{}\" opened for writing", filePath)
181 for(
auto& line : *
this )
182 oFile << line << std::endl;
184 ALIB_MESSAGE(
"FILETREE/TEXTFILE",
"File \"{}\", {} lines written", filePath, Vector::size() )
198template <
size_t TLocalBufferSize= 1024>
206template <
size_t TLocalBufferSize= 1024>
210# undef TEXTFILE_DEFAULT_ALLOCATOR
#define ALIB_MESSAGE(domain,...)
#define ALIB_WARNING(domain,...)
TAString & _(const TAppendable &src)
constexpr integer Size() const noexcept
std::errc Write(const PathString &filePath)
constexpr StoredType & At(TIntegral idx) noexcept
TTextFile(AllocatorType &ma)
constexpr const StoredType & At(TIntegral idx) const noexcept
std::vector< TNString, lang::StdAllocator< TNString, TEXTFILE_DEFAULT_ALLOCATOR > > Vector
Type definition publishing the base container type.
TAllocator AllocatorType
Type definition publishing template parameter TAllocator.
lang::AllocatorMember< TAllocator > base
The allocator member base-type.
std::errc Read(const CPathString &filePath)
strings::TString< nchar > NString
Type alias in namespace #"%alib".
system::TextFileLineReader< TLocalBufferSize > TextFileLineReader
constexpr NString NULL_NSTRING
A nulled string of the narrow character type.
lang::integer integer
Type alias in namespace #"%alib".
system::TTextFile< NString, TEXTFILE_DEFAULT_ALLOCATOR, TLocalBufferSize > TextFile
strings::TLocalString< nchar, TCapacity, lang::HeapAllocator > NLocalString
Type alias in namespace #"%alib".
strings::TCString< PathCharType > CPathString
The string-type used with this ALib Module.
strings::TString< PathCharType > PathString
The string-type used with this ALib Module.
strings::TSubstring< nchar > NSubstring
Type alias in namespace #"%alib".
strings::compatibility::std::TIStreamLine< alib::nchar > IStreamLineN
Type alias in namespace #"%alib".
#define ALIB_STRINGS_TO_NARROW( src, dest, bufSize)
TEXTFILE_DEFAULT_ALLOCATOR & GetAllocator() const noexcept
TextFileLineReader(const CPathString &filePath)
NLocalString< TLocalBufferSize > Line
void construct(const CPathString &filePath)