File: mbl_read_multi_props.h

package info (click to toggle)
vxl 1.17.0.dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 153,280 kB
  • ctags: 105,123
  • sloc: cpp: 747,420; ansic: 209,130; fortran: 34,230; lisp: 14,915; sh: 6,187; python: 5,856; makefile: 340; perl: 294; xml: 160
file content (95 lines) | stat: -rw-r--r-- 3,933 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#ifndef mbl_read_multi_props_h
#define mbl_read_multi_props_h
//:
// \file
// \author Ian Scott
// \date 21-Nov-2005
// \brief Load properties with repeated labels from text files

#include <vcl_map.h>
#include <vcl_iosfwd.h>
#include <vcl_string.h>
#include <vcl_vector.h>


//: The type of the property dictionary
class mbl_read_multi_props_type : public vcl_multimap<vcl_string, vcl_string>
{
 public:

  //: Return a single expected value of the given property \a label.
  // The matching entry is removed from the property list.
  // \throws mbl_exception_missing_property if \a label doesn't exist.
  // \throws mbl_exception_read_props_parse_error if there are two or more values of \a label.
  vcl_string get_required_property(const vcl_string& label);

  //: Return a single value of the given property \a label.
  // The matching entry is removed from the property list.
  // returns empty string or \a default_prop if \a label doesn't exist.
  // \throws mbl_exception_read_props_parse_error if there are two or more values of \a label.
  vcl_string get_optional_property(const vcl_string& label,
    const vcl_string& default_prop="");

  //: Return a vector of all values for a given property label \a label.
  // All entries of \a label are removed from the property list.
  // \throws mbl_exception_missing_property if \a label doesn't occur at least once.
  // \param nmax The maximum number of permitted occurrences of this label (default=max<unsigned>).
  // \param nmin The minimum number of permitted occurrences of this label (default=1).
  // \throws mbl_exception_read_props_parse_error if \a label occurs an invalid number of times.
  void get_required_properties(
    const vcl_string& label,
    vcl_vector<vcl_string>& values,
    const unsigned nmax= (unsigned)(-1), //=max<unsigned>
    const unsigned nmin=1);

  //: Return a vector of all values for a given property label \a label.
  // All entries of \a label are removed from the property list.
  // Returns an empty vector if \a label doesn't occur at least once.
  // \param nmax The maximum number of permitted occurrences of this label (default=max<unsigned>).
  // \throws mbl_exception_read_props_parse_error if \a label occurs too many times.
  void get_optional_properties(const vcl_string& label,
                             vcl_vector<vcl_string>& values,
                             const unsigned nmax= (unsigned)(-1)); //=max<unsigned>
};


//: Read properties with repeated labels from a text stream.
// The function will terminate on an eof. If one of
// the opening lines contains an opening brace '{', then the function
// will also stop reading the stream after finding a line containing
// a closing brace '}'
//
// Every property label ends in ":", and should not contain
// any whitespace.
// If there is a brace after the first string following the label,
// the following text up to matching
// braces is included in the property value.
//
// Differs from mbl_read_props_ws(afs) in that a property label can be repeated,
// and the all the repeated values will be returned.
mbl_read_multi_props_type mbl_read_multi_props_ws(vcl_istream &afs);


//: Print a list of properties for debugging purposes.
void mbl_read_multi_props_print(vcl_ostream &afs, mbl_read_multi_props_type props);


//: Throw error if there are any keys in props that aren't in ignore.
// \throw mbl_exception_unused_props
void mbl_read_multi_props_look_for_unused_props(
  const vcl_string & function_name,
  const mbl_read_multi_props_type &props,
  const mbl_read_multi_props_type &ignore);

//: Throw error if there are any keys in props.
// \throw mbl_exception_unused_props
inline void mbl_read_multi_props_look_for_unused_props(
  const vcl_string & function_name,
  const mbl_read_multi_props_type &props)
{
  mbl_read_multi_props_look_for_unused_props(function_name, props,
    mbl_read_multi_props_type());
}


#endif // mbl_read_multi_props_h