LSST Applications 26.0.0,g0265f82a02+6660c170cc,g07994bdeae+30b05a742e,g0a0026dc87+17526d298f,g0a60f58ba1+17526d298f,g0e4bf8285c+96dd2c2ea9,g0ecae5effc+c266a536c8,g1e7d6db67d+6f7cb1f4bb,g26482f50c6+6346c0633c,g2bbee38e9b+6660c170cc,g2cc88a2952+0a4e78cd49,g3273194fdb+f6908454ef,g337abbeb29+6660c170cc,g337c41fc51+9a8f8f0815,g37c6e7c3d5+7bbafe9d37,g44018dc512+6660c170cc,g4a941329ef+4f7594a38e,g4c90b7bd52+5145c320d2,g58be5f913a+bea990ba40,g635b316a6c+8d6b3a3e56,g67924a670a+bfead8c487,g6ae5381d9b+81bc2a20b4,g93c4d6e787+26b17396bd,g98cecbdb62+ed2cb6d659,g98ffbb4407+81bc2a20b4,g9ddcbc5298+7f7571301f,ga1e77700b3+99e9273977,gae46bcf261+6660c170cc,gb2715bf1a1+17526d298f,gc86a011abf+17526d298f,gcf0d15dbbd+96dd2c2ea9,gdaeeff99f8+0d8dbea60f,gdb4ec4c597+6660c170cc,ge23793e450+96dd2c2ea9,gf041782ebf+171108ac67
LSST Data Management Base Package
Loading...
Searching...
No Matches
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);
442
444
457 virtual void combine(PropertySet const & source);
459
466 virtual void remove(std::string const& name);
467
468protected:
469 /*
470 * Find the property name (possibly hierarchical) and set or replace its
471 * value with the given vector of values. Hook for subclass overrides of
472 * top-level setting.
473 *
474 * @param[in] name Property name to find, possibly hierarchical.
475 * @param[in] vp shared_ptr to vector of values.
476 * @throws InvalidParameterError Hierarchical name uses non-PropertySet.
477 */
478 virtual void _set(std::string const& name, std::shared_ptr<std::vector<std::any> > vp);
479
480 /*
481 * Find the property name (possibly hierarchical) and append or set 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 _add(std::string const& name, std::shared_ptr<std::vector<std::any> > vp);
489
490 // Format a value in human-readable form; called by toString
491 virtual std::string _format(std::string const& name) const;
492
493private:
494
495 typedef std::unordered_map<std::string, std::shared_ptr<std::vector<std::any> > > AnyMap;
496
497 /*
498 * Find the property name (possibly hierarchical).
499 *
500 * @param[in] name Property name to find, possibly hierarchical.
501 * @return unordered_map::iterator to the property or end() if nonexistent.
502 */
503 AnyMap::iterator _find(std::string const& name);
504
505 /*
506 * Find the property name (possibly hierarchical). Const version.
507 *
508 * @param[in] name Property name to find, possibly hierarchical.
509 * @return unordered_map::const_iterator to the property or end().
510 */
511 AnyMap::const_iterator _find(std::string const& name) const;
512
513 /*
514 * Find the property name (possibly hierarchical) and set or replace its
515 * value with the given vector of values.
516 *
517 * @param[in] name Property name to find, possibly hierarchical.
518 * @param[in] vp shared_ptr to vector of values.
519 * @throws InvalidParameterError Hierarchical name uses non-PropertySet.
520 */
521 virtual void _findOrInsert(std::string const& name, std::shared_ptr<std::vector<std::any> > vp);
522 void _cycleCheckPtrVec(std::vector<std::shared_ptr<PropertySet>> const& v, std::string const& name);
523 void _cycleCheckAnyVec(std::vector<std::any> const& v, std::string const& name);
524 void _cycleCheckPtr(std::shared_ptr<PropertySet> const & v, std::string const& name);
525
526 AnyMap _map;
527 bool _flat;
528};
529
530#if defined(__ICC)
531#pragma warning(pop)
532#endif
533
534template <>
535void PropertySet::add<std::shared_ptr<PropertySet>>(
536 std::string const& name,
538);
539
540template <>
541void PropertySet::add<std::shared_ptr<PropertySet>>(
542 std::string const& name,
544);
545
546}
547} // namespace daf
548} // namespace lsst
549
550#endif
table::Key< std::string > name
Definition Amplifier.cc:116
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:927
STL namespace.