ALib C++ Library
Library Version: 2402 R1
Documentation generated by doxygen
Loading...
Searching...
No Matches
textfile.hpp
Go to the documentation of this file.
1/** ************************************************************************************************
2 * \file
3 * This header file is part of module \alib_files of the \aliblong.
4 *
5 * \emoji :copyright: 2013-2024 A-Worx GmbH, Germany.
6 * Published under \ref mainpage_license "Boost Software License".
7 **************************************************************************************************/
8#ifndef HPP_ALIB_FILES_TEXTFILE
9#define HPP_ALIB_FILES_TEXTFILE 1
10#if !defined(ALIB_DOX) // todo remove
11
12#if !defined(HPP_ALIB_FILES_FTREE)
13# include "alib/files/ftree.hpp"
14#endif
15
16#if !defined(HPP_ALIB_MONOMEM_MASTRING)
18#endif
19
20#if !defined (HPP_ALIB_MONOMEM_STDCONTAINERMA)
22#endif
23namespace alib { namespace files {
24
25/** ************************************************************************************************
26 * Todox
27 * Todox: explain the strict monotonic behaviour and that the allocator must not be used
28 * outside during operation, because it will be reset with destruction
29 **************************************************************************************************/
30class TextFile
31{
32 protected:
33 MonoAllocator* allocator; ///< The given allocator
34 MonoAllocator::Snapshot priorUsage; ///< The state of the given allocator with construction.
35
36 public:
37 /** The text lines */
38 std::vector<MAString, StdContMA<MAString>>* Lines;
39
40 /**
41 * Constructor.
42 * @param allocator The allocator to use.
43 */
45 TextFile(monomem::MonoAllocator* allocator);
46
47 /** Destructor. Resets the #allocator to the state it was in when this object was
48 * constructed. */
49 ~TextFile();
50
51 /**
52 * Reads the file into field #Lines.
53 * @param filePath The path of the file.
54 * @param extraSpacePercentage If given, the allocated line strings are extended by a
55 * percentage of the original line length. This avoids
56 * the allocation of new intermediate strings, and hence might
57 * be small speed optimization. If for example only replacements
58 * are made that shorten the lines, this parameter should not be
59 * given. Defaults to \c 0.
60 * @return \alib{lang::system;SystemErrors;SystemErrors::OK} if all went well, otherwise an
61 * error code.
62 */
64 lang::system::SystemErrors Read(const String& filePath, int extraSpacePercentage= 0);
65
66 /**
67 * Writes the #Lines into the given \p{filePath}.
68 * @param filePath The path of the file.
69 */
71 lang::system::SystemErrors Write(const String& filePath);
72
73 /**
74 * Resets the file
75 */
77 void Reset();
78};
79
80} // namespace alib[::files]
81
82/// Type alias in namespace \b alib.
83using TextFile = files::TextFile;
84
85} // namespace [alib]
86
87#endif //!defined(ALIB_DOX) // todo remove
88
89
90#endif // HPP_ALIB_FILES_TEXTFILE
#define ALIB_API
Definition alib.hpp:538
Definition alib.cpp:57
monomem::MonoAllocator MonoAllocator
Type alias in namespace alib.