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