creaImageIO_lib
creaImageIOSynchron.h
Go to the documentation of this file.
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  //================================================================================================================
43  class AddList
44  {
45  public :
47  std::string key;
49  std::string path;
51  std::string recursive;
53  std::string nbFiles;
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  //================================================================================================================
66  class RemoveList
67  {
68  public :
70  std::string key;
72  std::string path;
74  std::string remove;
76  std::string time;
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  //================================================================================================================
90  {
91  public:
93  Synchronizer(const std::string& path);
95  virtual ~Synchronizer();
97  void Initialize();
99  void InsertAddOp(const std::string& path,
100  const std::string& recursive,
101  const std::string& nChildren,
102  const std::string& refdb);
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);
110  void RemoveEntry(const std::string i_table, const std::string i_key);
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);
117  void GetFileList(std::vector<AddList>& files , const std::string& refdb);
119  void GetIgnoredFiles(const std::string& key, std::vector<std::string> &ignoreList);
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);
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;
140  std::vector<AddList> mAddList;
142  std::vector<RemoveList> mIgnoreList;
143  private :
144 
148  std::string pathDB;
150  void CreateDB();
152  void UpdateAddList(const std::string& refdb);
154  void CleanList(const std::string& refdb);
156  void CleanName(std::string& str) const;
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