1 #ifndef __creaImageIOGimmick_h_INCLUDED__
2 #define __creaImageIOGimmick_h_INCLUDED__
4 #include <creaImageIOSQLiteTreeHandler.h>
5 #include <creaImageIOTreeHandlerImageAdder.h>
6 #include <creaImageIOSynchron.h>
7 #include <creaImageIOSettings.h>
14 #define DEBUG_NEW new(_NORMAL_BLOCK ,__FILE__, __LINE__)
20 #ifdef TRACKING_MEMORY_LEAKS
22 #pragma warning(disable : 4291)
25 void * operator new( size_t size, int line, const char *file );
26 void * operator new[]( size_t size, int line, const char *file );
27 void operator delete( void *p );
28 void operator delete[]( void *p );
34 #define OMISCID_NEW new( __LINE__, __FILE__ )
36 #else // TRACKING_MEMORY_LEAKS is not defined
38 #define OMISCID_NEW new
46 * \defgroup Controller Controller
52 * \defgroup Model Model
55 * \defgroup GUI Top level graphical user interfaces
58 * \defgroup IO Image I/O classes
61 * \defgroup Tree Attributed tree management
64 * \defgroup Previewer Preview related
71 //=======================================================================
72 /// Central controler of the gimmick application
76 /// the selected attributes by end-user
79 // name of database to get attributes
81 // attributes available in this databse
82 std::vector<std::string> inside;
83 // attributes not available in this databse
84 std::vector<std::string> outside;
89 class CREAIMAGEIO_EXPORT Gimmick
98 typedef TreeHandlerImageAdder::Progress AddProgress;
99 typedef TreeHandlerImageAdder::ProgressCallbackType AddProgressCallbackType;
101 /// Adds the function f to the list of functions to call
102 /// when addition operations progres.
103 /// f is of type AddProgressCallbackType which is:
104 /// void (*AddProgressCallbackType)(AddProgress&)
105 /// To pass a member function 'f' of an instance 'c' of a class 'C'
106 /// as callback you have to 'bind' it, i.e. call:
107 /// ConnectAddProgressObserver ( boost::bind( &C::f , c, _1 ) );
108 void ConnectAddProgressObserver( AddProgressCallbackType callback )
109 { mImageAdder.ConnectProgressObserver(callback); }
112 const AddProgress& GetAddProgress() const { return mImageAdder.GetProgress(); }
114 /// Initializes with default values (read/creates databases, etc.)
117 /// Initializes with the local database descriptor in the path given (read/creates databases, etc.)
118 void Initialize(const std::string namedescp, const std::string namedb = "Local Database");
120 /// Finalize (closes databases, etc.)
123 /// Sets level for messages "Gimmick!"
124 static void SetMessageLevel(int level);
125 /// Sets level for debug messages "Gimmick! DEBUG"
126 static void SetDebugMessageLevel(int level);
128 /// Type of map from TreeHandler name to TreeHandler*
129 typedef std::map<std::string, TreeHandler*> TreeHandlerMapType;
131 typedef std::map<std::string, TreeHandler*>::const_iterator ItTreeHandlerMap;
133 /// Returns the TreeHandlerMap (ref)
134 TreeHandlerMapType& GetTreeHandlerMap() { return mTreeHandlerMap; }
136 /// Returns the TreeHandlerMap (const ref)
137 const TreeHandlerMapType& GetTreeHandlerMap() const
138 { return mTreeHandlerMap; }
140 /// Add the files to the given TreeHandler
141 void AddFiles(const std::string& handler,
142 const std::vector<std::string>& filenames);
144 /// Add a dir to the given TreeHandler
145 void AddDir(const std::string& handler, const std::string& path,
148 /// Removes a file from the given TreeHandler
149 void RemoveFile(const std::string& d,
150 tree::Node* filename);
152 ///Deletes the given drive name from the databases
153 void DeleteDrive(const std::string& drive);
156 /// Copies the files into the local directory
157 void CopyFiles(const std::vector<std::string>& filenames, const std::string& d );
160 ///Synchronizes the loaded data with the database d. If repair is true the database will be updated, otherwise
161 ///only a warning sign will be issued
162 std::string Synchronize(const std::string& d, bool repair, bool checkAttributes);
164 /// Prints the tree handled by the handler
165 void Print(const std::string& handler);
167 ///create a DB from a given descriptor file and for a specific location
168 SQLiteTreeHandler* createDB(const std::string &i_name,
169 const std::string &i_locDesc,
170 const std::string &i_locDB);
172 /// add an existent DB
173 void addDB(const std::string &i_nameDB, const std::string &i_locationDB);
175 /// Returns the TreeHandler with a given name
176 TreeHandler* GetTreeHandler(const std::string& name) const;
179 SQLiteTreeHandler* GetLocalDatabase() { return mLocalDatabase; }
181 const SQLiteTreeHandler* GetLocalDatabase() const { return mLocalDatabase; }
183 ///Returns the given setting value for the given setting parameter
184 void GetSetting(const std::string& name, std::string& value);
186 ///Updates the settings file
187 void UpdateSetting(const std::string& name, const std::string& value);
189 /// add DB from Settings file
190 void addDBSettings();
192 ///Edits the field described by the name and key provided with the value given
193 void EditField(tree::Node* node, const std::string& d, const std::string& name, const std::string& key, const std::string& val);
195 /// Returns the attributes in results described in params
196 void GetAttributes(const std::string& d,
197 const std::string& filename,
198 const std::vector<std::string>& params,
199 std::vector<std::string>& results);
201 /// get Values for given attributes
202 void GetAttributes(const std::string filename, std::map<std::string, std::string> &i_res, OutputAttr i_attr);
204 const std::string& GetHomeDirectory();
205 const std::string& GetUserSettingsDirectory();
206 void CreateUserSettingsDirectory();
207 const std::string& GetLocalDatabasePath();
209 /// Decide if attributes are available through database
210 void fillVectInfos(std::vector<std::string> i_attr, OutputAttr &infos);
212 /// Get Add Opertaion summary
213 const std::string getSummary();
214 //=============================================
216 SQLiteTreeHandler* mLocalDatabase;
217 TreeHandlerMapType mTreeHandlerMap;
218 Synchronizer* mSynchronizer;
220 std::string mCurrentDirectory;
221 std::string mHomeDirectory;
222 std::string mUserSettingsDirectory;
223 std::string mLocalDatabasePath;
225 TreeHandlerImageAdder mImageAdder;
226 std::string mLocalDBName;
227 std::string mLocalDescpName;
230 //=======================================================================
233 } // EO namespace creaImageIO