contrib/mul/clsfy/clsfy_builder_base.cxx
Go to the documentation of this file.
00001 // This is mul/clsfy/clsfy_builder_base.cxx
00002 // Copyright: (C) 2000 British Telecommunications plc
00003 #include "clsfy_builder_base.h"
00004 //:
00005 // \file
00006 // \brief Implement bits of an abstract classifier builder
00007 // \author Ian Scott
00008 // \date 2000-05-10
00009 // \verbatim
00010 //  Modifications
00011 //   2 May 2001 IMS Converted to VXL
00012 // \endverbatim
00013 
00014 
00015 //=======================================================================
00016 
00017 #include <vsl/vsl_indent.h>
00018 #include <vsl/vsl_binary_loader.h>
00019 #include <mbl/mbl_cloneables_factory.h>
00020 #include <mbl/mbl_read_props.h>
00021 
00022 
00023 
00024 //: Initialise the parameters from a text stream.
00025 // Default case accepts no parameters.
00026 void clsfy_builder_base::config(vcl_istream &as)
00027 {
00028   mbl_read_props_type props = mbl_read_props_ws(as);
00029     
00030   // Check there are no unused properties
00031   mbl_read_props_look_for_unused_props("clsfy_builder_base::config",
00032                                        props, mbl_read_props_type());
00033 }
00034 
00035 //=======================================================================
00036 //: Load description from a text stream
00037 // The stream should contain the name of the feature extractor
00038 // class that will be used, followed by a brace-enclosed list of
00039 // parameters for the builder. This function will construct
00040 // the appropriate clsfy_builder_base derivative and return that.
00041 // \throws if the parse fails.
00042 vcl_auto_ptr<clsfy_builder_base> clsfy_builder_base::new_builder(
00043   vcl_istream &as)
00044 {
00045   vcl_string name;
00046   as >> name;
00047 
00048   vcl_auto_ptr<clsfy_builder_base> ps;
00049   try
00050   {
00051     ps = mbl_cloneables_factory<clsfy_builder_base>::get_clone(name);
00052   }
00053   catch (const mbl_exception_no_name_in_factory & e)
00054   {
00055     throw (mbl_exception_parse_error( e.what() ));
00056   }
00057 
00058   ps->config(as);
00059   
00060   return ps;
00061 }
00062 
00063 
00064 //=======================================================================
00065 
00066 void vsl_add_to_binary_loader(const clsfy_builder_base& b)
00067 {
00068   vsl_binary_loader<clsfy_builder_base>::instance().add(b);
00069 }
00070 
00071 //=======================================================================
00072 
00073 vcl_string clsfy_builder_base::is_a() const
00074 {
00075   return vcl_string("clsfy_builder_base");
00076 }
00077 
00078 //=======================================================================
00079 
00080 bool clsfy_builder_base::is_class(vcl_string const& s) const
00081 {
00082   return s == clsfy_builder_base::is_a();
00083 }
00084 
00085 //=======================================================================
00086 
00087 void vsl_b_write(vsl_b_ostream& os, const clsfy_builder_base& b)
00088 {
00089   b.b_write(os);
00090 }
00091 
00092 //=======================================================================
00093 
00094 void vsl_b_read(vsl_b_istream& bfs, clsfy_builder_base& b)
00095 {
00096   b.b_read(bfs);
00097 }
00098 
00099 //=======================================================================
00100 
00101 vcl_ostream& operator<<(vcl_ostream& os,const clsfy_builder_base& b)
00102 {
00103   os << b.is_a() << ": ";
00104   vsl_indent_inc(os);
00105   b.print_summary(os);
00106   vsl_indent_dec(os);
00107   return os;
00108 }
00109 
00110 //=======================================================================
00111 
00112 void vsl_print_summary(vcl_ostream& os,const clsfy_builder_base* b)
00113 {
00114   if (b)
00115     os << *b;
00116   else
00117     os << "No clsfy_builder_base defined.";
00118 }
00119 
00120 //=======================================================================
00121 
00122 vcl_ostream& operator<<(vcl_ostream& os,const clsfy_builder_base* b)
00123 {
00124   vsl_print_summary(os, b);
00125   return os;
00126 }
00127