LSST Applications  21.0.0-147-g0e635eb1+1acddb5be5,22.0.0+052faf71bd,22.0.0+1ea9a8b2b2,22.0.0+6312710a6c,22.0.0+729191ecac,22.0.0+7589c3a021,22.0.0+9f079a9461,22.0.1-1-g7d6de66+b8044ec9de,22.0.1-1-g87000a6+536b1ee016,22.0.1-1-g8e32f31+6312710a6c,22.0.1-10-gd060f87+016f7cdc03,22.0.1-12-g9c3108e+df145f6f68,22.0.1-16-g314fa6d+c825727ab8,22.0.1-19-g93a5c75+d23f2fb6d8,22.0.1-19-gb93eaa13+aab3ef7709,22.0.1-2-g8ef0a89+b8044ec9de,22.0.1-2-g92698f7+9f079a9461,22.0.1-2-ga9b0f51+052faf71bd,22.0.1-2-gac51dbf+052faf71bd,22.0.1-2-gb66926d+6312710a6c,22.0.1-2-gcb770ba+09e3807989,22.0.1-20-g32debb5+b8044ec9de,22.0.1-23-gc2439a9a+fb0756638e,22.0.1-3-g496fd5d+09117f784f,22.0.1-3-g59f966b+1e6ba2c031,22.0.1-3-g849a1b8+f8b568069f,22.0.1-3-gaaec9c0+c5c846a8b1,22.0.1-32-g5ddfab5d3+60ce4897b0,22.0.1-4-g037fbe1+64e601228d,22.0.1-4-g8623105+b8044ec9de,22.0.1-5-g096abc9+d18c45d440,22.0.1-5-g15c806e+57f5c03693,22.0.1-7-gba73697+57f5c03693,master-g6e05de7fdc+c1283a92b8,master-g72cdda8301+729191ecac,w.2021.39
LSST Data Management Base Package
PropertySet.h
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 
25 #ifndef LSST_DAF_BASE_PROPERTYSET
26 #define LSST_DAF_BASE_PROPERTYSET
27 
46 #include <memory>
47 #include <string>
48 #include <typeinfo>
49 #include <unordered_map>
50 #include <vector>
51 #include <any>
52 
53 #include "lsst/base.h"
55 #include "lsst/pex/exceptions.h"
56 
57 namespace lsst {
58 namespace daf {
59 namespace base {
60 
61 #if defined(__ICC)
62 #pragma warning(push)
63 #pragma warning(disable : 444)
64 #endif
65 
67 public:
68  // Typedefs
71 
77  explicit PropertySet(bool flat = false);
78 
80  virtual ~PropertySet() noexcept;
81 
82  // No copying
83  PropertySet(const PropertySet&) = delete;
84  PropertySet& operator=(const PropertySet&) = delete;
85 
86  // No moving
87  PropertySet(PropertySet&&) = delete;
88  PropertySet& operator=(PropertySet&&) = delete;
89 
90  // Accessors
91 
97  virtual Ptr deepCopy() const;
98 
105  size_t nameCount(bool topLevelOnly = true) const;
106 
114  std::vector<std::string> names(bool topLevelOnly = true) const;
115 
119  std::vector<std::string> paramNames(bool topLevelOnly = true) const;
120 
124  std::vector<std::string> propertySetNames(bool topLevelOnly = true) const;
125 
132  bool exists(std::string const& name) const;
133 
140  bool isArray(std::string const& name) const;
141 
148  bool isPropertySetPtr(std::string const& name) const;
149 
156  bool isUndefined(std::string const& name) const;
157 
164  size_t valueCount() const;
165 
172  size_t valueCount(std::string const& name) const;
173 
183  std::type_info const& typeOf(std::string const& name) const;
184 
188  // Implemented in the .cc file to work around symbol visiblity issues on macOS
189  // e.g. https://github.com/pybind/pybind11/issues/1503
190  template <typename T>
191  static std::type_info const& typeOfT();
192 
193  // The following throw an exception if the type does not match exactly.
194 
206  template <typename T>
207  T get(std::string const& name) const;
208 
221  template <typename T>
222  T get(std::string const& name, T const& defaultValue) const;
223 
235  template <typename T>
236  std::vector<T> getArray(std::string const& name) const;
237 
238  // The following throw an exception if the conversion is inappropriate.
239 
250  bool getAsBool(std::string const& name) const;
251 
261  int getAsInt(std::string const& name) const;
262 
274  int64_t getAsInt64(std::string const& name) const;
275 
285  uint64_t getAsUInt64(std::string const& name) const;
286 
296  double getAsDouble(std::string const& name) const;
297 
309  std::string getAsString(std::string const& name) const;
310 
319  PropertySet::Ptr getAsPropertySetPtr(std::string const& name) const;
320 
329  Persistable::Ptr getAsPersistablePtr(std::string const& name) const;
330 
340  virtual std::string toString(bool topLevelOnly = false, std::string const& indent = "") const;
341 
342  // Modifiers
343 
352  template <typename T>
353  void set(std::string const& name, T const& value);
354 
363  template <typename T>
364  void set(std::string const& name, std::vector<T> const& value);
365 
373  void set(std::string const& name, char const* value);
374 
384  template <typename T>
385  void add(std::string const& name, T const& value);
386 
398  template <typename T>
399  void add(std::string const& name, std::vector<T> const& value);
400 
411  void add(std::string const& name, char const* value);
412 
426  virtual void copy(std::string const& dest, ConstPtr source, std::string const& name,
427  bool asScalar = false);
428 
442  virtual void combine(ConstPtr source);
443 
450  virtual void remove(std::string const& name);
451 
452 protected:
453  /*
454  * Find the property name (possibly hierarchical) and set or replace its
455  * value with the given vector of values. Hook for subclass overrides of
456  * top-level setting.
457  *
458  * @param[in] name Property name to find, possibly hierarchical.
459  * @param[in] vp shared_ptr to vector of values.
460  * @throws InvalidParameterError Hierarchical name uses non-PropertySet.
461  */
462  virtual void _set(std::string const& name, std::shared_ptr<std::vector<std::any> > vp);
463 
464  /*
465  * Find the property name (possibly hierarchical) and append or set its
466  * value with the given vector of values.
467  *
468  * @param[in] name Property name to find, possibly hierarchical.
469  * @param[in] vp shared_ptr to vector of values.
470  * @throws InvalidParameterError Hierarchical name uses non-PropertySet.
471  */
472  virtual void _add(std::string const& name, std::shared_ptr<std::vector<std::any> > vp);
473 
474  // Format a value in human-readable form; called by toString
475  virtual std::string _format(std::string const& name) const;
476 
477 private:
478 
479  typedef std::unordered_map<std::string, std::shared_ptr<std::vector<std::any> > > AnyMap;
480 
481  /*
482  * Find the property name (possibly hierarchical).
483  *
484  * @param[in] name Property name to find, possibly hierarchical.
485  * @return unordered_map::iterator to the property or end() if nonexistent.
486  */
487  AnyMap::iterator _find(std::string const& name);
488 
489  /*
490  * Find the property name (possibly hierarchical). Const version.
491  *
492  * @param[in] name Property name to find, possibly hierarchical.
493  * @return unordered_map::const_iterator to the property or end().
494  */
495  AnyMap::const_iterator _find(std::string const& name) const;
496 
497  /*
498  * Find the property name (possibly hierarchical) and set or replace its
499  * value with the given vector of values.
500  *
501  * @param[in] name Property name to find, possibly hierarchical.
502  * @param[in] vp shared_ptr to vector of values.
503  * @throws InvalidParameterError Hierarchical name uses non-PropertySet.
504  */
505  virtual void _findOrInsert(std::string const& name, std::shared_ptr<std::vector<std::any> > vp);
506  void _cycleCheckPtrVec(std::vector<Ptr> const& v, std::string const& name);
507  void _cycleCheckAnyVec(std::vector<std::any> const& v, std::string const& name);
508  void _cycleCheckPtr(Ptr const& v, std::string const& name);
509 
510  AnyMap _map;
511  bool _flat;
512 };
513 
514 #if defined(__ICC)
515 #pragma warning(pop)
516 #endif
517 
518 template <>
519 void PropertySet::add<PropertySet::Ptr>(std::string const& name, Ptr const& value);
520 template <>
521 void PropertySet::add<PropertySet::Ptr>(std::string const& name, std::vector<Ptr> const& value);
522 }
523 } // namespace daf
524 } // namespace lsst
525 
526 #endif
table::Key< std::string > name
Definition: Amplifier.cc:116
Basic LSST definitions.
#define LSST_EXPORT
Make a symbol visible even if visiblity is hidden (e.g.
Definition: base.h:37
Base class for all persistable classes.
Definition: Persistable.h:75
Class for storing generic metadata.
Definition: PropertySet.h:66
std::shared_ptr< PropertySet > Ptr
Definition: PropertySet.h:69
std::shared_ptr< PropertySet const > ConstPtr
Definition: PropertySet.h:70
PropertySet(bool flat=false)
Construct an empty PropertySet.
virtual ~PropertySet() noexcept
Destructor.
Interface for Persistable base class.
daf::base::PropertySet * set
Definition: fits.cc:912
const char * source()
Source function that allows astChannel to source from a Stream.
Definition: Stream.h:224
bool any(CoordinateExpr< N > const &expr) noexcept
Return true if any elements are true.
A base class for image defects.
STL namespace.