LSSTApplications  19.0.0-14-gb0260a2+72efe9b372,20.0.0+7927753e06,20.0.0+8829bf0056,20.0.0+995114c5d2,20.0.0+b6f4b2abd1,20.0.0+bddc4f4cbe,20.0.0-1-g253301a+8829bf0056,20.0.0-1-g2b7511a+0d71a2d77f,20.0.0-1-g5b95a8c+7461dd0434,20.0.0-12-g321c96ea+23efe4bbff,20.0.0-16-gfab17e72e+fdf35455f6,20.0.0-2-g0070d88+ba3ffc8f0b,20.0.0-2-g4dae9ad+ee58a624b3,20.0.0-2-g61b8584+5d3db074ba,20.0.0-2-gb780d76+d529cf1a41,20.0.0-2-ged6426c+226a441f5f,20.0.0-2-gf072044+8829bf0056,20.0.0-2-gf1f7952+ee58a624b3,20.0.0-20-geae50cf+e37fec0aee,20.0.0-25-g3dcad98+544a109665,20.0.0-25-g5eafb0f+ee58a624b3,20.0.0-27-g64178ef+f1f297b00a,20.0.0-3-g4cc78c6+e0676b0dc8,20.0.0-3-g8f21e14+4fd2c12c9a,20.0.0-3-gbd60e8c+187b78b4b8,20.0.0-3-gbecbe05+48431fa087,20.0.0-38-ge4adf513+a12e1f8e37,20.0.0-4-g97dc21a+544a109665,20.0.0-4-gb4befbc+087873070b,20.0.0-4-gf910f65+5d3db074ba,20.0.0-5-gdfe0fee+199202a608,20.0.0-5-gfbfe500+d529cf1a41,20.0.0-6-g64f541c+d529cf1a41,20.0.0-6-g9a5b7a1+a1cd37312e,20.0.0-68-ga3f3dda+5fca18c6a4,20.0.0-9-g4aef684+e18322736b,w.2020.45
LSSTDataManagementBasePackage
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
std::string
STL class.
std::shared_ptr< PropertySet >
std::vector
STL class.
boost
Definition: Polygon.cc:25
lsst::daf::base::PropertySet::Ptr
std::shared_ptr< PropertySet > Ptr
Definition: PropertySet.h:70
lsst::afw::geom.transform.transformContinued.name
string name
Definition: transformContinued.py:32
ast::detail::source
const char * source()
Source function that allows astChannel to source from a Stream.
Definition: Stream.h:224
base.h
lsst::geom::any
bool any(CoordinateExpr< N > const &expr) noexcept
Return true if any elements are true.
Definition: CoordinateExpr.h:89
lsst
A base class for image defects.
Definition: imageAlgorithm.dox:1
Persistable.h
Interface for Persistable base class.
lsst::daf::base::PropertySet::ConstPtr
std::shared_ptr< PropertySet const > ConstPtr
Definition: PropertySet.h:71
lsst::daf::base::Persistable
Base class for all persistable classes.
Definition: Persistable.h:75
std
STL namespace.
lsst::daf::base::PropertySet::~PropertySet
virtual ~PropertySet() noexcept
Destructor.
lsst::daf::base::PropertySet
Class for storing generic metadata.
Definition: PropertySet.h:67
lsst::daf::base::PropertySet::PropertySet
PropertySet(bool flat=false)
Construct an empty PropertySet.
std::unordered_map< std::string, std::shared_ptr< std::vector< boost::any > > >
set
daf::base::PropertySet * set
Definition: fits.cc:912
LSST_EXPORT
#define LSST_EXPORT
Make a symbol visible even if visiblity is hidden (e.g.
Definition: base.h:54
exceptions.h