]> Creatis software - creaImageIO.git/blob - src/creaImageIOTimestampDatabaseHandler.h
056614116d77f895ef1e95ac06bd1459193e1e3d
[creaImageIO.git] / src / creaImageIOTimestampDatabaseHandler.h
1 #ifndef __creaImageIOTimestampDatabaseHandler_h_INCLUDED__
2 #define __creaImageIOTimestampDatabaseHandler_h_INCLUDED__
3 #include <vector>
4 #include <map>
5 #include <creaImageIOTree.h>
6 class CppSQLite3DB;
7
8 namespace creaImageIO
9 {
10         using namespace std;
11 //=======================================================================
12   /// Concrete TreeHandler which manages a Tree stored in a sqlite database
13   class TimestampDatabaseHandler 
14   {
15   public:
16     //====================================================================
17     /// Ctor with database file name 
18     TimestampDatabaseHandler(const std::string& filename);
19     /// Dtor
20     virtual ~TimestampDatabaseHandler();
21     //====================================================================
22
23     //====================================================================
24     /// Returns the sqlite db file name 
25     const std::string& GetFileName() const { return mFileName; }
26     //====================================================================
27  
28     //====================================================================
29     // INITIALIZATION / FINALIZATION
30     //====================================================================
31
32     //====================================================================
33     /// Opens an existing 'source' 
34      bool Open();
35     /// Closes the 'source'
36     bool Close();
37     /// Creates a new 'source' 
38     bool Create();
39     /// Destroys the 'source'
40     bool Destroy();
41     //====================================================================
42
43         //====================================================================
44     // READ / WRITE
45     //====================================================================
46         //====================================================================
47         ///Returns the id of the path if it's indexed, blank otherwise
48         std::string IsIndexed(const std::string& path, const std::string& refdb);
49     ///Sets the current path's parent
50         bool AddDirectory(const std::string& parent,
51                                    const std::string& path, 
52                                    const time_t lastModif, 
53                                    const time_t lastRead,
54                                    const std::string& refdb);
55         ///Adds a new file to the database without a parent
56         void AddFile(const std::string& path, const time_t lastModif, const time_t lastRead, const std::string& refdb);
57         ///Adds a new file to the database with a parent
58         void AddFile(const std::string& parentId,const std::string& path, const time_t lastModif, const time_t lastRead, const std::string& refdb);
59         ///Sets the attribute to the value passed as parameter where the searchParameter is searchValue
60         void SetAttribute(const std::string& attName, 
61                                         const std::string& attValue,
62                                         const std::string& searchParam,
63                                         const std::string& searchValue);
64         ///Removes the given node
65         void RemoveNode(const std::string& searchAtt, const tree::Node* node, const std::string& refdb);
66         ///Removes the filename with the given pathname
67         void RemoveFile(const std::string& searchAtt, const std::string& searchVal, const std::string& refdb);
68         ///Cleans the path name
69         void CleanPath(std::string& str) const;
70         ///Checks the timestamp in the database and compares it with the given one. 
71         //If there is a difference, it will return false, otherwise it will return true.
72         bool CheckTimestamp(const std::string pathId, const time_t lastModif, const std::string& refdb);
73         ///Removes the entries that match the given parameters
74         void RemoveEntries(const std::string i_table, 
75                 const std::string i_attribute, 
76                 const std::string i_operand, 
77                 const std::string i_val);
78
79         //====================================================================
80
81
82   protected:
83     //======================================================================
84     /// Open the database
85     bool DBOpen();
86     //======================================================================
87     //======================================================================
88     // Creation
89     /// Creates a new database on disk and the tables
90     bool DBCreate();
91     //======================================================================
92         //======================================================================
93     // Removes a file from the database
94         void DBRemove(const std::string& searchAtt, const std::string& searchVal, const std::string& refdb);
95  
96   private:
97     /// The DB
98     CppSQLite3DB* mDB;
99    /// The physical location associated to the DicomDatabase (directory, db file...)
100     std::string mFileName;
101   
102   };
103   // EO class
104   //=======================================================================
105
106
107 } // EO namespace creaImageIO
108
109 // EOF
110 #endif  
111