1 // This is mul/clsfy/clsfy_builder_base.cxx
2 // Copyright: (C) 2000 British Telecommunications plc
3 #include "clsfy_builder_base.h"
4 //:
5 // \file
6 // \brief Implement bits of an abstract classifier builder
7 // \author Ian Scott
8 // \date 2000-05-10
9 // \verbatim
10 // Modifications
11 // 2 May 2001 IMS Converted to VXL
12 // \endverbatim
13
14
15 //=======================================================================
16
17 #include "vsl/vsl_indent.h"
18 #include "vsl/vsl_binary_loader.h"
19 #include <mbl/mbl_cloneables_factory.h>
20 #include <mbl/mbl_read_props.h>
21
22
23
24 //: Initialise the parameters from a text stream.
25 // Default case accepts no parameters.
config(std::istream & as)26 void clsfy_builder_base::config(std::istream &as)
27 {
28 mbl_read_props_type props = mbl_read_props_ws(as);
29
30 // Check there are no unused properties
31 mbl_read_props_look_for_unused_props("clsfy_builder_base::config",
32 props, mbl_read_props_type());
33 }
34
35 //=======================================================================
36 //: Load description from a text stream
37 // The stream should contain the name of the feature extractor
38 // class that will be used, followed by a brace-enclosed list of
39 // parameters for the builder. This function will construct
40 // the appropriate clsfy_builder_base derivative and return that.
41 // \throws if the parse fails.
new_builder(std::istream & as)42 std::unique_ptr<clsfy_builder_base> clsfy_builder_base::new_builder(
43 std::istream &as)
44 {
45 std::string name;
46 as >> name;
47
48 std::unique_ptr<clsfy_builder_base> ps;
49 try
50 {
51 ps = mbl_cloneables_factory<clsfy_builder_base>::get_clone(name);
52 }
53 catch (const mbl_exception_no_name_in_factory & e)
54 {
55 throw (mbl_exception_parse_error( e.what() ));
56 }
57
58 ps->config(as);
59
60 return ps;
61 }
62
63
64 //=======================================================================
65
vsl_add_to_binary_loader(const clsfy_builder_base & b)66 void vsl_add_to_binary_loader(const clsfy_builder_base& b)
67 {
68 vsl_binary_loader<clsfy_builder_base>::instance().add(b);
69 }
70
71 //=======================================================================
72
is_a() const73 std::string clsfy_builder_base::is_a() const
74 {
75 return std::string("clsfy_builder_base");
76 }
77
78 //=======================================================================
79
is_class(std::string const & s) const80 bool clsfy_builder_base::is_class(std::string const& s) const
81 {
82 return s == clsfy_builder_base::is_a();
83 }
84
85 //=======================================================================
86
vsl_b_write(vsl_b_ostream & os,const clsfy_builder_base & b)87 void vsl_b_write(vsl_b_ostream& os, const clsfy_builder_base& b)
88 {
89 b.b_write(os);
90 }
91
92 //=======================================================================
93
vsl_b_read(vsl_b_istream & bfs,clsfy_builder_base & b)94 void vsl_b_read(vsl_b_istream& bfs, clsfy_builder_base& b)
95 {
96 b.b_read(bfs);
97 }
98
99 //=======================================================================
100
operator <<(std::ostream & os,const clsfy_builder_base & b)101 std::ostream& operator<<(std::ostream& os,const clsfy_builder_base& b)
102 {
103 os << b.is_a() << ": ";
104 vsl_indent_inc(os);
105 b.print_summary(os);
106 vsl_indent_dec(os);
107 return os;
108 }
109
110 //=======================================================================
111
vsl_print_summary(std::ostream & os,const clsfy_builder_base * b)112 void vsl_print_summary(std::ostream& os,const clsfy_builder_base* b)
113 {
114 if (b)
115 os << *b;
116 else
117 os << "No clsfy_builder_base defined.";
118 }
119
120 //=======================================================================
121
operator <<(std::ostream & os,const clsfy_builder_base * b)122 std::ostream& operator<<(std::ostream& os,const clsfy_builder_base* b)
123 {
124 vsl_print_summary(os, b);
125 return os;
126 }
127