Project

General

Profile

Wiki » History » Version 26

Walter E Brown, 03/16/2012 09:33 AM

1 1 Walter E Brown
h1. Wiki
2 1 Walter E Brown
3 14 Walter E Brown
4 1 Walter E Brown
h2. Contents
5 2 Walter E Brown
6 14 Walter E Brown
* [[Wiki#Library overview|Library overview]]
7 14 Walter E Brown
* [[Wiki#The ParameterSet interface|The ParameterSet interface]]
8 26 Walter E Brown
** [[Wiki#Names, keys, and values|Names, keys, and values]]
9 26 Walter E Brown
** [[Wiki#Relationship to ParameterSetID|Relationship to ParameterSetID]]
10 26 Walter E Brown
** [[Wiki#Immutability|Immutability]]
11 26 Walter E Brown
** [[Wiki#Compiler-generated functions|Compiler-generated functions]]
12 26 Walter E Brown
** [[Wiki#Observers|Observers]]
13 26 Walter E Brown
** [[Wiki#Retrievers|Retrievers]]
14 26 Walter E Brown
** [[Wiki#Inserters|Inserters]]
15 26 Walter E Brown
** [[Wiki#Deleters|Deleters]]
16 26 Walter E Brown
** [[Wiki#Comparators|Comparators]]
17 26 Walter E Brown
** [[Wiki#Interface technical summary|Interface technical summary]]
18 1 Walter E Brown
* [[Release Notes]] (Separate page)
19 25 Walter E Brown
* [[ParameterSet Creation]] (Separate page)
20 12 Walter E Brown
21 14 Walter E Brown
22 5 Walter E Brown
h2. Library overview
23 1 Walter E Brown
24 14 Walter E Brown
The @fhiclcpp@ library provides types and functions that constitute a _binding_ of the FHiCL specification to C++.  (See https://cdcvs.fnal.gov/redmine/attachments/5348/quick_start.pdf for an introduction to FHiCL nomenclature and concepts.)
25 1 Walter E Brown
26 14 Walter E Brown
The following types are provided, each declared in the @fhicl@ namespace:
27 14 Walter E Brown
28 14 Walter E Brown
* @ParameterSet@, corresponding to a user-specified _configuration_ (a "collection of named values accessible to a user’s program while it is running");
29 4 Walter E Brown
* @ParameterSetID@, uniquely identifying a specific value of a @ParameterSet@ instance;
30 7 Walter E Brown
* @ParameterSetRegistry@, automatically registering each @ParameterSet@ instance (or sub-instance) with its corresponding @ParameterSetID@;
31 7 Walter E Brown
* @intermediate_table@, serving as an internal ("raw" or "working") representation of a FHiCL document;
32 4 Walter E Brown
* @extended_value@, representing a FHiCL value within an @intermediate_table@;
33 1 Walter E Brown
* @value_tag@, classifying an @extended_value@ instance; and
34 1 Walter E Brown
* @exception@, describing a circumstance from which the library can't recover.
35 16 Walter E Brown
36 1 Walter E Brown
In addition, the library provides public member functions and (also in the @fhicl@ namespace) free functions to construct, observe, and transform values of these types.
37 1 Walter E Brown
38 14 Walter E Brown
The next section details the interface of the @ParameterSet@ type, likely of greatest interest to most users of this library.  (A separate page will describe those remaining types and functions that are typically used only while initially producing @ParameterSet@ instances by combining information obtained from a @fhicl@ document with additional information from such sources as a command line and application-specific defaults.)
39 1 Walter E Brown
40 21 Walter E Brown
41 1 Walter E Brown
h2.  The ParameterSet interface
42 1 Walter E Brown
43 26 Walter E Brown
h3. Names, keys, and values
44 21 Walter E Brown
45 26 Walter E Brown
* In the descriptions below, parameters and arguments denoted @name@ are always of type of type @std::string@; each corresponds to FHiCL's notion of a _name_.
46 26 Walter E Brown
* In the descriptions below, parameters and arguments denoted @key@ are always of type of type @std::string@; each also corresponds to FHiCL's notion of a _name_, but when one @ParameterSet@ is nested within another @ParameterSet@, a key may employ the FHiCL _member notation_.
47 20 Walter E Brown
* Each @ParameterSet@ object consists of some number of  keys, each associated with a value of some C++ type.  Such an association is termed a _key-value pair_.  When the key is a simple name, the association is equivalently termed a _name-value pair_.
48 19 Walter E Brown
* A value can be retrieved from a @ParameterSet@ by presenting its corresponding key.  Similarly, a value can be inserted into a @ParameterSet@ by presenting both the value and its desired corresponding key.  
49 1 Walter E Brown
* A @ParameterSet@ contains values of C++ types closely corresponding to FHiCL values.  We refer to the C++ types in the following list as _FHiCL types_.
50 19 Walter E Brown
** The C++ standard @bool@ type corresponds to FHiCL's notion of a _boolean value_.
51 19 Walter E Brown
** The C++ standard signed and unsigned integer types, as well as the C++ standard floating-point types, correspond to FHiCL's notion of a _numeric value_.
52 20 Walter E Brown
** The C++ @std::complex<>@ types correspond to FHiCL's notion of a _complex value_.
53 21 Walter E Brown
** The C++ @std::string@ type corresponds to FHiCL's notion of a _string value_.
54 1 Walter E Brown
** The C++ @std::vector@ types correspond to FHiCL's notion of a _sequence value_.  Only homogeneous sequences are supported in this binding.
55 9 Walter E Brown
** The @fhicl::ParameterSet@ type corresponds to FHiCL's notion of a _table value_. Note that a processed FHiCL _document_ also yields a @ParameterSet@.
56 1 Walter E Brown
* As an extension to the functionality required of a FHiCL binding, a @ParameterSet@ can contain values of arbitrary user-defined C++ types. The library processes such values via user-supplied functions that convert to the user-defined type.  (In practice, this has been a rarely-used @fhiclcpp@ library feature.)
57 1 Walter E Brown
58 26 Walter E Brown
h3. Relationship to ParameterSetID
59 1 Walter E Brown
60 1 Walter E Brown
* A @ParameterSetID@ is automatically generated from (and thus corresponds to) the value of a @ParameterSet@ object.
61 17 Walter E Brown
* If the value of a @ParameterSet@ object @ps@ is modified in any way (whether by inserting, deleting, or updating any key-value pair), a new @ParameterSetID@ value is generated to correspond to the updated value of @ps@.
62 18 Walter E Brown
63 26 Walter E Brown
h3. Immutability
64 18 Walter E Brown
65 18 Walter E Brown
In practice, most @ParameterSet@ objects, once constructed, are treated as immutable. While such practice is not required, it is preferable because of the relationship of a @ParameterSet@ to a @ParameterSetID@, described above.
66 10 Walter E Brown
67 10 Walter E Brown
h3. Compiler-generated functions
68 10 Walter E Brown
69 10 Walter E Brown
* A default-constructed @ParameterSet@ object is  _empty_; that is, it consists of no key-value pairs.
70 10 Walter E Brown
* A copy-constructed @ParameterSet@ object has the same key-value pairs as did the @ParameterSet@ object from which it was copied.
71 10 Walter E Brown
* A newly assigned-to @ParameterSet@ object has the same key-value pairs as did the @ParameterSet@ object from which it was copied.
72 10 Walter E Brown
73 10 Walter E Brown
h3. Observers
74 10 Walter E Brown
75 10 Walter E Brown
* A call of the form @ps.is_empty()@ returns @true@ if @ps@ is empty, and returns @false@ otherwise.
76 10 Walter E Brown
* A call of the form @ps.id()@ returns the @ParameterSetID@ value corresponding to the current value of @ps@.
77 15 Walter E Brown
* A call of the form @ps.tostring()@ returns a compact @std::string@ representation of the current value of @ps@.
78 22 Walter E Brown
* A call of the form @ps.to_indented_string()@ returns an expanded and easier-to-read @std::string@ representation of the current value of @ps@.
79 22 Walter E Brown
* A call of the form @ps.get_keys()@ returns, as a @std::vector<std::string>@, a list of all names in @ps@.
80 1 Walter E Brown
* A call of the form @ps.get_pset_keys()@ returns, as a @std::vector<std::string>@, a list of all names in @ps@ whose corresponding values are of @ParameterSet@ type.
81 1 Walter E Brown
82 1 Walter E Brown
h3. Retrievers
83 20 Walter E Brown
84 20 Walter E Brown
* A call of the form @ps.get<T>(key)@ (or of the variant form @ps.get<T>(key, convert)@) will return the value of type @T@ associated with the key. 
85 20 Walter E Brown
** Either call will throw an exception if:
86 20 Walter E Brown
*** @ps@ contains no pair with a matching key, or 
87 20 Walter E Brown
*** @ps@ does contain a pair with a matching key, but the corresponding value can't be returned as a value of type @T@.
88 20 Walter E Brown
** The first form is used when the type @T@ is corresponds to a FHiCL value.
89 20 Walter E Brown
** The variant form is used when @T@ is an arbitrary user-defined type. The @convert@ argument is a user-provided function that converts a given FHiCL value to a value of type @T@.
90 20 Walter E Brown
* A call of the form @ps.get(key,default_value)@ (or of the variant form @ps.get<T>(key, default_value, convert)@) will return the value of type @T@ associated with the key.
91 20 Walter E Brown
** The first form is used when the type @T@ is corresponds to a FHiCL value.
92 20 Walter E Brown
** The variant form is used when @T@ is an arbitrary user-defined type. The @convert@ argument is a user-provided function that converts a given FHiCL value to a value of type @T@.
93 20 Walter E Brown
** Either call will return the supplied @default_value@ (which must be of type @T@) if:
94 20 Walter E Brown
*** @ps@ contains no pair with a matching key, or 
95 20 Walter E Brown
*** @ps@ does contain a pair with a matching key, but the corresponding value can't be returned as a value of type @T@.
96 20 Walter E Brown
* A call of the form @get_if_present(key, result)@ (or of the variant form @get_if_present(key, result, convert)@) has the following behavior:
97 20 Walter E Brown
** If the supplied key is an empty string, throw an exception.
98 20 Walter E Brown
** If @ps@ contains no pair with a matching key, return @false@.
99 20 Walter E Brown
** If @ps@ does contain a pair with a matching key, but the corresponding value isn't of type @T@, throw an exception.
100 20 Walter E Brown
** Otherwise, set the supplied @result@ (which must be an lvalue expression) to the corresponding value and return @true@.
101 1 Walter E Brown
** The first form is used when the type @T@ is corresponds to a FHiCL value.
102 1 Walter E Brown
** The variant form is used when @T@ is an arbitrary user-defined type. The @convert@ argument is a user-provided function that converts a given FHiCL value to a value of type @T@.
103 1 Walter E Brown
104 1 Walter E Brown
h3. Inserters
105 22 Walter E Brown
106 22 Walter E Brown
* A call of the form @ps.put(name, value)@ will insert into @ps@ a name-value pair composed of the given name and the given value.
107 22 Walter E Brown
** If @ps@ already contains a pair with the given name, that pair's value component is replaced by the value provided in the call.
108 22 Walter E Brown
** Otherwise, a new pair is constructed and inserted into @ps@.
109 24 Walter E Brown
** The type of the supplied value must be a FHiCL type.  If it is not, either the code will fail to compile or else the compiled code will throw an exception.
110 24 Walter E Brown
* A call of the form @ps.put(name)@ will insert into @ps@ a name-value pair composed of the given name and the library's equivalent of a FHiCL @nil@ value.
111 1 Walter E Brown
** If @ps@ already contains a pair with the given name, that pair's value component is replaced.
112 24 Walter E Brown
** Otherwise, a new pair is constructed and inserted into @ps@.
113 24 Walter E Brown
* A call of the form @ps.insert(name, value)@ will insert into @ps@ a name-value pair composed of the given name and the given value.
114 24 Walter E Brown
** If @ps@ already contains a pair with the given name, that pair's value component is replaced.
115 24 Walter E Brown
** Otherwise, a new pair is constructed and inserted into @ps@.
116 21 Walter E Brown
** The supplied value may be of any C++ type and will be inserted as-is (_i.e._, will be treated strictly as a user-defined type).  It is therefore recommended that this call not be used with values of any FHiCL type.
117 10 Walter E Brown
118 11 Walter E Brown
h3. Deleters
119 21 Walter E Brown
120 10 Walter E Brown
A call of the form @ps.erase(name)@ will attempt to remove from @ps@ the name-value pair with matching name and will return @true@ if successful and @false@ otherwise (_i.e._, if @ps@ contains no pair with the specified name).
121 10 Walter E Brown
122 10 Walter E Brown
h3. Comparators
123 14 Walter E Brown
124 10 Walter E Brown
Two @ParameterSet@ objects may be compared for equality or inequality via the corresponding conventional operator notations.  The objects are considered equal if and only if their respective @ParameterSetID@ values are equal.
125 10 Walter E Brown
126 10 Walter E Brown
h3. Interface technical summary
127 10 Walter E Brown
128 4 Walter E Brown
<pre><code class="cplusplus">
129 4 Walter E Brown
class ParameterSet
130 4 Walter E Brown
{
131 4 Walter E Brown
public:
132 4 Walter E Brown
  // use compiler-generated default c'tor, d'tor, and copy functions
133 4 Walter E Brown
134 4 Walter E Brown
  // observers:
135 4 Walter E Brown
  bool                      is_empty          ( ) const;
136 4 Walter E Brown
  ParameterSetID            id                ( ) const;
137 4 Walter E Brown
  std::string               to_string         ( ) const;
138 4 Walter E Brown
  std::string               to_indented_string( ) const;
139 4 Walter E Brown
  std::vector<std::string>  get_keys          ( ) const;
140 4 Walter E Brown
  std::vector<std::string>  get_pset_keys     ( ) const;
141 4 Walter E Brown
142 4 Walter E Brown
  // retrievers:
143 4 Walter E Brown
  template< class T >
144 4 Walter E Brown
    bool get_if_present( std::string const & key, T & value ) const;
145 4 Walter E Brown
  template< class T, class Via >
146 1 Walter E Brown
    bool get_if_present( std::string const & key, T & value, T convert(Via const &) ) const;
147 4 Walter E Brown
  template< class T >
148 4 Walter E Brown
    T  get( std::string const & key ) const;
149 1 Walter E Brown
  template< class T, class Via >
150 1 Walter E Brown
    T  get( std::string const & key, T convert(Via const &) ) const;
151 1 Walter E Brown
  template< class T >
152 4 Walter E Brown
    T  get( std::string const & key, T const & default_value ) const;
153 1 Walter E Brown
  template< class T, class Via >
154 1 Walter E Brown
    T  get( std::string const & key, T const & default_value, T convert(Via const &) ) const;
155 8 Walter E Brown
156 21 Walter E Brown
  // inserters:
157 21 Walter E Brown
  void  insert( std::string const & name, boost::any const & value );
158 8 Walter E Brown
  void  put( std::string const & name );  // implicit nil value
159 21 Walter E Brown
  template< class T >
160 8 Walter E Brown
    void  put( std::string const & name, T const & value );
161 8 Walter E Brown
162 21 Walter E Brown
  // deleters:
163 4 Walter E Brown
  bool  erase( std::string const & name );
164 4 Walter E Brown
165 4 Walter E Brown
  // comparators:
166 4 Walter E Brown
  bool  operator == ( ParameterSet const & other ) const;
167 4 Walter E Brown
  bool  operator != ( ParameterSet const & other ) const;
168 4 Walter E Brown
169 10 Walter E Brown
};  // ParameterSet
170 1 Walter E Brown
</code></pre>