LSST Applications g063fba187b+eddd1b24d7,g0f08755f38+4a855ab515,g1653933729+a8ce1bb630,g168dd56ebc+a8ce1bb630,g1a2382251a+062a45aee3,g1dcb35cd9c+45d3fa5522,g20f6ffc8e0+4a855ab515,g217e2c1bcf+f55e51b560,g28da252d5a+7d8e536cc7,g2bbee38e9b+2d92fc7d83,g2bc492864f+2d92fc7d83,g3156d2b45e+6e55a43351,g32e5bea42b+625186cc6b,g347aa1857d+2d92fc7d83,g35bb328faa+a8ce1bb630,g3a166c0a6a+2d92fc7d83,g3e281a1b8c+c5dd892a6c,g3e8969e208+a8ce1bb630,g414038480c+5927e1bc1e,g41af890bb2+1af189bab1,g7af13505b9+7b6a50a2f8,g80478fca09+6174b7f182,g82479be7b0+5b71efbaf0,g858d7b2824+4a855ab515,g9125e01d80+a8ce1bb630,ga5288a1d22+61618a97c4,gb58c049af0+d64f4d3760,gc28159a63d+2d92fc7d83,gc5452a3dca+f4add4ffd5,gcab2d0539d+d9f5af7f69,gcf0d15dbbd+6c7e0a19ec,gda6a2b7d83+6c7e0a19ec,gdaeeff99f8+1711a396fd,ge79ae78c31+2d92fc7d83,gef2f8181fd+55fff6f525,gf0baf85859+c1f95f4921,gfa517265be+4a855ab515,gfa999e8aa5+17cd334064,w.2024.51
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)