LSST Applications  21.0.0+04719a4bac,21.0.0-1-ga51b5d4+f5e6047307,21.0.0-11-g2b59f77+a9c1acf22d,21.0.0-11-ga42c5b2+86977b0b17,21.0.0-12-gf4ce030+76814010d2,21.0.0-13-g1721dae+760e7a6536,21.0.0-13-g3a573fe+768d78a30a,21.0.0-15-g5a7caf0+f21cbc5713,21.0.0-16-g0fb55c1+b60e2d390c,21.0.0-19-g4cded4ca+71a93a33c0,21.0.0-2-g103fe59+bb20972958,21.0.0-2-g45278ab+04719a4bac,21.0.0-2-g5242d73+3ad5d60fb1,21.0.0-2-g7f82c8f+8babb168e8,21.0.0-2-g8f08a60+06509c8b61,21.0.0-2-g8faa9b5+616205b9df,21.0.0-2-ga326454+8babb168e8,21.0.0-2-gde069b7+5e4aea9c2f,21.0.0-2-gecfae73+1d3a86e577,21.0.0-2-gfc62afb+3ad5d60fb1,21.0.0-25-g1d57be3cd+e73869a214,21.0.0-3-g357aad2+ed88757d29,21.0.0-3-g4a4ce7f+3ad5d60fb1,21.0.0-3-g4be5c26+3ad5d60fb1,21.0.0-3-g65f322c+e0b24896a3,21.0.0-3-g7d9da8d+616205b9df,21.0.0-3-ge02ed75+a9c1acf22d,21.0.0-4-g591bb35+a9c1acf22d,21.0.0-4-g65b4814+b60e2d390c,21.0.0-4-gccdca77+0de219a2bc,21.0.0-4-ge8a399c+6c55c39e83,21.0.0-5-gd00fb1e+05fce91b99,21.0.0-6-gc675373+3ad5d60fb1,21.0.0-64-g1122c245+4fb2b8f86e,21.0.0-7-g04766d7+cd19d05db2,21.0.0-7-gdf92d54+04719a4bac,21.0.0-8-g5674e7b+d1bd76f71f,master-gac4afde19b+a9c1acf22d,w.2021.13
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 
52 #include "boost/any.hpp"
53 
54 #include "lsst/base.h"
56 #include "lsst/pex/exceptions.h"
57 
58 namespace lsst {
59 namespace daf {
60 namespace base {
61 
62 #if defined(__ICC)
63 #pragma warning(push)
64 #pragma warning(disable : 444)
65 #endif
66 
68 public:
69  // Typedefs
72 
78  explicit PropertySet(bool flat = false);
79 
81  virtual ~PropertySet() noexcept;
82 
83  // No copying
84  PropertySet(const PropertySet&) = delete;
85  PropertySet& operator=(const PropertySet&) = delete;
86 
87  // No moving
88  PropertySet(PropertySet&&) = delete;
89  PropertySet& operator=(PropertySet&&) = delete;
90 
91  // Accessors
92 
98  virtual Ptr deepCopy() const;
99 
106  size_t nameCount(bool topLevelOnly = true) const;
107 
115  std::vector<std::string> names(bool topLevelOnly = true) const;
116 
120  std::vector<std::string> paramNames(bool topLevelOnly = true) const;
121 
125  std::vector<std::string> propertySetNames(bool topLevelOnly = true) const;
126 
133  bool exists(std::string const& name) const;
134 
141  bool isArray(std::string const& name) const;
142 
149  bool isPropertySetPtr(std::string const& name) const;
150 
157  bool isUndefined(std::string const& name) const;
158 
165  size_t valueCount() const;
166 
173  size_t valueCount(std::string const& name) const;
174 
184  std::type_info const& typeOf(std::string const& name) const;
185 
189  // Implemented in the .cc file to work around symbol visiblity issues on macOS
190  // e.g. https://github.com/pybind/pybind11/issues/1503
191  template <typename T>
192  static std::type_info const& typeOfT();
193 
194  // The following throw an exception if the type does not match exactly.
195 
207  template <typename T>
208  T get(std::string const& name) const;
209 
222  template <typename T>
223  T get(std::string const& name, T const& defaultValue) const;
224 
236  template <typename T>
237  std::vector<T> getArray(std::string const& name) const;
238 
239  // The following throw an exception if the conversion is inappropriate.
240 
251  bool getAsBool(std::string const& name) const;
252 
262  int getAsInt(std::string const& name) const;
263 
275  int64_t getAsInt64(std::string const& name) const;
276 
286  uint64_t getAsUInt64(std::string const& name) const;
287 
297  double getAsDouble(std::string const& name) const;
298 
310  std::string getAsString(std::string const& name) const;
311 
320  PropertySet::Ptr getAsPropertySetPtr(std::string const& name) const;
321 
330  Persistable::Ptr getAsPersistablePtr(std::string const& name) const;
331 
341  virtual std::string toString(bool topLevelOnly = false, std::string const& indent = "") const;
342 
343  // Modifiers
344 
353  template <typename T>
354  void set(std::string const& name, T const& value);
355 
364  template <typename T>
365  void set(std::string const& name, std::vector<T> const& value);
366 
374  void set(std::string const& name, char const* value);
375 
385  template <typename T>
386  void add(std::string const& name, T const& value);
387 
399  template <typename T>
400  void add(std::string const& name, std::vector<T> const& value);
401 
412  void add(std::string const& name, char const* value);
413 
427  virtual void copy(std::string const& dest, ConstPtr source, std::string const& name,
428  bool asScalar = false);
429 
443  virtual void combine(ConstPtr source);
444 
451  virtual void remove(std::string const& name);
452 
453 protected:
454  /*
455  * Find the property name (possibly hierarchical) and set or replace its
456  * value with the given vector of values. Hook for subclass overrides of
457  * top-level setting.
458  *
459  * @param[in] name Property name to find, possibly hierarchical.
460  * @param[in] vp shared_ptr to vector of values.
461  * @throws InvalidParameterError Hierarchical name uses non-PropertySet.
462  */
463  virtual void _set(std::string const& name, std::shared_ptr<std::vector<boost::any> > vp);
464 
465  /*
466  * Find the property name (possibly hierarchical) and append or set its
467  * value with the given vector of values.
468  *
469  * @param[in] name Property name to find, possibly hierarchical.
470  * @param[in] vp shared_ptr to vector of values.
471  * @throws InvalidParameterError Hierarchical name uses non-PropertySet.
472  */
473  virtual void _add(std::string const& name, std::shared_ptr<std::vector<boost::any> > vp);
474 
475  // Format a value in human-readable form; called by toString
476  virtual std::string _format(std::string const& name) const;
477 
478 private:
479 
480  typedef std::unordered_map<std::string, std::shared_ptr<std::vector<boost::any> > > AnyMap;
481 
482  /*
483  * Find the property name (possibly hierarchical).
484  *
485  * @param[in] name Property name to find, possibly hierarchical.
486  * @return unordered_map::iterator to the property or end() if nonexistent.
487  */
488  AnyMap::iterator _find(std::string const& name);
489 
490  /*
491  * Find the property name (possibly hierarchical). Const version.
492  *
493  * @param[in] name Property name to find, possibly hierarchical.
494  * @return unordered_map::const_iterator to the property or end().
495  */
496  AnyMap::const_iterator _find(std::string const& name) const;
497 
498  /*
499  * Find the property name (possibly hierarchical) and set or replace its
500  * value with the given vector of values.
501  *
502  * @param[in] name Property name to find, possibly hierarchical.
503  * @param[in] vp shared_ptr to vector of values.
504  * @throws InvalidParameterError Hierarchical name uses non-PropertySet.
505  */
506  virtual void _findOrInsert(std::string const& name, std::shared_ptr<std::vector<boost::any> > vp);
507  void _cycleCheckPtrVec(std::vector<Ptr> const& v, std::string const& name);
508  void _cycleCheckAnyVec(std::vector<boost::any> const& v, std::string const& name);
509  void _cycleCheckPtr(Ptr const& v, std::string const& name);
510 
511  AnyMap _map;
512  bool _flat;
513 };
514 
515 #if defined(__ICC)
516 #pragma warning(pop)
517 #endif
518 
519 template <>
520 void PropertySet::add<PropertySet::Ptr>(std::string const& name, Ptr const& value);
521 template <>
522 void PropertySet::add<PropertySet::Ptr>(std::string const& name, std::vector<Ptr> const& value);
523 }
524 } // namespace daf
525 } // namespace lsst
526 
527 #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:54
Base class for all persistable classes.
Definition: Persistable.h:75
Class for storing generic metadata.
Definition: PropertySet.h:67
std::shared_ptr< PropertySet > Ptr
Definition: PropertySet.h:70
std::shared_ptr< PropertySet const > ConstPtr
Definition: PropertySet.h:71
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
Definition: Polygon.cc:25
bool any(CoordinateExpr< N > const &expr) noexcept
Return true if any elements are true.
A base class for image defects.
STL namespace.