LSSTApplications  17.0+11,17.0+34,17.0+56,17.0+57,17.0+59,17.0+7,17.0-1-g377950a+33,17.0.1-1-g114240f+2,17.0.1-1-g4d4fbc4+28,17.0.1-1-g55520dc+49,17.0.1-1-g5f4ed7e+52,17.0.1-1-g6dd7d69+17,17.0.1-1-g8de6c91+11,17.0.1-1-gb9095d2+7,17.0.1-1-ge9fec5e+5,17.0.1-1-gf4e0155+55,17.0.1-1-gfc65f5f+50,17.0.1-1-gfc6fb1f+20,17.0.1-10-g87f9f3f+1,17.0.1-11-ge9de802+16,17.0.1-16-ga14f7d5c+4,17.0.1-17-gc79d625+1,17.0.1-17-gdae4c4a+8,17.0.1-2-g26618f5+29,17.0.1-2-g54f2ebc+9,17.0.1-2-gf403422+1,17.0.1-20-g2ca2f74+6,17.0.1-23-gf3eadeb7+1,17.0.1-3-g7e86b59+39,17.0.1-3-gb5ca14a,17.0.1-3-gd08d533+40,17.0.1-30-g596af8797,17.0.1-4-g59d126d+4,17.0.1-4-gc69c472+5,17.0.1-6-g5afd9b9+4,17.0.1-7-g35889ee+1,17.0.1-7-gc7c8782+18,17.0.1-9-gc4bbfb2+3,w.2019.22
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"
55 #include "lsst/daf/base/Citizen.h"
57 #include "lsst/pex/exceptions.h"
58 
59 namespace lsst {
60 namespace daf {
61 namespace base {
62 
63 #if defined(__ICC)
64 #pragma warning(push)
65 #pragma warning(disable : 444)
66 #endif
67 
69 public:
70  // Typedefs
73 
79  explicit PropertySet(bool flat = false);
80 
82  virtual ~PropertySet() noexcept;
83 
84  // No copying
85  PropertySet(const PropertySet&) = delete;
86  PropertySet& operator=(const PropertySet&) = delete;
87 
88  // No moving
89  PropertySet(PropertySet&&) = delete;
90  PropertySet& operator=(PropertySet&&) = delete;
91 
92  // Accessors
93 
99  virtual Ptr deepCopy() const;
100 
107  size_t nameCount(bool topLevelOnly = true) const;
108 
116  std::vector<std::string> names(bool topLevelOnly = true) const;
117 
121  std::vector<std::string> paramNames(bool topLevelOnly = true) const;
122 
126  std::vector<std::string> propertySetNames(bool topLevelOnly = true) const;
127 
134  bool exists(std::string const& name) const;
135 
142  bool isArray(std::string const& name) const;
143 
150  bool isPropertySetPtr(std::string const& name) const;
151 
158  bool isUndefined(std::string const& name) const;
159 
166  size_t valueCount(std::string const& name) const;
167 
177  std::type_info const& typeOf(std::string const& name) const;
178 
182  // Implemented in the .cc file to work around symbol visiblity issues on macOS
183  // e.g. https://github.com/pybind/pybind11/issues/1503
184  template <typename T>
185  static std::type_info const& typeOfT();
186 
187  // The following throw an exception if the type does not match exactly.
188 
200  template <typename T>
201  T get(std::string const& name) const;
202 
215  template <typename T>
216  T get(std::string const& name, T const& defaultValue) const;
217 
229  template <typename T>
230  std::vector<T> getArray(std::string const& name) const;
231 
232  // The following throw an exception if the conversion is inappropriate.
233 
244  bool getAsBool(std::string const& name) const;
245 
255  int getAsInt(std::string const& name) const;
256 
268  int64_t getAsInt64(std::string const& name) const;
269 
279  double getAsDouble(std::string const& name) const;
280 
292  std::string getAsString(std::string const& name) const;
293 
302  PropertySet::Ptr getAsPropertySetPtr(std::string const& name) const;
303 
312  Persistable::Ptr getAsPersistablePtr(std::string const& name) const;
313 
323  virtual std::string toString(bool topLevelOnly = false, std::string const& indent = "") const;
324 
325  // Modifiers
326 
335  template <typename T>
336  void set(std::string const& name, T const& value);
337 
346  template <typename T>
347  void set(std::string const& name, std::vector<T> const& value);
348 
356  void set(std::string const& name, char const* value);
357 
367  template <typename T>
368  void add(std::string const& name, T const& value);
369 
381  template <typename T>
382  void add(std::string const& name, std::vector<T> const& value);
383 
394  void add(std::string const& name, char const* value);
395 
409  virtual void copy(std::string const& dest, ConstPtr source, std::string const& name,
410  bool asScalar = false);
411 
425  virtual void combine(ConstPtr source);
426 
433  virtual void remove(std::string const& name);
434 
435 protected:
436  /*
437  * Find the property name (possibly hierarchical) and set or replace its
438  * value with the given vector of values. Hook for subclass overrides of
439  * top-level setting.
440  *
441  * @param[in] name Property name to find, possibly hierarchical.
442  * @param[in] vp shared_ptr to vector of values.
443  * @throws InvalidParameterError Hierarchical name uses non-PropertySet.
444  */
445  virtual void _set(std::string const& name, std::shared_ptr<std::vector<boost::any> > vp);
446 
447  /*
448  * Find the property name (possibly hierarchical) and append or set its
449  * value with the given vector of values.
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 _add(std::string const& name, std::shared_ptr<std::vector<boost::any> > vp);
456 
457  // Format a value in human-readable form; called by toString
458  virtual std::string _format(std::string const& name) const;
459 
460 private:
461 
462  typedef std::unordered_map<std::string, std::shared_ptr<std::vector<boost::any> > > AnyMap;
463 
464  /*
465  * Find the property name (possibly hierarchical).
466  *
467  * @param[in] name Property name to find, possibly hierarchical.
468  * @return unordered_map::iterator to the property or end() if nonexistent.
469  */
470  AnyMap::iterator _find(std::string const& name);
471 
472  /*
473  * Find the property name (possibly hierarchical). Const version.
474  *
475  * @param[in] name Property name to find, possibly hierarchical.
476  * @return unordered_map::const_iterator to the property or end().
477  */
478  AnyMap::const_iterator _find(std::string const& name) const;
479 
480  /*
481  * Find the property name (possibly hierarchical) and set or replace its
482  * value with the given vector of values.
483  *
484  * @param[in] name Property name to find, possibly hierarchical.
485  * @param[in] vp shared_ptr to vector of values.
486  * @throws InvalidParameterError Hierarchical name uses non-PropertySet.
487  */
488  virtual void _findOrInsert(std::string const& name, std::shared_ptr<std::vector<boost::any> > vp);
489  void _cycleCheckPtrVec(std::vector<Ptr> const& v, std::string const& name);
490  void _cycleCheckAnyVec(std::vector<boost::any> const& v, std::string const& name);
491  void _cycleCheckPtr(Ptr const& v, std::string const& name);
492 
493  AnyMap _map;
494  bool _flat;
495 };
496 
497 #if defined(__ICC)
498 #pragma warning(pop)
499 #endif
500 
501 template <>
502 void PropertySet::add<PropertySet::Ptr>(std::string const& name, Ptr const& value);
503 template <>
504 void PropertySet::add<PropertySet::Ptr>(std::string const& name, std::vector<Ptr> const& value);
505 }
506 } // namespace daf
507 } // namespace lsst
508 
509 #endif
Interface for Persistable base class.
std::shared_ptr< PropertySet > Ptr
Definition: PropertySet.h:71
Definition: Polygon.cc:25
Basic LSST definitions.
STL namespace.
std::shared_ptr< PropertySet const > ConstPtr
Definition: PropertySet.h:72
daf::base::PropertySet * set
Definition: fits.cc:884
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
STL class.
Class for storing generic metadata.
Definition: PropertySet.h:68
#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
Citizen is a class that should be among all LSST classes base classes, and handles basic memory manag...
Definition: Citizen.h:55