#pragma once #include #include namespace knacki::cd{ class AppContext; typedef char PTR_TYPE; class IOError { public: IOError(const std::string &e): what(e) {} const std::string what; }; class HistoryEntry { public: HistoryEntry(PTR_TYPE index, const std::string &e); HistoryEntry(const HistoryEntry &); HistoryEntry &operator=(const HistoryEntry &o); const std::string &GetPath() const; PTR_TYPE GetIndex() const; protected: std::string path; PTR_TYPE index; }; class History { public: History(const std::string &file); const std::vector &GetEntries() const; const HistoryEntry *GetNextWorkingDirectory(const AppContext &app) const; bool IsPrevious(const HistoryEntry &) const; bool IsCurrent(const HistoryEntry &) const; protected: History() {}; std::vector hist; PTR_TYPE current; PTR_TYPE prev; void Read(std::istream &file); const HistoryEntry *GetHistoryEntry(PTR_TYPE index) const; }; class HistoryRW: public History { public: HistoryRW(const std::string &file); bool AppendCwd(); bool Append(const std::string &); bool Append(const HistoryEntry &); bool Flush(); void Write(); protected: void TruncateAfter(PTR_TYPE pos); private: const std::string path; }; }