| |
| |
| #ifndef T_FILEPATH_INCLUDED |
| #define T_FILEPATH_INCLUDED |
| |
| #include "tcommon.h" |
| #include "texception.h" |
| |
| #undef DVAPI |
| #undef DVVAR |
| #ifdef TSYSTEM_EXPORTS |
| #define DVAPI DV_EXPORT_API |
| #define DVVAR DV_EXPORT_VAR |
| #else |
| #define DVAPI DV_IMPORT_API |
| #define DVVAR DV_IMPORT_VAR |
| #endif |
| |
| class QString; |
| |
| |
| |
| |
| |
| |
| |
| |
| class DVAPI TFrameId |
| { |
| int m_frame; |
| char m_letter; |
| |
| public: |
| enum { EMPTY_FRAME = -1, |
| NO_FRAME = -2 |
| }; |
| |
| enum FrameFormat { |
| FOUR_ZEROS, |
| NO_PAD, |
| UNDERSCORE_FOUR_ZEROS, |
| UNDERSCORE_NO_PAD |
| }; |
| |
| TFrameId(int f = EMPTY_FRAME) : m_frame(f), m_letter(0){}; |
| TFrameId(int f, char c) : m_frame(f), m_letter(c){}; |
| |
| inline bool operator==(const TFrameId &f) const { return f.m_frame == m_frame && f.m_letter == m_letter; }; |
| inline bool operator!=(const TFrameId &f) const { return (m_frame != f.m_frame || m_letter != f.m_letter); }; |
| inline bool operator<(const TFrameId &f) const { return (m_frame < f.m_frame || (m_frame == f.m_frame && m_letter < f.m_letter)); }; |
| inline bool operator>(const TFrameId &f) const { return f < *this; } |
| inline bool operator>=(const TFrameId &f) const { return !operator<(f); } |
| inline bool operator<=(const TFrameId &f) const { return !operator>(f); } |
| |
| const TFrameId &operator++(); |
| const TFrameId &operator--(); |
| |
| TFrameId &operator=(const TFrameId &f) |
| { |
| m_frame = f.m_frame; |
| m_letter = f.m_letter; |
| return *this; |
| }; |
| |
| bool isEmptyFrame() const { return m_frame == EMPTY_FRAME; }; |
| bool isNoFrame() const { return m_frame == NO_FRAME; }; |
| |
| |
| string expand(FrameFormat format = FOUR_ZEROS) const; |
| int getNumber() const { return m_frame; }; |
| char getLetter() const { return m_letter; }; |
| }; |
| |
| |
| |
| |
| inline ostream &operator<<(ostream &out, const TFrameId &f) |
| { |
| if (f.isNoFrame()) |
| out << "<noframe>"; |
| else if (f.isEmptyFrame()) |
| out << "''"; |
| else |
| out << f.expand().c_str(); |
| return out; |
| } |
| |
| |
| |
| |
| |
| class DVAPI TFilePath |
| { |
| static bool m_underscoreFormatAllowed; |
| wstring m_path; |
| void setPath(wstring path); |
| |
| public: |
| |
| static void setUnderscoreFormatAllowed(bool state) { m_underscoreFormatAllowed = state; } |
| |
| |
| |
| |
| |
| |
| explicit TFilePath(const char *path = ""); |
| explicit TFilePath(const string &path); |
| explicit TFilePath(const std::wstring &path); |
| explicit TFilePath(const QString &path); |
| |
| ~TFilePath(){}; |
| TFilePath(const TFilePath &fp) : m_path(fp.m_path) {} |
| TFilePath &operator=(const TFilePath &fp) |
| { |
| m_path = fp.m_path; |
| return *this; |
| } |
| |
| bool operator==(const TFilePath &fp) const; |
| inline bool operator!=(const TFilePath &fp) const { return !(m_path == fp.m_path); } |
| bool operator<(const TFilePath &fp) const; |
| |
| const std::wstring getWideString() const; |
| QString getQString() const; |
| |
| |
| |
| |
| |
| string getDots() const; |
| |
| |
| |
| string getDottedType() const; |
| |
| |
| |
| string getUndottedType() const; |
| |
| |
| |
| |
| string getType() const { return getUndottedType(); }; |
| |
| string getName() const; |
| wstring getWideName() const; |
| |
| |
| |
| |
| string getLevelName() const; |
| std::wstring getLevelNameW() const; |
| |
| |
| TFilePath getParentDir() const; |
| |
| TFrameId getFrame() const; |
| |
| bool isLevelName() const; |
| bool isAbsolute() const; |
| bool isRoot() const; |
| bool isEmpty() const { return m_path == L""; }; |
| |
| |
| |
| TFilePath withType(const string &type) const; |
| |
| TFilePath withName(const string &name) const; |
| |
| TFilePath withName(const std::wstring &name) const; |
| |
| TFilePath withParentDir(const TFilePath &dir) const; |
| |
| TFilePath withoutParentDir() const { return withParentDir(TFilePath()); } |
| |
| TFilePath withFrame(const TFrameId &frame, TFrameId::FrameFormat format = TFrameId::FOUR_ZEROS) const; |
| |
| TFilePath withFrame(int f) const { return withFrame(TFrameId(f)); }; |
| |
| TFilePath withFrame(int f, char letter) const { return withFrame(TFrameId(f, letter)); }; |
| |
| TFilePath withFrame() const { return withFrame(TFrameId(TFrameId::EMPTY_FRAME)); }; |
| TFilePath withNoFrame() const { return withFrame(TFrameId(TFrameId::NO_FRAME)); }; |
| |
| TFilePath operator+(const TFilePath &fp) const; |
| TFilePath &operator+=(const TFilePath &fp) ; |
| |
| inline TFilePath operator+(const string &s) const |
| { |
| return operator+(TFilePath(s)); |
| }; |
| inline TFilePath &operator+=(const string &s) |
| { |
| return operator+=(TFilePath(s)); |
| }; |
| |
| TFilePath &operator+=(const std::wstring &s); |
| TFilePath operator+(const std::wstring &s) const |
| { |
| TFilePath res(*this); |
| return res += s; |
| } |
| |
| bool isAncestorOf(const TFilePath &) const; |
| |
| TFilePath operator-(const TFilePath &fp) const; |
| |
| |
| bool match(const TFilePath &fp) const; |
| |
| |
| void split(wstring &head, TFilePath &tail) const; |
| }; |
| |
| |
| |
| class TMalformedFrameException : public TException |
| { |
| public: |
| TMalformedFrameException(const TFilePath &fp, const wstring &msg = wstring()) |
| : TException(fp.getWideName() + L":" + msg) |
| { |
| } |
| |
| private: |
| TMalformedFrameException(); |
| }; |
| |
| |
| |
| DVAPI ostream &operator<<(ostream &out, const TFilePath &path); |
| |
| typedef list<TFilePath> TFilePathSet; |
| |
| #endif |
| |