File indexing completed on 2024-05-12 04:38:06
0001 /* 0002 SPDX-FileCopyrightText: 2008 David Nolden <david.nolden.kdevelop@art-master.de> 0003 0004 SPDX-License-Identifier: LGPL-2.0-only 0005 */ 0006 0007 #ifndef KDEVPLATFORM_MODIFICATIONREVISION_H 0008 #define KDEVPLATFORM_MODIFICATIONREVISION_H 0009 0010 #include <QDateTime> 0011 #include <language/languageexport.h> 0012 #include "../backgroundparser/documentchangetracker.h" 0013 0014 class QString; 0015 0016 namespace KDevelop { 0017 class IndexedString; 0018 0019 KDEVPLATFORMLANGUAGE_EXPORT extern const int cacheModificationTimesForSeconds; 0020 0021 /** 0022 * Pairs together a date and a revision-number, for simpler moving around and comparison. Plus some convenience-functions. 0023 * Use this to track changes to files, by storing the file-modification time and the editor-revision if applicable (@see KTextEditor::MovingInterface) 0024 * 0025 * All member-functions except the IndexedString constructor directly act on the two members, without additional logic. 0026 * 0027 * Does not need a d-pointer, is only a container-class. 0028 * 0029 * It is safe to store this class in the disk-mapped internal duchain data structures. 0030 * 0031 * */ 0032 class KDEVPLATFORMLANGUAGE_EXPORT ModificationRevision 0033 { 0034 public: 0035 ///Constructs a ModificationRevision for the file referenced by the given string, which should have been constructed using QUrl::pathOrUrl at some point 0036 ///This is efficient, because it uses a cache to look up the modification-revision, caching file-system stats for some time 0037 static ModificationRevision revisionForFile(const IndexedString& fileName); 0038 0039 ///You can use this when you want to make sure that any cached on-disk modification-time is discarded 0040 ///and it's re-read from disk on the next access. 0041 ///Otherwise, the on-disk modification-times are re-used for a specific amount of time 0042 static void clearModificationCache(const IndexedString& fileName); 0043 0044 ///The default-revision is 0, because that is the kate moving-revision for cleanly opened documents 0045 explicit ModificationRevision(const QDateTime& modTime = QDateTime(), int revision_ = 0); 0046 0047 bool operator <(const ModificationRevision& rhs) const; 0048 0049 bool operator==(const ModificationRevision& rhs) const; 0050 0051 bool operator!=(const ModificationRevision& rhs) const; 0052 0053 QString toString() const; 0054 0055 uint modificationTime; //On-disk modification-time of a document in time_t format 0056 int revision; //MovingInterface revision of a document 0057 0058 private: 0059 friend class DocumentChangeTracker; 0060 static void setEditorRevisionForFile(const IndexedString& filename, int revision); 0061 static void clearEditorRevisionForFile(const IndexedString& filename); 0062 }; 0063 } 0064 0065 #endif