contrib/mul/mbl/mbl_file_data_collector.h
Go to the documentation of this file.
00001 // This is mul/mbl/mbl_file_data_collector.h
00002 #ifndef mbl_file_data_collector_h_
00003 #define mbl_file_data_collector_h_
00004 //:
00005 // \file
00006 // \brief Collect data objects and store them in a file.
00007 // \author dac
00008 
00009 #include <mbl/mbl_data_collector.h>
00010 #include <mbl/mbl_file_data_wrapper.h>
00011 #include <vsl/vsl_binary_io.h>
00012 #include <vcl_string.h>
00013 #include <vcl_iosfwd.h>
00014 
00015 //: Collect data objects and store them in a file.
00016 template<class T>
00017 class mbl_file_data_collector : public mbl_data_collector<T>
00018 {
00019   //: binary file stream where the data is stored
00020   vsl_b_ofstream *bfs_;
00021 
00022   //: path to binary data stream
00023   vcl_string path_;
00024 
00025   //: wrapper object point to same file (return reference to this object!)
00026   mbl_file_data_wrapper<T>* wrapper_;
00027 
00028  public:
00029  
00030   //: Constructor
00031   mbl_file_data_collector( const vcl_string & path );
00032 
00033 //#if 0
00034   // Copy constructor
00035   mbl_file_data_collector(const mbl_data_collector_base& c);
00036   // Copy constructor
00037   mbl_file_data_collector(const mbl_file_data_collector & c);
00038 
00039   //: Copy operator
00040   //virtual mbl_file_data_collector<T>& operator=( const mbl_data_collector_base& c);
00041   virtual mbl_file_data_collector<T>& operator=( const mbl_file_data_collector & c);
00042 //#endif
00043 
00044   //: Destructor
00045   virtual ~mbl_file_data_collector();
00046 
00047   //: Clear any stored data
00048   virtual void clear();
00049 
00050   //: delete stuff
00051   void delete_stuff();
00052 
00053   //: Hint about how many examples to expect
00054   virtual void set_n_samples(int n);
00055 
00056   //: Record given object
00057   virtual void record(const T& v);
00058 
00059   //: Return object describing stored data
00060   virtual mbl_data_wrapper<T >& data_wrapper();
00061 
00062   //: Version number for I/O
00063   short version_no() const;
00064 
00065   //: Name of the class
00066   virtual vcl_string is_a() const;
00067 
00068   //: Does the name of the class match the argument?
00069   virtual bool is_class(vcl_string const& s) const;
00070 
00071   //: Create a copy on the heap and return base class pointer
00072   virtual mbl_data_collector_base* clone() const;
00073 
00074   //: Print class to os
00075   virtual void print_summary(vcl_ostream& os) const;
00076 
00077   //: Save class to binary file stream
00078   virtual void b_write(vsl_b_ostream& bfs) const;
00079 
00080   //: Load class from binary file stream
00081   virtual void b_read(vsl_b_istream& bfs);
00082 
00083 };
00084 
00085 #endif // mbl_file_data_collector_h_