contrib/mul/mbl/mbl_read_multi_props.h
Go to the documentation of this file.
00001 #ifndef mbl_read_multi_props_h
00002 #define mbl_read_multi_props_h
00003 //:
00004 // \file
00005 // \author Ian Scott
00006 // \date 21-Nov-2005
00007 // \brief Load properties with repeated labels from text files
00008 
00009 #include <vcl_map.h>
00010 #include <vcl_iosfwd.h>
00011 #include <vcl_string.h>
00012 #include <vcl_vector.h>
00013 
00014 
00015 //: The type of the property dictionary
00016 class mbl_read_multi_props_type : public vcl_multimap<vcl_string, vcl_string>
00017 {
00018  public:
00019 
00020   //: Return a single expected value of the given property \a label.
00021   // The matching entry is removed from the property list.
00022   // \throws mbl_exception_missing_property if \a label doesn't exist.
00023   // \throws mbl_exception_read_props_parse_error if there are two or more values of \a label.
00024   vcl_string get_required_property(const vcl_string& label);
00025 
00026   //: Return a single value of the given property \a label.
00027   // The matching entry is removed from the property list.
00028   // returns empty string or \a default_prop if \a label doesn't exist.
00029   // \throws mbl_exception_read_props_parse_error if there are two or more values of \a label.
00030   vcl_string get_optional_property(const vcl_string& label,
00031     const vcl_string& default_prop="");
00032 
00033   //: Return a vector of all values for a given property label \a label.
00034   // All entries of \a label are removed from the property list.
00035   // \throws mbl_exception_missing_property if \a label doesn't occur at least once.
00036   // \param nmax The maximum number of permitted occurrences of this label (default=max<unsigned>).
00037   // \param nmin The minimum number of permitted occurrences of this label (default=1).
00038   // \throws mbl_exception_read_props_parse_error if \a label occurs an invalid number of times.
00039   void get_required_properties(
00040     const vcl_string& label,
00041     vcl_vector<vcl_string>& values,
00042     const unsigned nmax= (unsigned)(-1), //=max<unsigned>
00043     const unsigned nmin=1);
00044 
00045   //: Return a vector of all values for a given property label \a label.
00046   // All entries of \a label are removed from the property list.
00047   // Returns an empty vector if \a label doesn't occur at least once.
00048   // \param nmax The maximum number of permitted occurrences of this label (default=max<unsigned>).
00049   // \throws mbl_exception_read_props_parse_error if \a label occurs too many times.
00050   void get_optional_properties(const vcl_string& label,
00051                              vcl_vector<vcl_string>& values,
00052                              const unsigned nmax= (unsigned)(-1)); //=max<unsigned>
00053 };
00054 
00055 
00056 //: Read properties with repeated labels from a text stream.
00057 // The function will terminate on an eof. If one of
00058 // the opening lines contains an opening brace '{', then the function
00059 // will also stop reading the stream after finding a line containing
00060 // a closing brace '}'
00061 //
00062 // Every property label ends in ":", and should not contain
00063 // any whitespace.
00064 // If there is a brace after the first string following the label,
00065 // the following text up to matching
00066 // braces is included in the property value.
00067 //
00068 // Differs from mbl_read_props_ws(afs) in that a property label can be repeated,
00069 // and the all the repeated values will be returned.
00070 mbl_read_multi_props_type mbl_read_multi_props_ws(vcl_istream &afs);
00071 
00072 
00073 //: Print a list of properties for debugging purposes.
00074 void mbl_read_multi_props_print(vcl_ostream &afs, mbl_read_multi_props_type props);
00075 
00076 
00077 //: Throw error if there are any keys in props that aren't in ignore.
00078 // \throw mbl_exception_unused_props
00079 void mbl_read_multi_props_look_for_unused_props(
00080   const vcl_string & function_name,
00081   const mbl_read_multi_props_type &props,
00082   const mbl_read_multi_props_type &ignore);
00083 
00084 //: Throw error if there are any keys in props.
00085 // \throw mbl_exception_unused_props
00086 inline void mbl_read_multi_props_look_for_unused_props(
00087   const vcl_string & function_name,
00088   const mbl_read_multi_props_type &props)
00089 {
00090   mbl_read_multi_props_look_for_unused_props(function_name, props,
00091     mbl_read_multi_props_type());
00092 }
00093 
00094 
00095 #endif // mbl_read_multi_props_h