LSSTApplications  19.0.0-14-gb0260a2+c4152221ba,20.0.0+428775a0ef,20.0.0+7c6b12c2f9,20.0.0+ae956f52c5,20.0.0+c388114e2c,20.0.0+e2e26847c2,20.0.0+e5529315c6,20.0.0-1-g04bee24+7c6b12c2f9,20.0.0-1-g10df615+cc9679e3e4,20.0.0-1-g253301a+7c6b12c2f9,20.0.0-1-g2b7511a+46a6078777,20.0.0-1-g4d801e7+9b3155b620,20.0.0-1-g5b95a8c+3d35cd64b7,20.0.0-1-gb058bd0+46a6078777,20.0.0-1-gb88604f+acecce4127,20.0.0-1-gc96f8cb+f5ea1f6730,20.0.0-1-gedffbd8+57e6df9186,20.0.0-10-g0891cd99+21712b8dc8,20.0.0-10-g9a20bd332+576ca7b471,20.0.0-17-gcdbda88+f8ebf1b2ab,20.0.0-2-g4dae9ad+f5ea1f6730,20.0.0-2-g61b8584+85c46248f3,20.0.0-2-gb780d76+f45b7d88f4,20.0.0-20-g7966b28+f5ea1f6730,20.0.0-21-g1f5da01+74cacf985d,20.0.0-23-g8900aa8+dfd6ff4ddf,20.0.0-3-g1653f94+85c46248f3,20.0.0-3-g4cc78c6+63636aeed8,20.0.0-3-g750bffe+3a91ba9410,20.0.0-3-gbd60e8c+ff10c6d78d,20.0.0-32-g15a0e07c+fb20712e7c,20.0.0-4-g97dc21a+dfd6ff4ddf,20.0.0-4-gfea843c+f45b7d88f4,20.0.0-5-g357b56b+f45b7d88f4,20.0.0-59-gb502cbb+701042a847,20.0.0-6-g9a5b7a1+3980549e0d,20.0.0-7-gcda7bf1+ddb9d7f898,w.2020.43
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(std::string const& name) const;
166 
176  std::type_info const& typeOf(std::string const& name) const;
177 
181  // Implemented in the .cc file to work around symbol visiblity issues on macOS
182  // e.g. https://github.com/pybind/pybind11/issues/1503
183  template <typename T>
184  static std::type_info const& typeOfT();
185 
186  // The following throw an exception if the type does not match exactly.
187 
199  template <typename T>
200  T get(std::string const& name) const;
201 
214  template <typename T>
215  T get(std::string const& name, T const& defaultValue) const;
216 
228  template <typename T>
229  std::vector<T> getArray(std::string const& name) const;
230 
231  // The following throw an exception if the conversion is inappropriate.
232 
243  bool getAsBool(std::string const& name) const;
244 
254  int getAsInt(std::string const& name) const;
255 
267  int64_t getAsInt64(std::string const& name) const;
268 
278  uint64_t getAsUInt64(std::string const& name) const;
279 
289  double getAsDouble(std::string const& name) const;
290 
302  std::string getAsString(std::string const& name) const;
303 
312  PropertySet::Ptr getAsPropertySetPtr(std::string const& name) const;
313 
322  Persistable::Ptr getAsPersistablePtr(std::string const& name) const;
323 
333  virtual std::string toString(bool topLevelOnly = false, std::string const& indent = "") const;
334 
335  // Modifiers
336 
345  template <typename T>
346  void set(std::string const& name, T const& value);
347 
356  template <typename T>
357  void set(std::string const& name, std::vector<T> const& value);
358 
366  void set(std::string const& name, char const* value);
367 
377  template <typename T>
378  void add(std::string const& name, T const& value);
379 
391  template <typename T>
392  void add(std::string const& name, std::vector<T> const& value);
393 
404  void add(std::string const& name, char const* value);
405 
419  virtual void copy(std::string const& dest, ConstPtr source, std::string const& name,
420  bool asScalar = false);
421 
435  virtual void combine(ConstPtr source);
436 
443  virtual void remove(std::string const& name);
444 
445 protected:
446  /*
447  * Find the property name (possibly hierarchical) and set or replace its
448  * value with the given vector of values. Hook for subclass overrides of
449  * top-level setting.
450  *
451  * @param[in] name Property name to find, possibly hierarchical.
452  * @param[in] vp shared_ptr to vector of values.
453  * @throws InvalidParameterError Hierarchical name uses non-PropertySet.
454  */
455  virtual void _set(std::string const& name, std::shared_ptr<std::vector<boost::any> > vp);
456 
457  /*
458  * Find the property name (possibly hierarchical) and append or set its
459  * value with the given vector of values.
460  *
461  * @param[in] name Property name to find, possibly hierarchical.
462  * @param[in] vp shared_ptr to vector of values.
463  * @throws InvalidParameterError Hierarchical name uses non-PropertySet.
464  */
465  virtual void _add(std::string const& name, std::shared_ptr<std::vector<boost::any> > vp);
466 
467  // Format a value in human-readable form; called by toString
468  virtual std::string _format(std::string const& name) const;
469 
470 private:
471 
472  typedef std::unordered_map<std::string, std::shared_ptr<std::vector<boost::any> > > AnyMap;
473 
474  /*
475  * Find the property name (possibly hierarchical).
476  *
477  * @param[in] name Property name to find, possibly hierarchical.
478  * @return unordered_map::iterator to the property or end() if nonexistent.
479  */
480  AnyMap::iterator _find(std::string const& name);
481 
482  /*
483  * Find the property name (possibly hierarchical). Const version.
484  *
485  * @param[in] name Property name to find, possibly hierarchical.
486  * @return unordered_map::const_iterator to the property or end().
487  */
488  AnyMap::const_iterator _find(std::string const& name) const;
489 
490  /*
491  * Find the property name (possibly hierarchical) and set or replace its
492  * value with the given vector of values.
493  *
494  * @param[in] name Property name to find, possibly hierarchical.
495  * @param[in] vp shared_ptr to vector of values.
496  * @throws InvalidParameterError Hierarchical name uses non-PropertySet.
497  */
498  virtual void _findOrInsert(std::string const& name, std::shared_ptr<std::vector<boost::any> > vp);
499  void _cycleCheckPtrVec(std::vector<Ptr> const& v, std::string const& name);
500  void _cycleCheckAnyVec(std::vector<boost::any> const& v, std::string const& name);
501  void _cycleCheckPtr(Ptr const& v, std::string const& name);
502 
503  AnyMap _map;
504  bool _flat;
505 };
506 
507 #if defined(__ICC)
508 #pragma warning(pop)
509 #endif
510 
511 template <>
512 void PropertySet::add<PropertySet::Ptr>(std::string const& name, Ptr const& value);
513 template <>
514 void PropertySet::add<PropertySet::Ptr>(std::string const& name, std::vector<Ptr> const& value);
515 }
516 } // namespace daf
517 } // namespace lsst
518 
519 #endif
std::string
STL class.
std::shared_ptr< PropertySet >
base.h
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
Persistable.h
Interface for Persistable base class.
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
exceptions.h
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.
LSST_EXPORT
#define LSST_EXPORT
Make a symbol visible even if visiblity is hidden (e.g.
Definition: base.h:54
std::unordered_map< std::string, std::shared_ptr< std::vector< boost::any > > >
set
daf::base::PropertySet * set
Definition: fits.cc:912