LSST Applications g0b6bd0c080+a72a5dd7e6,g1182afd7b4+2a019aa3bb,g17e5ecfddb+2b8207f7de,g1d67935e3f+06cf436103,g38293774b4+ac198e9f13,g396055baef+6a2097e274,g3b44f30a73+6611e0205b,g480783c3b1+98f8679e14,g48ccf36440+89c08d0516,g4b93dc025c+98f8679e14,g5c4744a4d9+a302e8c7f0,g613e996a0d+e1c447f2e0,g6c8d09e9e7+25247a063c,g7271f0639c+98f8679e14,g7a9cd813b8+124095ede6,g9d27549199+a302e8c7f0,ga1cf026fa3+ac198e9f13,ga32aa97882+7403ac30ac,ga786bb30fb+7a139211af,gaa63f70f4e+9994eb9896,gabf319e997+ade567573c,gba47b54d5d+94dc90c3ea,gbec6a3398f+06cf436103,gc6308e37c7+07dd123edb,gc655b1545f+ade567573c,gcc9029db3c+ab229f5caf,gd01420fc67+06cf436103,gd877ba84e5+06cf436103,gdb4cecd868+6f279b5b48,ge2d134c3d5+cc4dbb2e3f,ge448b5faa6+86d1ceac1d,gecc7e12556+98f8679e14,gf3ee170dca+25247a063c,gf4ac96e456+ade567573c,gf9f5ea5b4d+ac198e9f13,gff490e6085+8c2580be5c,w.2022.27
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#include <any>
52
53#include "lsst/base.h"
55#include "lsst/pex/exceptions.h"
56
57namespace lsst {
58namespace daf {
59namespace base {
60
61#if defined(__ICC)
62#pragma warning(push)
63#pragma warning(disable : 444)
64#endif
65
67public:
68 // Typedefs
71
77 explicit PropertySet(bool flat = false);
78
80 virtual ~PropertySet() noexcept;
81
82 // No copying
83 PropertySet(const PropertySet&) = delete;
84 PropertySet& operator=(const PropertySet&) = delete;
85
86 // No moving
88 PropertySet& operator=(PropertySet&&) = delete;
89
90 // Accessors
91
97 virtual std::shared_ptr<PropertySet> deepCopy() const;
98
105 size_t nameCount(bool topLevelOnly = true) const;
106
114 std::vector<std::string> names(bool topLevelOnly = true) const;
115
119 std::vector<std::string> paramNames(bool topLevelOnly = true) const;
120
124 std::vector<std::string> propertySetNames(bool topLevelOnly = true) const;
125
132 bool exists(std::string const& name) const;
133
140 bool isArray(std::string const& name) const;
141
148 bool isPropertySetPtr(std::string const& name) const;
149
156 bool isUndefined(std::string const& name) const;
157
164 size_t valueCount() const;
165
172 size_t valueCount(std::string const& name) const;
173
183 std::type_info const& typeOf(std::string const& name) const;
184
188 // Implemented in the .cc file to work around symbol visiblity issues on macOS
189 // e.g. https://github.com/pybind/pybind11/issues/1503
190 template <typename T>
191 static std::type_info const& typeOfT();
192
193 // The following throw an exception if the type does not match exactly.
194
206 template <typename T>
207 T get(std::string const& name) const;
208
221 template <typename T>
222 T get(std::string const& name, T const& defaultValue) const;
223
235 template <typename T>
236 std::vector<T> getArray(std::string const& name) const;
237
238 // The following throw an exception if the conversion is inappropriate.
239
250 bool getAsBool(std::string const& name) const;
251
261 int getAsInt(std::string const& name) const;
262
274 int64_t getAsInt64(std::string const& name) const;
275
285 uint64_t getAsUInt64(std::string const& name) const;
286
296 double getAsDouble(std::string const& name) const;
297
309 std::string getAsString(std::string const& name) const;
310
319 std::shared_ptr<PropertySet> getAsPropertySetPtr(std::string const& name) const;
320
329 Persistable::Ptr getAsPersistablePtr(std::string const& name) const;
330
340 virtual std::string toString(bool topLevelOnly = false, std::string const& indent = "") const;
341
342 // Modifiers
343
358 template <typename T>
359 void set(std::string const& name, T const& value);
360
369 template <typename T>
370 void set(std::string const& name, std::vector<T> const& value);
371
379 void set(std::string const& name, char const* value);
380
396 template <typename T>
397 void add(std::string const& name, T const& value);
398
410 template <typename T>
411 void add(std::string const& name, std::vector<T> const& value);
412
423 void add(std::string const& name, char const* value);
424
426
439 virtual void copy(std::string const& dest, PropertySet const & source, std::string const& name,
440 bool asScalar = false);
441 [[deprecated("Replaced by a non-shared_ptr overload. Will be removed after v25.")]]
442 virtual void copy(std::string const& dest, std::shared_ptr<PropertySet const> source,
443 std::string const& name, bool asScalar = false);
445
447
460 virtual void combine(PropertySet const & source);
461 [[deprecated("Replaced by a non-shared_ptr overload. Will be removed after v25.")]]
462 virtual void combine(std::shared_ptr<PropertySet const> source);
464
471 virtual void remove(std::string const& name);
472
473protected:
474 /*
475 * Find the property name (possibly hierarchical) and set or replace its
476 * value with the given vector of values. Hook for subclass overrides of
477 * top-level setting.
478 *
479 * @param[in] name Property name to find, possibly hierarchical.
480 * @param[in] vp shared_ptr to vector of values.
481 * @throws InvalidParameterError Hierarchical name uses non-PropertySet.
482 */
483 virtual void _set(std::string const& name, std::shared_ptr<std::vector<std::any> > vp);
484
485 /*
486 * Find the property name (possibly hierarchical) and append or set its
487 * value with the given vector of values.
488 *
489 * @param[in] name Property name to find, possibly hierarchical.
490 * @param[in] vp shared_ptr to vector of values.
491 * @throws InvalidParameterError Hierarchical name uses non-PropertySet.
492 */
493 virtual void _add(std::string const& name, std::shared_ptr<std::vector<std::any> > vp);
494
495 // Format a value in human-readable form; called by toString
496 virtual std::string _format(std::string const& name) const;
497
498private:
499
500 typedef std::unordered_map<std::string, std::shared_ptr<std::vector<std::any> > > AnyMap;
501
502 /*
503 * Find the property name (possibly hierarchical).
504 *
505 * @param[in] name Property name to find, possibly hierarchical.
506 * @return unordered_map::iterator to the property or end() if nonexistent.
507 */
508 AnyMap::iterator _find(std::string const& name);
509
510 /*
511 * Find the property name (possibly hierarchical). Const version.
512 *
513 * @param[in] name Property name to find, possibly hierarchical.
514 * @return unordered_map::const_iterator to the property or end().
515 */
516 AnyMap::const_iterator _find(std::string const& name) const;
517
518 /*
519 * Find the property name (possibly hierarchical) and set or replace its
520 * value with the given vector of values.
521 *
522 * @param[in] name Property name to find, possibly hierarchical.
523 * @param[in] vp shared_ptr to vector of values.
524 * @throws InvalidParameterError Hierarchical name uses non-PropertySet.
525 */
526 virtual void _findOrInsert(std::string const& name, std::shared_ptr<std::vector<std::any> > vp);
527 void _cycleCheckPtrVec(std::vector<std::shared_ptr<PropertySet>> const& v, std::string const& name);
528 void _cycleCheckAnyVec(std::vector<std::any> const& v, std::string const& name);
529 void _cycleCheckPtr(std::shared_ptr<PropertySet> const & v, std::string const& name);
530
531 AnyMap _map;
532 bool _flat;
533};
534
535#if defined(__ICC)
536#pragma warning(pop)
537#endif
538
539template <>
540void PropertySet::add<std::shared_ptr<PropertySet>>(
541 std::string const& name,
543);
544
545template <>
546void PropertySet::add<std::shared_ptr<PropertySet>>(
547 std::string const& name,
549);
550
551}
552} // namespace daf
553} // namespace lsst
554
555#endif
table::Key< std::string > name
Definition: Amplifier.cc:116
table::Key< int > a
Basic LSST definitions.
#define LSST_EXPORT
Make a symbol visible even if visiblity is hidden (e.g.
Definition: base.h:37
Base class for all persistable classes.
Definition: Persistable.h:75
Class for storing generic metadata.
Definition: PropertySet.h:66
std::shared_ptr< PropertySet > Ptr
Definition: PropertySet.h:69
std::shared_ptr< PropertySet const > ConstPtr
Definition: PropertySet.h:70
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
bool any(CoordinateExpr< N > const &expr) noexcept
Return true if any elements are true.
A base class for image defects.
STL namespace.