| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- #pragma once
- #include <vector>
- #include <string>
- 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<HistoryEntry> &GetEntries() const;
- const HistoryEntry *GetNextWorkingDirectory(const AppContext &app) const;
- bool IsPrevious(const HistoryEntry &) const;
- bool IsCurrent(const HistoryEntry &) const;
- protected:
- History() {};
- std::vector<HistoryEntry> 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;
- };
- }
|