]> Creatis software - creaImageIO.git/blob - src/creaImageIOTimestampDatabaseHandler.h
#3185 creaImageIO Feature New Normal - Clean code
[creaImageIO.git] / src / creaImageIOTimestampDatabaseHandler.h
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image 
5 #                        pour la Santé)
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 #
10 #  This software is governed by the CeCILL-B license under French law and 
11 #  abiding by the rules of distribution of free software. You can  use, 
12 #  modify and/ or redistribute the software under the terms of the CeCILL-B 
13 #  license as circulated by CEA, CNRS and INRIA at the following URL 
14 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
15 #  or in the file LICENSE.txt.
16 #
17 #  As a counterpart to the access to the source code and  rights to copy,
18 #  modify and redistribute granted by the license, users are provided only
19 #  with a limited warranty  and the software's author,  the holder of the
20 #  economic rights,  and the successive licensors  have only  limited
21 #  liability. 
22 #
23 #  The fact that you are presently reading this means that you have had
24 #  knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------
26 */
27
28
29 #ifndef __creaImageIOTimestampDatabaseHandler_h_INCLUDED__
30 #define __creaImageIOTimestampDatabaseHandler_h_INCLUDED__
31 #include <vector>
32 #include <map>
33 #include <creaImageIOTree.h>
34 class CppSQLite3DB;
35
36 namespace creaImageIO
37 {
38         using namespace std;
39 //=======================================================================
40   /// Concrete TreeHandler which manages a Tree stored in a sqlite database
41   class TimestampDatabaseHandler 
42   {
43   public:
44     //====================================================================
45     /// Ctor with database file name 
46     TimestampDatabaseHandler(const std::string& filename);
47     /// Dtor
48     virtual ~TimestampDatabaseHandler();
49     //====================================================================
50
51     //====================================================================
52     /// Returns the sqlite db file name 
53     const std::string& GetFileName() const { return mFileName; }
54     //====================================================================
55  
56     //====================================================================
57     // INITIALIZATION / FINALIZATION
58     //====================================================================
59
60     //====================================================================
61     /// Opens an existing 'source' 
62      bool Open();
63     /// Closes the 'source'
64     bool Close();
65     /// Creates a new 'source' 
66     bool Create();
67     /// Destroys the 'source'
68     bool Destroy();
69     //====================================================================
70
71         //====================================================================
72     // READ / WRITE
73     //====================================================================
74         //====================================================================
75         ///Returns the id of the path if it's indexed, blank otherwise
76         std::string IsIndexed(const std::string& path, const std::string& refdb);
77     ///Sets the current path's parent
78         bool AddDirectory(const std::string& parent,
79                                    const std::string& path, 
80                                    const time_t lastModif, 
81                                    const time_t lastRead,
82                                    const std::string& refdb);
83         ///Adds a new file to the database without a parent
84         void AddFile(const std::string& path, const time_t lastModif, const time_t lastRead, const std::string& refdb);
85         ///Adds a new file to the database with a parent
86         void AddFile(const std::string& parentId,const std::string& path, const time_t lastModif, const time_t lastRead, const std::string& refdb);
87         ///Sets the attribute to the value passed as parameter where the searchParameter is searchValue
88         void SetAttribute(const std::string& attName, 
89                                         const std::string& attValue,
90                                         const std::string& searchParam,
91                                         const std::string& searchValue);
92         ///Removes the given node
93         void RemoveNode(const std::string& searchAtt, const tree::Node* node, const std::string& refdb);
94         ///Removes the filename with the given pathname
95         void RemoveFile(const std::string& searchAtt, const std::string& searchVal, const std::string& refdb);
96         ///Cleans the path name
97         void CleanPath(std::string& str) const;
98         ///Checks the timestamp in the database and compares it with the given one. 
99         //If there is a difference, it will return false, otherwise it will return true.
100         bool CheckTimestamp(const std::string pathId, const time_t lastModif, const std::string& refdb);
101         ///Removes the entries that match the given parameters
102         void RemoveEntries(const std::string i_table, 
103                 const std::string i_attribute, 
104                 const std::string i_operand, 
105                 const std::string i_val);
106
107         //====================================================================
108
109
110   protected:
111     //======================================================================
112     /// Open the database
113     bool DBOpen();
114     //======================================================================
115     //======================================================================
116     // Creation
117     /// Creates a new database on disk and the tables
118     bool DBCreate();
119     //======================================================================
120         //======================================================================
121     // Removes a file from the database
122         void DBRemove(const std::string& searchAtt, const std::string& searchVal, const std::string& refdb);
123  
124   private:
125     /// The DB
126     CppSQLite3DB* mDB;
127    /// The physical location associated to the DicomDatabase (directory, db file...)
128     std::string mFileName;
129   
130   };
131   // EO class
132   //=======================================================================
133
134
135 } // EO namespace creaImageIO
136
137 // EOF
138 #endif  
139