1 #ifndef __FILEDATA_H 2 #define __FILEDATA_H 3 4 /// @file filedata.h 5 // Copyright (C) 2012 Kyrus. See COPYING for details 6 7 // $Id$ 8 9 #include <set> 10 #include <string> 11 #include <iostream> 12 #include <stdlib.h> 13 #include <assert.h> 14 #include "tchar-local.h" 15 16 /// Contains a fuzzy hash and associated metadata for file 17 class Filedata 18 { 19 public: Filedata()20 Filedata() : m_has_match_file(false) {} 21 22 /// Creates a new Filedata object with the given filename and signature 23 /// 24 /// If sig is not valid, throws std::bad_alloc 25 Filedata(const TCHAR * fn, const char * sig, const char * match_file = NULL); 26 27 /// Creates a new Filedata object with the given filename and signature 28 /// 29 /// If sig is not valid, throws std::bad_alloc 30 Filedata(const std::string& sig, const char * match_file = NULL); 31 32 /// Returns the file's fuzzy hash without a filename. 33 /// std::string("[blocksize]:[sig1]:[sig2]") get_signature(void)34 std::string get_signature(void) const { return m_signature; } 35 36 /// Returns the file's name 37 /// RBF - Should this be a std::wstring? get_filename(void)38 TCHAR * get_filename(void) const { return m_filename; } 39 40 /// Returns true if this file came from a file of known files on the disk has_match_file(void)41 bool has_match_file(void) const { return m_has_match_file; } 42 /// Returns the name of the file on the disk from which this file came 43 /// RBF - Should this be a std::wstring? get_match_file(void)44 std::string get_match_file(void) const { return m_match_file; } 45 46 /// Returns true if this file belongs to a cluster of similar files has_cluster(void)47 bool has_cluster(void) const { return (m_cluster != NULL); } set_cluster(std::set<Filedata * > * c)48 void set_cluster(std::set<Filedata *> *c) { m_cluster = c; } get_cluster(void)49 std::set<Filedata* >* get_cluster(void) const { return m_cluster; } 50 void clear_cluster(void); 51 ~Filedata()52 ~Filedata() { if (m_filename) { free(m_filename); } } 53 54 private: Filedata(const Filedata & other)55 Filedata(const Filedata &other) { assert(false); /* never copy */ } 56 57 std::set<Filedata *> * m_cluster; 58 59 /// Original signature in the form [blocksize]:[sig1]:[sig2] 60 /// It may also contain the filename, but there is no guarantee of that 61 /// one way or the other. 62 std::string m_signature; 63 64 /// RBF - Should this be a std::wstring? 65 TCHAR * m_filename; 66 67 /// File of hashes where we got this known file from, if any 68 std::string m_match_file; 69 bool m_has_match_file; 70 71 /// Returns true if the m_signature field contains a valid fuzzy hash 72 bool valid(void) const; 73 }; 74 75 76 /// Display [blocksize]:[sig1]:[sig2],"filename" 77 std::ostream& operator<<(std::ostream& o, const Filedata& f); 78 79 /// RBF - We can use this IF AND ONLY IF get_filename() returns a std::wstring 80 //bool operator==(const Filedata& a, const Filedata& b); 81 82 #endif // ifndef __FILEDATA_H 83