#ifndef TEXT_ACCESS_H #define TEXT_ACCESS_H #include #include #include #include "FilePath.h" class TextAccess { public: static std::shared_ptr createFromFile(const FilePath& filePath); static std::shared_ptr createFromString(const std::string& text, const FilePath& filePath = FilePath()); static std::shared_ptr createFromLines(const std::vector& lines, const FilePath& filePath = FilePath()); virtual ~TextAccess(); unsigned int getLineCount() const; bool isEmpty() const; FilePath getFilePath() const; /** * @param lineNumber: starts with 1 */ std::string getLine(const unsigned int lineNumber) const; /** * @param firstLineNumber: starts with 1 * @param lastLineNumber: starts with 1 */ std::vector getLines(const unsigned int firstLineNumber, const unsigned int lastLineNumber); const std::vector& getAllLines() const; std::string getText() const; private: static std::vector readFile(const FilePath& filePath); static std::vector splitStringByLines(const std::string& text); TextAccess(); TextAccess(const TextAccess&); TextAccess operator=(const TextAccess&); bool checkIndexInRange(const unsigned int index) const; bool checkIndexIntervalInRange(const unsigned int firstIndex, const unsigned int lastIndex) const; FilePath m_filePath; std::vector m_lines; }; #endif // TEXT_ACCESS_H