LSST Applications g180d380827+0f66a164bb,g2079a07aa2+86d27d4dc4,g2305ad1205+7d304bc7a0,g29320951ab+500695df56,g2bbee38e9b+0e5473021a,g337abbeb29+0e5473021a,g33d1c0ed96+0e5473021a,g3a166c0a6a+0e5473021a,g3ddfee87b4+e42ea45bea,g48712c4677+36a86eeaa5,g487adcacf7+2dd8f347ac,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+c70619cc9d,g5a732f18d5+53520f316c,g5ea96fc03c+341ea1ce94,g64a986408d+f7cd9c7162,g858d7b2824+f7cd9c7162,g8a8a8dda67+585e252eca,g99cad8db69+469ab8c039,g9ddcbc5298+9a081db1e4,ga1e77700b3+15fc3df1f7,gb0e22166c9+60f28cb32d,gba4ed39666+c2a2e4ac27,gbb8dafda3b+c92fc63c7e,gbd866b1f37+f7cd9c7162,gc120e1dc64+02c66aa596,gc28159a63d+0e5473021a,gc3e9b769f7+b0068a2d9f,gcf0d15dbbd+e42ea45bea,gdaeeff99f8+f9a426f77a,ge6526c86ff+84383d05b3,ge79ae78c31+0e5473021a,gee10cc3b42+585e252eca,gff1a9f87cc+f7cd9c7162,w.2024.17
LSST Data Management Base Package
Loading...
Searching...
No Matches
PropertyList.cc
Go to the documentation of this file.
1// -*- lsst-c++ -*-
2
3/*
4 * LSST Data Management System
5 * Copyright 2008, 2009, 2010 LSST Corporation.
6 *
7 * This product includes software developed by the
8 * LSST Project (http://www.lsst.org/).
9 *
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the LSST License Statement and
21 * the GNU General Public License along with this program. If not,
22 * see <http://www.lsstcorp.org/LegalNotices/>.
23 */
24
26
27#include <algorithm>
28#include <iomanip>
29#include <sstream>
30#include <stdexcept>
31#include <any>
32
34
35namespace lsst {
36namespace daf {
37namespace base {
38
42
45PropertyList::~PropertyList() noexcept = default;
46
48// Accessors
50
51std::shared_ptr<PropertySet> PropertyList::deepCopy() const {
53 n->PropertySet::combine(*this->PropertySet::deepCopy());
54 n->_order = _order;
55 n->_comments = _comments;
56 return n;
57}
58
59// The following throw an exception if the type does not match exactly.
60
61template <typename T>
63 const { /* parasoft-suppress LsstDm-3-4a LsstDm-4-6 "allow template over bool" */
64 return PropertySet::get<T>(name);
65}
66
67template <typename T>
68T PropertyList::get(std::string const& name, T const& defaultValue)
69 const { /* parasoft-suppress LsstDm-3-4a LsstDm-4-6 "allow template over bool" */
70 return PropertySet::get<T>(name, defaultValue);
71}
72
73template <typename T>
75 return PropertySet::getArray<T>(name);
76}
77
79 return _comments.find(name)->second;
80}
81
84 for (auto const& name : _order) {
85 v.push_back(name);
86 }
87 return v;
88}
89
90std::list<std::string>::const_iterator PropertyList::begin() const { return _order.begin(); }
91
92std::list<std::string>::const_iterator PropertyList::end() const { return _order.end(); }
93
94std::string PropertyList::toString(bool topLevelOnly, std::string const& indent) const {
96 for (auto const& name : _order) {
97 s << _format(name);
98 std::string const& comment = _comments.find(name)->second;
99 if (comment.size()) {
100 s << "// " << comment << std::endl;
101 }
102 }
103 return s.str();
104}
105
107// Modifiers
109
111// Normal versions of set/add with placement control
112
113template <typename T>
114void PropertyList::set(std::string const& name, T const& value) {
115 PropertySet::set(name, value);
116}
117
119 auto pl = std::dynamic_pointer_cast<PropertyList, PropertySet>(value);
120 PropertySet::set(name, value);
121 _comments.erase(name);
122 _order.remove(name);
123 std::vector<std::string> paramNames = value->paramNames(false);
124 if (pl) {
125 for (auto const& paramName : paramNames) {
126 _commentOrderFix(name + "." + paramName, pl->getComment(paramName));
127 }
128 }
129}
130
131void PropertyList::set(std::string const& name, char const* value) { set(name, std::string(value)); }
132
133template <typename T>
134void PropertyList::set(std::string const& name, std::vector<T> const& value) {
135 PropertySet::set(name, value);
136}
137
138template <typename T>
139void PropertyList::add(std::string const& name, T const& value) {
140 PropertySet::add(name, value);
141}
142
143void PropertyList::add(std::string const& name, char const* value) { add(name, std::string(value)); }
144
145template <typename T>
146void PropertyList::add(std::string const& name, std::vector<T> const& value) {
147 PropertySet::add(name, value);
148}
149
151// Commented versions of set/add
152
153template <typename T>
154void PropertyList::set(std::string const& name, T const& value, std::string const& comment) {
155 PropertySet::set(name, value);
156 _commentOrderFix(name, comment);
157}
158
159void PropertyList::set(std::string const& name, char const* value, std::string const& comment) {
160 set(name, std::string(value), comment);
161}
162
163template <typename T>
164void PropertyList::set(std::string const& name, std::vector<T> const& value, std::string const& comment) {
165 PropertySet::set(name, value);
166 _commentOrderFix(name, comment);
167}
168template <typename T>
169void PropertyList::add(std::string const& name, T const& value, std::string const& comment) {
170 PropertySet::add(name, value);
171 _commentOrderFix(name, comment);
172}
173
174void PropertyList::add(std::string const& name, char const* value, std::string const& comment) {
175 add(name, std::string(value), comment);
176}
177
178template <typename T>
179void PropertyList::add(std::string const& name, std::vector<T> const& value, std::string const& comment) {
180 PropertySet::add(name, value);
181 _commentOrderFix(name, comment);
182}
183
185// Other modifiers
186
187void PropertyList::copy(std::string const& dest, PropertySet const & source, std::string const& name,
188 bool asScalar) {
189 PropertySet::copy(dest, source, name, asScalar);
190 auto const * pl = dynamic_cast<PropertyList const *>(&source);
191 if (pl) {
192 _comments[name] = pl->_comments.find(name)->second;
193 }
194}
195
196
197void PropertyList::combine(PropertySet const & source) {
198 auto const * pl = dynamic_cast<PropertyList const *>(&source);
199 std::list<std::string> newOrder;
200 if (pl) {
201 newOrder = _order;
202 for (auto const& name : *pl) {
203 bool present = _comments.find(name) != _comments.end();
204 if (!present) {
205 newOrder.push_back(name);
206 }
207 }
208 }
209 PropertySet::combine(source);
210 if (pl) {
211 _order = newOrder;
212 for (auto const& name : *pl) {
213 _comments[name] = pl->_comments.find(name)->second;
214 }
215 }
216}
217
218
221 _comments.erase(name);
222 _order.remove(name);
223}
224
226// Private member functions
228
230 PropertySet::_set(name, vp);
231 if (_comments.find(name) == _comments.end()) {
232 _comments.insert(std::make_pair(name, std::string()));
233 _order.push_back(name);
234 }
235}
236
238 _order.remove(name);
239 _order.push_back(name);
240}
241
242void PropertyList::_commentOrderFix(std::string const& name, std::string const& comment) {
243 _comments[name] = comment;
244}
245
247// Explicit template instantiations
249
251// Explicit template instantiations are not well understood by doxygen.
252
253#define INSTANTIATE(t) \
254 template t PropertyList::get<t>(std::string const& name) const; \
255 template t PropertyList::get<t>(std::string const& name, t const& defaultValue) const; \
256 template std::vector<t> PropertyList::getArray<t>(std::string const& name) const; \
257 template void PropertyList::set<t>(std::string const& name, t const& value); \
258 template void PropertyList::set<t>(std::string const& name, std::vector<t> const& value); \
259 template void PropertyList::add<t>(std::string const& name, t const& value); \
260 template void PropertyList::add<t>(std::string const& name, std::vector<t> const& value); \
261 template void PropertyList::set<t>(std::string const& name, t const& value, std::string const& comment); \
262 template void PropertyList::set<t>(std::string const& name, std::vector<t> const& value, \
263 std::string const& comment); \
264 template void PropertyList::add<t>(std::string const& name, t const& value, std::string const& comment); \
265 template void PropertyList::add<t>(std::string const& name, std::vector<t> const& value, \
266 std::string const& comment); \
267 template void PropertyList::set<t>(std::string const& name, t const& value, char const* comment); \
268 template void PropertyList::set<t>(std::string const& name, std::vector<t> const& value, \
269 char const* comment); \
270 template void PropertyList::add<t>(std::string const& name, t const& value, char const* comment); \
271 template void PropertyList::add<t>(std::string const& name, std::vector<t> const& value, \
272 char const* comment);
273
274INSTANTIATE(bool)
275INSTANTIATE(char)
276INSTANTIATE(signed char)
277INSTANTIATE(unsigned char)
278INSTANTIATE(short)
279INSTANTIATE(unsigned short)
280INSTANTIATE(int)
281INSTANTIATE(unsigned int)
282INSTANTIATE(long)
283INSTANTIATE(unsigned long)
284INSTANTIATE(long long)
285INSTANTIATE(unsigned long long)
286INSTANTIATE(float)
287INSTANTIATE(double)
292
293
294
295} // namespace base
296} // namespace daf
297} // namespace lsst
table::Key< std::string > name
Definition Amplifier.cc:116
Interface for DateTime class.
#define INSTANTIATE(FROMSYS, TOSYS)
Definition Detector.cc:509
T begin(T... args)
Class for handling dates/times, including MJD, UTC, and TAI.
Definition DateTime.h:64
Class for storing ordered metadata with comments.
std::list< std::string >::const_iterator end() const
End iterator over the list of property names, in the order they were added.
PropertyList()
Construct an empty PropertyList.
virtual void combine(PropertySet const &source)
Append all value vectors from the source to their corresponding properties.
void set(std::string const &name, T const &value)
Replace all values for a property name (possibly hierarchical) with a new scalar value.
T get(std::string const &name) const
Get the last value for a property name (possibly hierarchical).
void add(std::string const &name, T const &value)
Append a single value to the vector of values for a property name (possibly hierarchical).
virtual void _set(std::string const &name, std::shared_ptr< std::vector< std::any > > vp)
std::string const & getComment(std::string const &name) const
Get the comment for a string property name (possibly hierarchical).
std::vector< T > getArray(std::string const &name) const
Get the vector of values for a property name (possibly hierarchical).
std::vector< std::string > getOrderedNames() const
Get the list of property names, in the order they were added.
virtual void remove(std::string const &name)
Remove all values for a property name (possibly hierarchical).
virtual ~PropertyList() noexcept
Destructor.
virtual void _moveToEnd(std::string const &name)
virtual void copy(std::string const &dest, PropertySet const &source, std::string const &name, bool asScalar=false)
Replace a single value vector in the destination with one from the source.
virtual void _commentOrderFix(std::string const &name, std::string const &comment)
virtual std::string toString(bool topLevelOnly=false, std::string const &indent="") const
Generate a string representation of the PropertySet.
std::list< std::string >::const_iterator begin() const
Begin iterator over the list of property names, in the order they were added.
Class for storing generic metadata.
Definition PropertySet.h:66
virtual void _set(std::string const &name, std::shared_ptr< std::vector< std::any > > vp)
virtual void remove(std::string const &name)
Remove all values for a property name (possibly hierarchical).
virtual std::string _format(std::string const &name) const
void set(std::string const &name, T const &value)
Replace all values for a property name (possibly hierarchical) with a new scalar value.
virtual void copy(std::string const &dest, PropertySet const &source, std::string const &name, bool asScalar=false)
Replace a single value vector in the destination with one from the source.
virtual void combine(PropertySet const &source)
Append all value vectors from the source to their corresponding properties.
void add(std::string const &name, T const &value)
Append a single value to the vector of values for a property name (possibly hierarchical).
virtual std::shared_ptr< PropertySet > deepCopy() const
Make a deep copy of the PropertySet and all of its contents.
std::vector< std::string > paramNames(bool topLevelOnly=true) const
A variant of names that excludes the names of subproperties.
T end(T... args)
T endl(T... args)
T erase(T... args)
T find(T... args)
daf::base::PropertySet * set
Definition fits.cc:931
T insert(T... args)
T make_pair(T... args)
STL namespace.
T push_back(T... args)
T remove(T... args)
T size(T... args)