1 #ifndef __creaImageIOTreeHandlerImageAdder_h_INCLUDED__
2 #define __creaImageIOTreeHandlerImageAdder_h_INCLUDED__
4 #include <creaImageIOTreeHandler.h>
5 #include <creaImageIOTimestampDatabaseHandler.h>
6 #include <creaImageIOImageReader.h>
8 #include <wx/progdlg.h>
9 // Signal/slot mechanism for progress events
10 #include <boost/signal.hpp>
11 #include <boost/bind.hpp>
20 //=======================================================================
21 /// Object which can add images files to a TreeHandler. Is able to parse (recursively) a part of a filesystem to look for known images and load their attributes in order to add the images to a Tree (submission via a TreeHandler::AddBranch)
23 class TreeHandlerImageAdder
26 //====================================================================
28 TreeHandlerImageAdder(TreeHandler* tree);
30 ~TreeHandlerImageAdder();
31 /// Sets the TreeHandler
32 void SetTreeHandler(TreeHandler* tree) { mTreeHandler = tree;}
33 /// Sets the TimestampDatabaseHandler
34 void SetTimestampHandler(TimestampDatabaseHandler* tdh) { mTimestampHandler = tdh;}
35 //====================================================================
37 //====================================================================
38 /// Structure which holds progress information
39 /// To stop the image adder use SetStop()
43 Progress() { Reset(); }
49 mNumberScannedFiles = 0;
50 mNumberScannedDirs = 0;
51 mNumberHandledFiles = 0;
52 mNumberAddedFiles = 0;
55 int GetNumberScannedFiles() const { return mNumberScannedFiles; }
56 int GetNumberScannedDirs() const { return mNumberScannedDirs; }
57 int GetNumberHandledFiles() const { return mNumberHandledFiles; }
58 int GetNumberAddedFiles() const { return mNumberAddedFiles; }
60 void IncNumberScannedFiles() { mNumberScannedFiles++; }
61 void IncNumberScannedDirs() { mNumberScannedDirs++; }
62 void IncNumberHandledFiles() { mNumberHandledFiles++; }
63 void IncNumberAddedFiles() { mNumberAddedFiles++; }
65 void SetStop() { mStop = true; }
66 bool GetStop() const { return mStop; }
70 int mNumberScannedFiles;
71 int mNumberScannedDirs;
72 int mNumberHandledFiles;
73 int mNumberAddedFiles;
75 //=============================================
77 //=============================================
78 const Progress& GetProgress() const { return mProgress; }
79 //=============================================
81 //=============================================
82 typedef boost::signal<void (Progress&)> ProgressSignalType;
83 typedef ProgressSignalType::slot_function_type ProgressCallbackType;
84 //=============================================
86 //==================================================================
87 /// Adds the function f to the list of functions to call
88 /// when the addition progresses.
89 /// f is of type ProgressCallbackType which is:
90 /// void (*ProgressCallbackType)(Progress&)
91 /// To pass a member function 'f' of an instance 'c' of a class 'C'
92 /// as callback you have to 'bind' it, i.e. call:
93 /// ConnectProgressObserver ( boost::bind( &C::f , c, _1 ) );
94 void ConnectProgressObserver(ProgressCallbackType callback);
95 //==================================================================
97 //====================================================================
98 /// Returns if the file can be read or not
99 bool IsHandledFile( const std::string& filename);
100 /// Adds a list of files to the TreeHandler
101 void AddFiles( const std::vector<std::string>& filename );
102 /// (Recursively) adds the files of a directory to the TreeHandler
103 void AddDirectory( const std::string& directory,
105 //====================================================================
109 /// Adds a single file to the TreeHandler
110 /// **WITHOUT** testing wether it is handled or not
111 /// hence you have to call IsHandledFile before using AddFile!
112 void AddFile( const std::string& filename );
114 /// Recursive method which does the main job for AddDirectory
115 void AddDirectoryRecursor( const std::string& directory,
118 TreeHandler* mTreeHandler;
119 TimestampDatabaseHandler* mTimestampHandler;
123 ProgressSignalType mProgressSignal;
127 // EO class TreeHandlerImageAdder
128 //=======================================================================
134 } // EO namespace creaImageIO
137 inline std::ostream& operator << ( std::ostream& o,
138 const creaImageIO::TreeHandlerImageAdder::Progress& p)
140 o << p.GetNumberScannedFiles() << " files - "
141 << p.GetNumberScannedDirs() << " dirs - "
142 << p.GetNumberHandledFiles() << " handled -"
143 << p.GetNumberAddedFiles() << " added";