contrib/mul/mcal/mcal_single_basis_cost.cxx
Go to the documentation of this file.
00001 //:
00002 // \file
00003 #include "mcal_single_basis_cost.h"
00004 #include <vcl_cstdlib.h>
00005 #include <mbl/mbl_exception.h>
00006 #include <mbl/mbl_cloneables_factory.h>
00007 #include <mbl/mbl_parse_block.h>
00008 #include <vsl/vsl_indent.h>
00009 #include <vsl/vsl_binary_loader.h>
00010 
00011 //=======================================================================
00012 
00013 mcal_single_basis_cost::mcal_single_basis_cost()
00014 {
00015 }
00016 
00017 //=======================================================================
00018 
00019 mcal_single_basis_cost::~mcal_single_basis_cost()
00020 {
00021 }
00022 
00023 
00024 //=======================================================================
00025 
00026 short mcal_single_basis_cost::version_no() const
00027 {
00028   return 1;
00029 }
00030 
00031 //=======================================================================
00032 
00033 void vsl_add_to_binary_loader(const mcal_single_basis_cost& b)
00034 {
00035   vsl_binary_loader<mcal_single_basis_cost>::instance().add(b);
00036 }
00037 
00038 //=======================================================================
00039 
00040 vcl_string  mcal_single_basis_cost::is_a() const
00041 {
00042   return vcl_string("mcal_single_basis_cost");
00043 }
00044 
00045 
00046 //: Create a concrete mcal_single_basis_cost object, from a text specification.
00047 vcl_auto_ptr<mcal_single_basis_cost>
00048   mcal_single_basis_cost::create_from_stream(vcl_istream &is)
00049 {
00050   vcl_string name;
00051   is >> name;
00052 
00053   vcl_auto_ptr<mcal_single_basis_cost> pvmb;
00054   try
00055   {
00056     pvmb = mbl_cloneables_factory<mcal_single_basis_cost>::get_clone(name);
00057   }
00058   catch (const mbl_exception_no_name_in_factory & e)
00059   {
00060       vcl_cerr<<"ERROR in mcal_single_basis_cost::new_vm_builder_from_stream\n"
00061               <<"\tRequired vector model builder of "<<name<<" is not in the factory. Further exception details follow:\n"
00062               <<'\t'<<e.what()<<vcl_endl;
00063       vcl_abort();
00064   }
00065   pvmb->config_from_stream(is);
00066   return pvmb;
00067 }
00068 
00069 //: Read initialisation settings from a stream.
00070 // The default implementation merely checks that no properties have
00071 // been specified.
00072 void mcal_single_basis_cost::config_from_stream(vcl_istream& is)
00073 {
00074   vcl_string s = mbl_parse_block(is);
00075   if (s.empty() || s=="{}") return;
00076 
00077   throw mbl_exception_parse_error(
00078     this->is_a() + " expects no properties in initialisation,\n"
00079     "But the following properties were given:\n" + s);
00080 }
00081 
00082 
00083 //=======================================================================
00084 // Associated function: operator<<
00085 //=======================================================================
00086 
00087 void vsl_b_write(vsl_b_ostream& bfs, const mcal_single_basis_cost& b)
00088 {
00089     b.b_write(bfs);
00090 }
00091 
00092 //=======================================================================
00093 // Associated function: operator>>
00094 //=======================================================================
00095 
00096 void vsl_b_read(vsl_b_istream& bfs, mcal_single_basis_cost& b)
00097 {
00098     b.b_read(bfs);
00099 }
00100 
00101 //=======================================================================
00102 // Associated function: operator<<
00103 //=======================================================================
00104 
00105 vcl_ostream& operator<<(vcl_ostream& os,const mcal_single_basis_cost& b)
00106 {
00107   os << b.is_a() << ": ";
00108   vsl_indent_inc(os);
00109   b.print_summary(os);
00110   vsl_indent_dec(os);
00111   return os;
00112 }
00113 
00114 //=======================================================================
00115 // Associated function: operator<<
00116 //=======================================================================
00117 
00118 vcl_ostream& operator<<(vcl_ostream& os,const mcal_single_basis_cost* b)
00119 {
00120     if (b)
00121     return os << *b;
00122     else
00123     return os << "No mcal_single_basis_cost defined.";
00124 }