]> Creatis software - creaImageIO.git/blob - src2/creaImageIOGimmick.h
memory leak tracking
[creaImageIO.git] / src2 / creaImageIOGimmick.h
1 #ifndef __creaImageIOGimmick_h_INCLUDED__
2 #define __creaImageIOGimmick_h_INCLUDED__
3
4 #include <creaImageIOSQLiteTreeHandler.h>
5 #include <creaImageIOTreeHandlerImageAdder.h>
6 #include <creaImageIOSynchron.h>
7 #include <creaImageIOSettings.h>
8
9
10 #ifdef _DEBUG
11 #include <crtdbg.h>
12 #define DEBUG_NEW new(_NORMAL_BLOCK ,__FILE__, __LINE__)
13 #else
14 #define DEBUG_NEW new
15 #endif
16 // Only when asked
17 /*
18 #ifdef TRACKING_MEMORY_LEAKS
19 #ifdef WIN32
20 #pragma warning(disable : 4291)
21 #endif
22
23 void * operator new( size_t size, int line, const char *file );
24 void * operator new[]( size_t size, int line, const char *file );
25 void operator delete( void *p );
26 void operator delete[]( void *p );
27
28 #ifdef OMISCID_NEW
29 #undef OMISCID_NEW
30 #endif
31
32 #define OMISCID_NEW new( __LINE__, __FILE__ )
33
34 #else // TRACKING_MEMORY_LEAKS is not defined
35
36 #define OMISCID_NEW new
37
38 #endif*/
39
40
41 namespace creaImageIO
42 {
43         /**
44         * \defgroup Controller Controller
45         */
46         /**
47         * \defgroup View View
48         */
49         /**
50         * \defgroup Model Model
51         */
52         /**
53         * \defgroup GUI Top level graphical user interfaces
54         */
55         /**
56         * \defgroup IO Image I/O classes
57         */
58         /**
59         * \defgroup Tree Attributed tree management
60         */
61         /**
62         * \defgroup Previewer Preview related
63         */
64
65         /**
66         * \ingroup Controller
67         */
68
69   //=======================================================================
70   /// Central controler of the gimmick application
71   class CREAIMAGEIO_EXPORT Gimmick
72   {
73   public:
74     /// Ctor
75     Gimmick();
76     /// Dtor
77     ~Gimmick();
78     
79     ///
80     typedef TreeHandlerImageAdder::Progress AddProgress;
81     typedef TreeHandlerImageAdder::ProgressCallbackType AddProgressCallbackType;
82     
83     /// Adds the function f to the list of functions to call 
84     /// when addition operations progres.
85     /// f is of type AddProgressCallbackType which is:
86     /// void (*AddProgressCallbackType)(AddProgress&)
87     /// To pass a member function 'f' of an instance 'c' of a class 'C' 
88     /// as callback you have to 'bind' it, i.e. call:
89     /// ConnectAddProgressObserver ( boost::bind( &C::f , c, _1 ) );
90      void ConnectAddProgressObserver( AddProgressCallbackType callback )
91     { mImageAdder.ConnectProgressObserver(callback); }
92     
93     ///
94     const AddProgress& GetAddProgress() const { return mImageAdder.GetProgress(); }
95
96     /// Initializes with default values (read/creates databases, etc.)
97     void Initialize();
98
99         /// Initializes with the local database descriptor in the path given (read/creates databases, etc.)
100     void Initialize(const std::string& path);
101     
102     /// Finalize (closes databases, etc.)
103     void Finalize();
104
105     /// Sets level for messages "Gimmick!" 
106     static void SetMessageLevel(int level);
107     /// Sets level for debug messages "Gimmick! DEBUG" 
108     static void SetDebugMessageLevel(int level);
109     
110     /// Type of map from TreeHandler name to TreeHandler*
111         typedef std::map<std::string, TreeHandler*> TreeHandlerMapType;
112
113     /// Returns the TreeHandlerMap (ref)
114     TreeHandlerMapType& GetTreeHandlerMap() { return mTreeHandlerMap; }
115     /// Returns the TreeHandlerMap (const ref)
116     const TreeHandlerMapType& GetTreeHandlerMap() const
117     { return mTreeHandlerMap; }    
118
119     /// Add the files to the given TreeHandler
120     void AddFiles(const std::string& handler,
121                   const std::vector<std::string>& filenames);
122
123     /// Add a dir to the given TreeHandler
124     void AddDir(const std::string& handler, const std::string& path, 
125                 bool recurse);
126
127         /// Removes a file from the given TreeHandler
128         void RemoveFile(const std::string& d, 
129                         tree::Node* filename);
130
131         ///Deletes the given drive name from the databases
132         void DeleteDrive(const std::string& drive);
133   
134
135         /// Copies the files into the local directory
136         void CopyFiles(const std::vector<std::string>& filenames, const std::string& d );
137   
138
139         ///Synchronizes the loaded data with the database d. If repair is true the database will be updated, otherwise 
140         ///only a warning sign will be issued
141         std::string Synchronize(const std::string& d, bool repair, bool checkAttributes);
142
143     /// Prints the tree handled by the handler
144     void Print(const std::string& handler);
145         
146     ///create a DB from a given descriptor file and for a specific location
147         SQLiteTreeHandler* createDB(const std::string &i_name, 
148                                 const std::string &i_locDesc, 
149                                 const std::string &i_locDB);
150
151         /// add an existent DB 
152         void addDB(const std::string &i_nameDB, const std::string &i_locationDB);
153
154     /// Returns the TreeHandler with a given name
155     TreeHandler* GetTreeHandler(const std::string& name) const;
156
157         /// 
158         SQLiteTreeHandler* GetLocalDatabase() { return mLocalDatabase; }
159
160     const SQLiteTreeHandler* GetLocalDatabase() const     { return mLocalDatabase; }
161
162         ///Returns the given setting value for the given setting parameter
163         void GetSetting(const std::string& name, std::string& value);
164
165         ///Updates the settings file
166         void UpdateSetting(const std::string& name, const std::string& value);
167
168         /// add DB from Settings file
169     void addDBSettings();
170
171         ///Edits the field described by the name and key provided with the value given
172         void EditField(tree::Node* node, const std::string& d, const std::string& name, const std::string& key, const std::string& val);
173
174         /// Returns the attributes in results described in params
175         void GetAttributes(const std::string& d, 
176           const std::string& filename, 
177           const std::vector<std::string>& params, 
178           std::vector<std::string>& results);
179   
180     /// 
181     const std::string& GetHomeDirectory();
182     const std::string& GetUserSettingsDirectory();
183     void CreateUserSettingsDirectory();
184     const std::string& GetLocalDatabasePath();
185         
186
187
188     //=============================================
189   private:
190         SQLiteTreeHandler* mLocalDatabase;
191         TreeHandlerMapType mTreeHandlerMap;
192         Synchronizer* mSynchronizer;
193
194     std::string mCurrentDirectory;
195     std::string mHomeDirectory;
196     std::string mUserSettingsDirectory;
197     std::string mLocalDatabasePath;
198         Settings        *mSettings;
199     TreeHandlerImageAdder mImageAdder;
200   };
201   // EO class Gimmick
202   //=======================================================================
203
204
205 } // EO namespace creaImageIO
206
207 // EOF
208 #endif  
209
210