]> Creatis software - creaImageIO.git/blob - src/creaImageIOSynchron.h
#3185 creaImageIO Feature New Normal - Clean code
[creaImageIO.git] / src / creaImageIOSynchron.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 __creaImageIOSynchron_h_INCLUDED__
30 #define __creaImageIOSynchron_h_INCLUDED__
31
32 #include <string>
33 #include <map>
34 #include <iostream>
35 #include <vector>
36 #include "CppSQLite3.h"
37
38 namespace creaImageIO
39 {
40         using namespace std;
41    //================================================================================================================
42         ///Represents the list of currently added files
43     class AddList
44     {
45       public :
46                   ///Key to be added into the database
47               std::string key;
48                           ///Path of the directory
49               std::string path;
50                           /// Defines if the operation was recursive or not
51               std::string recursive;
52                           ///Number of added files
53               std::string nbFiles;
54                           ///Ctor
55               AddList(CppSQLite3Query& res):
56                           key(res.getStringField(0)), 
57                           path(res.getStringField(1)),
58                           recursive(res.getStringField(2)),
59                           nbFiles(res.getStringField(3))
60               {}
61     };
62    //================================================================================================================
63
64    //================================================================================================================
65         ///Represents the list of currently removed files
66         class RemoveList
67     {
68       public :
69                   ///Key to be added into the database
70               std::string key;
71                           ///Path of the remove file
72               std::string path;
73                           ///Defines if the file was removed or not
74               std::string remove;
75                           ///Time of the last change of the file
76               std::string time;
77              ///Ctor
78               RemoveList(CppSQLite3Query& res):
79                           key(res.getStringField(1)), 
80                           path(res.getStringField(2)),
81                           remove(res.getStringField(3)),
82                           time(res.getStringField(4))
83                           {}
84     };
85    //================================================================================================================
86   
87    //================================================================================================================
88         ///In charge of the synchronization of the database and the disk state.
89     class Synchronizer
90     {
91       public:
92                   ///Ctor
93               Synchronizer(const std::string& path);
94                           ///Dtor
95               virtual ~Synchronizer();
96                           ///Initializes the database
97                           void Initialize();
98                           ///Inserts an add operation to the database
99                           void InsertAddOp(const std::string& path, 
100                                                         const std::string& recursive,
101                                                         const std::string& nChildren, 
102                                                         const std::string& refdb);
103                           ///Inserts a file to be ignored
104                           void InsertIgnoreFile(const std::string& addKey,
105                                                         const std::string& path, 
106                                                         const std::string& remove,
107                                                         const std::string& time,
108                                                         const std::string& refdb);
109                           ///Removes an entry that matches the given parameter
110                           void RemoveEntry(const std::string i_table, const std::string i_key);
111                           ///Removes several entries
112                           void RemoveEntries(const std::string i_table, 
113                                                                                         const std::string i_attribute, 
114                                                                                         const std::string i_operand, 
115                                                                                         const std::string i_key);
116                           ///Gets the list of AddFiles
117                           void GetFileList(std::vector<AddList>& files , const std::string& refdb);
118                           ///Gets the list of ignored files
119                           void GetIgnoredFiles(const std::string& key, std::vector<std::string> &ignoreList);
120                           ///Gets the attribute that matches the parameters
121                           std::string GetAttribute(const std::string& attribute, 
122                                                                                 const std::string& table, 
123                                                                                 const std::string& searchParam,
124                                                                                 const std::string& searchValue,
125                                                                                 const std::string& refdb);
126                           ///Sets an attribute to an entry that matches the given parameters
127                           void SetAttribute(const std::string& attribute, 
128                                                                                 const std::string& table, 
129                                                                                 const std::string& value,
130                                                                                 const std::string& searchParam,
131                                                                                 const std::string& searchValue, 
132                                                                                 const std::string& refdb);
133                           // Get the List of indexed files (removed or not)
134                           void GetList(const std::string i_db);
135                           // Test to not if a file is indexed on db or not
136                           bool isIndexed(const std::string filename);
137                           // List of all indexed files
138                           std::map <std::string, bool> mList;
139                           ///The current AddList
140               std::vector<AddList>  mAddList;
141                           ///The current RemoveList
142               std::vector<RemoveList>  mIgnoreList;
143       private :
144              
145               /// The DB
146               CppSQLite3DB* mDB;
147                           ///Path of the current database
148               std::string pathDB;
149                           ///Creates a new database
150               void CreateDB();
151                           ///Updates the AddList
152               void UpdateAddList(const std::string& refdb);
153                           ///Cleans the list in case operations are no longer useful (0 added files)
154               void CleanList(const std::string& refdb);
155                           ///Cleans the name (changes slashes and backslashes according to the system)
156                           void CleanName(std::string& str) const;
157                           ///Gets the ignore list
158                       std::vector<std::string> GetIgnoreList(const std::string &i_key);
159                           const std::string convert(const std::string &i_word);
160
161     };
162    //================================================================================================================
163
164        
165
166 // EOF
167 #endif
168