LSSTApplications  17.0+124,17.0+14,17.0+73,18.0.0+37,18.0.0+80,18.0.0-4-g68ffd23+4,18.1.0-1-g0001055+12,18.1.0-1-g03d53ef+5,18.1.0-1-g1349e88+55,18.1.0-1-g2505f39+44,18.1.0-1-g5315e5e+4,18.1.0-1-g5e4b7ea+14,18.1.0-1-g7e8fceb+4,18.1.0-1-g85f8cd4+48,18.1.0-1-g8ff0b9f+4,18.1.0-1-ga2c679d+1,18.1.0-1-gd55f500+35,18.1.0-10-gb58edde+2,18.1.0-11-g0997b02+4,18.1.0-13-gfe4edf0b+12,18.1.0-14-g259bd21+21,18.1.0-19-gdb69f3f+2,18.1.0-2-g5f9922c+24,18.1.0-2-gd3b74e5+11,18.1.0-2-gfbf3545+32,18.1.0-26-g728bddb4+5,18.1.0-27-g6ff7ca9+2,18.1.0-3-g52aa583+25,18.1.0-3-g8ea57af+9,18.1.0-3-gb69f684+42,18.1.0-3-gfcaddf3+6,18.1.0-32-gd8786685a,18.1.0-4-gf3f9b77+6,18.1.0-5-g1dd662b+2,18.1.0-5-g6dbcb01+41,18.1.0-6-gae77429+3,18.1.0-7-g9d75d83+9,18.1.0-7-gae09a6d+30,18.1.0-9-gc381ef5+4,w.2019.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(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::shared_ptr< PropertySet > Ptr
Definition: PropertySet.h:70
Definition: Polygon.cc:25
STL namespace.
std::shared_ptr< PropertySet const > ConstPtr
Definition: PropertySet.h:71
daf::base::PropertySet * set
Definition: fits.cc:902
bool any(CoordinateExpr< N > const &expr) noexcept
Return true if any elements are true.
STL class.
A base class for image defects.
const char * source()
Source function that allows astChannel to source from a Stream.
Definition: Stream.h:224
Interface for Persistable base class.
Definition: __init__.py:1
STL class.
Class for storing generic metadata.
Definition: PropertySet.h:67
Basic LSST definitions.
Base class for all persistable classes.
Definition: Persistable.h:75
#define LSST_EXPORT
Make a symbol visible even if visiblity is hidden (e.g.
Definition: base.h:54