]> Creatis software - creaImageIO.git/blob - src2/creaImageIOSynchron.h
422c2ebb79c4db2e51118a1be4b3c6a32d682b2f
[creaImageIO.git] / src2 / 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                           ///The current AddList
106               std::vector<AddList>  mAddList;
107                           ///The current RemoveList
108               std::vector<RemoveList>  mIgnoreList;
109       private :
110              
111               /// The DB
112               CppSQLite3DB* mDB;
113                           ///Path of the current database
114               std::string pathDB;
115                           ///Creates a new database
116               void CreateDB();
117                           ///Updates the AddList
118               void UpdateAddList(const std::string& refdb);
119                           ///Cleans the list in case operations are no longer useful (0 added files)
120               void CleanList(const std::string& refdb);
121                           ///Cleans the name (changes slashes and backslashes according to the system)
122                           void CleanName(std::string& str) const;
123                           ///Gets the ignore list
124                       std::vector<std::string> GetIgnoreList(const std::string &i_key);
125
126     };
127    //================================================================================================================
128
129        
130
131 // EOF
132 #endif
133