LSSTApplications  21.0.0+75b29a8a7f,21.0.0+e70536a077,21.0.0-1-ga51b5d4+62c747d40b,21.0.0-11-ga6ea59e8e+47cba9fc36,21.0.0-2-g103fe59+914993bf7c,21.0.0-2-g1367e85+e2614ded12,21.0.0-2-g45278ab+e70536a077,21.0.0-2-g4bc9b9f+7b2b5f8678,21.0.0-2-g5242d73+e2614ded12,21.0.0-2-g54e2caa+6403186824,21.0.0-2-g7f82c8f+3ac4acbffc,21.0.0-2-g8dde007+04a6aea1af,21.0.0-2-g8f08a60+9402881886,21.0.0-2-ga326454+3ac4acbffc,21.0.0-2-ga63a54e+81dd751046,21.0.0-2-gc738bc1+5f65c6e7a9,21.0.0-2-gde069b7+26c92b3210,21.0.0-2-gecfae73+0993ddc9bd,21.0.0-2-gfc62afb+e2614ded12,21.0.0-21-gba890a8+5a4f502a26,21.0.0-23-g9966ff26+03098d1af8,21.0.0-3-g357aad2+8ad216c477,21.0.0-3-g4be5c26+e2614ded12,21.0.0-3-g6d51c4a+4d2fe0280d,21.0.0-3-g7d9da8d+75b29a8a7f,21.0.0-3-gaa929c8+522e0f12c2,21.0.0-3-ge02ed75+4d2fe0280d,21.0.0-4-g3300ddd+e70536a077,21.0.0-4-gc004bbf+eac6615e82,21.0.0-4-gccdca77+f94adcd104,21.0.0-4-gd1c1571+18b81799f9,21.0.0-5-g7b47fff+4d2fe0280d,21.0.0-5-gb155db7+d2632f662b,21.0.0-5-gdf36809+637e4641ee,21.0.0-6-g722ad07+28c848f42a,21.0.0-7-g959bb79+522e0f12c2,21.0.0-7-gfd72ab2+cf01990774,21.0.0-9-g87fb7b8d+e2ab11cdd6,w.2021.04
LSSTDataManagementBasePackage
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 
32 #include "lsst/daf/base/DateTime.h"
33 
34 namespace lsst {
35 namespace daf {
36 namespace base {
37 
41 
45 
47 // Accessors
49 
50 PropertySet::Ptr PropertyList::deepCopy() const {
51  Ptr n(new PropertyList);
52  n->PropertySet::combine(this->PropertySet::deepCopy());
53  n->_order = _order;
54  n->_comments = _comments;
55  return n;
56 }
57 
58 // The following throw an exception if the type does not match exactly.
59 
60 template <typename T>
62  const { /* parasoft-suppress LsstDm-3-4a LsstDm-4-6 "allow template over bool" */
63  return PropertySet::get<T>(name);
64 }
65 
66 template <typename T>
67 T PropertyList::get(std::string const& name, T const& defaultValue)
68  const { /* parasoft-suppress LsstDm-3-4a LsstDm-4-6 "allow template over bool" */
69  return PropertySet::get<T>(name, defaultValue);
70 }
71 
72 template <typename T>
74  return PropertySet::getArray<T>(name);
75 }
76 
78  return _comments.find(name)->second;
79 }
80 
83  for (auto const& name : _order) {
84  v.push_back(name);
85  }
86  return v;
87 }
88 
90 
92 
93 std::string PropertyList::toString(bool topLevelOnly, std::string const& indent) const {
95  for (auto const& name : _order) {
96  s << _format(name);
97  std::string const& comment = _comments.find(name)->second;
98  if (comment.size()) {
99  s << "// " << comment << std::endl;
100  }
101  }
102  return s.str();
103 }
104 
106 // Modifiers
108 
110 // Normal versions of set/add with placement control
111 
112 template <typename T>
113 void PropertyList::set(std::string const& name, T const& value) {
114  PropertySet::set(name, value);
115 }
116 
118  Ptr pl = std::dynamic_pointer_cast<PropertyList, PropertySet>(value);
119  PropertySet::set(name, value);
120  _comments.erase(name);
121  _order.remove(name);
122  std::vector<std::string> paramNames = value->paramNames(false);
123  if (pl) {
124  for (auto const& paramName : paramNames) {
125  _commentOrderFix(name + "." + paramName, pl->getComment(paramName));
126  }
127  }
128 }
129 
130 void PropertyList::set(std::string const& name, char const* value) { set(name, std::string(value)); }
131 
132 template <typename T>
133 void PropertyList::set(std::string const& name, std::vector<T> const& value) {
134  PropertySet::set(name, value);
135 }
136 
137 template <typename T>
138 void PropertyList::add(std::string const& name, T const& value) {
139  PropertySet::add(name, value);
140 }
141 
142 void PropertyList::add(std::string const& name, char const* value) { add(name, std::string(value)); }
143 
144 template <typename T>
145 void PropertyList::add(std::string const& name, std::vector<T> const& value) {
146  PropertySet::add(name, value);
147 }
148 
150 // Commented versions of set/add
151 
152 template <typename T>
153 void PropertyList::set(std::string const& name, T const& value, std::string const& comment) {
154  PropertySet::set(name, value);
155  _commentOrderFix(name, comment);
156 }
157 
158 void PropertyList::set(std::string const& name, char const* value, std::string const& comment) {
159  set(name, std::string(value), comment);
160 }
161 
162 template <typename T>
163 void PropertyList::set(std::string const& name, std::vector<T> const& value, std::string const& comment) {
164  PropertySet::set(name, value);
165  _commentOrderFix(name, comment);
166 }
167 template <typename T>
168 void PropertyList::add(std::string const& name, T const& value, std::string const& comment) {
169  PropertySet::add(name, value);
170  _commentOrderFix(name, comment);
171 }
172 
173 void PropertyList::add(std::string const& name, char const* value, std::string const& comment) {
174  add(name, std::string(value), comment);
175 }
176 
177 template <typename T>
178 void PropertyList::add(std::string const& name, std::vector<T> const& value, std::string const& comment) {
179  PropertySet::add(name, value);
180  _commentOrderFix(name, comment);
181 }
182 
184 // Other modifiers
185 
187  bool asScalar) {
188  PropertySet::copy(dest, source, name, asScalar);
189  ConstPtr pl = std::dynamic_pointer_cast<PropertyList const, PropertySet const>(source);
190  if (pl) {
191  _comments[name] = pl->_comments.find(name)->second;
192  }
193 }
194 
196  ConstPtr pl = std::dynamic_pointer_cast<PropertyList const, PropertySet const>(source);
197  std::list<std::string> newOrder;
198  if (pl) {
199  newOrder = _order;
200  for (auto const& name : *pl) {
201  bool present = _comments.find(name) != _comments.end();
202  if (!present) {
203  newOrder.push_back(name);
204  }
205  }
206  }
208  if (pl) {
209  _order = newOrder;
210  for (auto const& name : *pl) {
211  _comments[name] = pl->_comments.find(name)->second;
212  }
213  }
214 }
215 
218  _comments.erase(name);
219  _order.remove(name);
220 }
221 
223 // Private member functions
225 
226 void PropertyList::_set(std::string const& name, std::shared_ptr<std::vector<boost::any> > vp) {
227  PropertySet::_set(name, vp);
228  if (_comments.find(name) == _comments.end()) {
229  _comments.insert(std::make_pair(name, std::string()));
230  _order.push_back(name);
231  }
232 }
233 
234 void PropertyList::_moveToEnd(std::string const& name) {
235  _order.remove(name);
236  _order.push_back(name);
237 }
238 
239 void PropertyList::_commentOrderFix(std::string const& name, std::string const& comment) {
240  _comments[name] = comment;
241 }
242 
244 // Explicit template instantiations
246 
248 // Explicit template instantiations are not well understood by doxygen.
249 
250 #define INSTANTIATE(t) \
251  template t PropertyList::get<t>(std::string const& name) const; \
252  template t PropertyList::get<t>(std::string const& name, t const& defaultValue) const; \
253  template std::vector<t> PropertyList::getArray<t>(std::string const& name) const; \
254  template void PropertyList::set<t>(std::string const& name, t const& value); \
255  template void PropertyList::set<t>(std::string const& name, std::vector<t> const& value); \
256  template void PropertyList::add<t>(std::string const& name, t const& value); \
257  template void PropertyList::add<t>(std::string const& name, std::vector<t> const& value); \
258  template void PropertyList::set<t>(std::string const& name, t const& value, std::string const& comment); \
259  template void PropertyList::set<t>(std::string const& name, std::vector<t> const& value, \
260  std::string const& comment); \
261  template void PropertyList::add<t>(std::string const& name, t const& value, std::string const& comment); \
262  template void PropertyList::add<t>(std::string const& name, std::vector<t> const& value, \
263  std::string const& comment); \
264  template void PropertyList::set<t>(std::string const& name, t const& value, char const* comment); \
265  template void PropertyList::set<t>(std::string const& name, std::vector<t> const& value, \
266  char const* comment); \
267  template void PropertyList::add<t>(std::string const& name, t const& value, char const* comment); \
268  template void PropertyList::add<t>(std::string const& name, std::vector<t> const& value, \
269  char const* comment);
270 
271 INSTANTIATE(bool)
272 INSTANTIATE(char)
273 INSTANTIATE(signed char)
274 INSTANTIATE(unsigned char)
275 INSTANTIATE(short)
276 INSTANTIATE(unsigned short)
277 INSTANTIATE(int)
278 INSTANTIATE(unsigned int)
279 INSTANTIATE(long)
280 INSTANTIATE(unsigned long)
281 INSTANTIATE(long long)
282 INSTANTIATE(unsigned long long)
283 INSTANTIATE(float)
284 INSTANTIATE(double)
285 INSTANTIATE(nullptr_t)
288 INSTANTIATE(DateTime)
289 
290 
292 } // namespace base
293 } // namespace daf
294 } // namespace lsst
lsst.pipe.tasks.cli.cmd.commands.default
default
Definition: commands.py:50
lsst::daf::base::PropertyList::combine
virtual void combine(PropertySet::ConstPtr source)
Append all value vectors from the source to their corresponding properties.
Definition: PropertyList.cc:195
lsst::daf::base::PropertyList::getComment
std::string const & getComment(std::string const &name) const
Get the comment for a string property name (possibly hierarchical).
Definition: PropertyList.cc:77
lsst::daf::base::PropertyList::end
std::list< std::string >::const_iterator end() const
End iterator over the list of property names, in the order they were added.
Definition: PropertyList.cc:91
std::string
STL class.
std::shared_ptr
STL class.
std::list
STL class.
lsst::daf::base::Persistable::Ptr
std::shared_ptr< Persistable > Ptr
Definition: Persistable.h:77
lsst::daf::base::PropertySet::_format
virtual std::string _format(std::string const &name) const
std::vector
STL class.
std::unordered_map::find
T find(T... args)
lsst::daf::base::PropertySet::add
void add(std::string const &name, T const &value)
Append a single value to the vector of values for a property name (possibly hierarchical).
std::string::size
T size(T... args)
DateTime.h
Interface for DateTime class.
lsst::daf::base::PropertyList
Class for storing ordered metadata with comments.
Definition: PropertyList.h:68
lsst::daf::base::PropertySet::copy
virtual void copy(std::string const &dest, ConstPtr source, std::string const &name, bool asScalar=false)
Replace a single value vector in the destination with one from the source.
INSTANTIATE
#define INSTANTIATE(FROMSYS, TOSYS)
Definition: Detector.cc:484
lsst::afw::geom.transform.transformContinued.name
string name
Definition: transformContinued.py:32
lsst::daf::base::PropertyList::get
T get(std::string const &name) const
Get the last value for a property name (possibly hierarchical).
Definition: PropertyList.cc:61
std::vector::push_back
T push_back(T... args)
PropertyList.h
lsst::daf::base::PropertySet::_set
virtual void _set(std::string const &name, std::shared_ptr< std::vector< boost::any > > vp)
ast::detail::source
const char * source()
Source function that allows astChannel to source from a Stream.
Definition: Stream.h:224
lsst::daf::base::PropertyList::add
void add(std::string const &name, T const &value)
Append a single value to the vector of values for a property name (possibly hierarchical).
Definition: PropertyList.cc:138
lsst::daf::base::PropertyList::begin
std::list< std::string >::const_iterator begin() const
Begin iterator over the list of property names, in the order they were added.
Definition: PropertyList.cc:89
lsst::daf::base::PropertyList::set
void set(std::string const &name, T const &value)
Replace all values for a property name (possibly hierarchical) with a new scalar value.
Definition: PropertyList.cc:113
lsst::daf::base::PropertyList::copy
virtual void copy(std::string const &dest, PropertySet::ConstPtr source, std::string const &name, bool asScalar=false)
Replace a single value vector in the destination with one from the source.
Definition: PropertyList.cc:186
std::unordered_map::erase
T erase(T... args)
std::list::remove
T remove(T... args)
lsst
A base class for image defects.
Definition: imageAlgorithm.dox:1
lsst::daf::base::PropertySet::paramNames
std::vector< std::string > paramNames(bool topLevelOnly=true) const
A variant of names that excludes the names of subproperties.
lsst::daf::base::PropertySet::remove
virtual void remove(std::string const &name)
Remove all values for a property name (possibly hierarchical).
lsst::daf::base::PropertyList::getArray
std::vector< T > getArray(std::string const &name) const
Get the vector of values for a property name (possibly hierarchical).
Definition: PropertyList.cc:73
std::ostringstream
STL class.
lsst::daf::base::PropertyList::PropertyList
PropertyList()
Construct an empty PropertyList.
Definition: PropertyList.cc:40
std::endl
T endl(T... args)
std::list::begin
T begin(T... args)
lsst::daf::base::PropertyList::toString
virtual std::string toString(bool topLevelOnly=false, std::string const &indent="") const
Generate a string representation of the PropertySet.
Definition: PropertyList.cc:93
std::unordered_map::insert
T insert(T... args)
lsst::daf::base::PropertySet
Class for storing generic metadata.
Definition: PropertySet.h:67
lsst::daf::base::PropertyList::~PropertyList
virtual ~PropertyList() noexcept
Destructor.
std::ostringstream::str
T str(T... args)
lsst::daf::base::PropertyList::remove
virtual void remove(std::string const &name)
Remove all values for a property name (possibly hierarchical).
Definition: PropertyList.cc:216
std::make_pair
T make_pair(T... args)
std::list::end
T end(T... args)
lsst::daf::base::PropertySet::combine
virtual void combine(ConstPtr source)
Append all value vectors from the source to their corresponding properties.
lsst::daf::base::PropertyList::getOrderedNames
std::vector< std::string > getOrderedNames() const
Get the list of property names, in the order they were added.
Definition: PropertyList.cc:81
lsst::daf::base::PropertySet::deepCopy
virtual Ptr deepCopy() const
Make a deep copy of the PropertySet and all of its contents.
lsst::daf::base::PropertySet::set
void set(std::string const &name, T const &value)
Replace all values for a property name (possibly hierarchical) with a new scalar value.