Cleaner comparators
[backups/.git] / filedata.hpp
index b339f05f92b2fcc4c425e13c119b56bbb37a8a5b..f98b520e5e8d18eef6d2bf79b3a0c58ab181e0eb 100644 (file)
@@ -29,6 +29,30 @@ class FileData {
     void setFileName(       const std::string &arg ) { filename         = arg; }
     void setLastBackupDate( unsigned long long arg ) { last_backup_date = arg; }
 
+    struct LastBackupCmp {
+      bool operator()( const FileData *a, const FileData *b ) {
+        return a->getLastBackupDate() < b->getLastBackupDate();
+      }
+    };
+
+    struct SizeCmp {
+      bool operator()( const FileData *a, const FileData *b ) {
+        return a->getFileSize() < b->getFileSize();
+      }
+    };
+
+    struct NameCmp {
+      bool operator()( const FileData *a, const FileData *b ) {
+        return cmp( a->getFileName(), b->getFileName() );
+      }
+      private:
+        std::less<std::string> cmp;
+    };
+
+    static const LastBackupCmp lastbackupcmp;
+    static const SizeCmp       sizecmp;
+    static const NameCmp       namecmp;
+
   private:
     FileData( const FileData & );
 
@@ -48,29 +72,9 @@ std::istream &operator>>( std::istream &i, FileData *d );
 std::ostream &operator<<( std::ostream &o, const FileData &d );
 std::istream &operator>>( std::istream &i, FileData &d );
 
-struct FileDataLastBackupCmp {
-  bool operator()( const FileData *a, const FileData *b ) {
-    return a->getLastBackupDate() < b->getLastBackupDate();
-  }
-};
-
-struct FileDataSizeCmp {
-  bool operator()( const FileData *a, const FileData *b ) {
-    return a->getFileSize() < b->getFileSize();
-  }
-};
-
-struct FileDataNameCmp {
-  bool operator()( const FileData *a, const FileData *b ) {
-    return cmp( a->getFileName(), b->getFileName() );
-  }
-  private:
-    std::less<std::string> cmp;
-};
-
 bool needs_backup( const FileData *before, const FileData *after );
 
-typedef std::set<FileData*,FileDataNameCmp> file_set;
-typedef std::vector<FileData*> file_vector;
+typedef std::set<FileData*,FileData::NameCmp> file_set;
+typedef std::vector<FileData*>                file_vector;
 
 #endif