LSST Applications g063fba187b+66a50001ff,g0f08755f38+1a22dc2551,g1653933729+a8ce1bb630,g168dd56ebc+a8ce1bb630,g217e2c1bcf+12e87a5bd8,g246886dfd9+466c7b6c06,g28da252d5a+858b171e04,g2bbee38e9b+404b60ec9b,g2bc492864f+404b60ec9b,g3156d2b45e+6e55a43351,g347aa1857d+404b60ec9b,g35bb328faa+a8ce1bb630,g3a166c0a6a+404b60ec9b,g3e281a1b8c+c5dd892a6c,g414038480c+6b9177ef31,g41af890bb2+70bea58702,g599934f4f4+b8c5400ca5,g781aacb6e4+a8ce1bb630,g7af13505b9+b5b9cefdb8,g80478fca09+c2997882f3,g82479be7b0+8974e6af0f,g858d7b2824+1a22dc2551,g89c8672015+f4add4ffd5,g8f1c07a47a+de51c9b0a5,g9125e01d80+a8ce1bb630,ga5288a1d22+b66f8cf76b,gb58c049af0+d64f4d3760,gc28159a63d+404b60ec9b,gcab2d0539d+66cf1de5d4,gcf0d15dbbd+12cb7e2563,gda6a2b7d83+12cb7e2563,gdaeeff99f8+1711a396fd,ge79ae78c31+404b60ec9b,gef2f8181fd+414189b318,gf0baf85859+c1f95f4921,gf0c06eb49c+1a22dc2551,gfa517265be+1a22dc2551,gfa999e8aa5+17cd334064,v28.0.0.rc2
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | List of all members
lsst::daf::base::PropertySet Class Reference

Class for storing generic metadata. More...

#include <PropertySet.h>

Inheritance diagram for lsst::daf::base::PropertySet:
lsst::daf::base::PropertyList

Public Types

typedef std::shared_ptr< PropertySetPtr
 
typedef std::shared_ptr< PropertySet const > ConstPtr
 

Public Member Functions

 PropertySet (bool flat=false)
 Construct an empty PropertySet.
 
virtual ~PropertySet () noexcept
 Destructor.
 
 PropertySet (const PropertySet &)=delete
 
PropertySetoperator= (const PropertySet &)=delete
 
 PropertySet (PropertySet &&)=delete
 
PropertySetoperator= (PropertySet &&)=delete
 
virtual std::shared_ptr< PropertySetdeepCopy () const
 Make a deep copy of the PropertySet and all of its contents.
 
size_t nameCount (bool topLevelOnly=true) const
 Get the number of names in the PropertySet, optionally including those in subproperties.
 
std::vector< std::stringnames (bool topLevelOnly=true) const
 Get the names in the PropertySet, optionally including those in subproperties.
 
std::vector< std::stringparamNames (bool topLevelOnly=true) const
 A variant of names that excludes the names of subproperties.
 
std::vector< std::stringpropertySetNames (bool topLevelOnly=true) const
 A variant of names that only returns the names of subproperties.
 
bool exists (std::string const &name) const
 Determine if a name (possibly hierarchical) exists.
 
bool isArray (std::string const &name) const
 Determine if a name (possibly hierarchical) has multiple values.
 
bool isPropertySetPtr (std::string const &name) const
 Determine if a name (possibly hierarchical) is a subproperty.
 
bool isUndefined (std::string const &name) const
 Determine if a name (possibly hierarchical) has a defined value.
 
size_t valueCount () const
 Get the number of values in the entire PropertySet, counting each element of a vector.
 
size_t valueCount (std::string const &name) const
 Get the number of values for a property name (possibly hierarchical).
 
std::type_info const & typeOf (std::string const &name) const
 Get the type of values for a property name (possibly hierarchical).
 
template<typename T >
get (std::string const &name) const
 Get the last value for a property name (possibly hierarchical).
 
template<typename T >
get (std::string const &name, T const &defaultValue) const
 Get the last value for a property name (possibly hierarchical); return the provided defaultValue if the property does not exist.
 
template<typename T >
std::vector< T > getArray (std::string const &name) const
 Get the vector of values for a property name (possibly hierarchical).
 
bool getAsBool (std::string const &name) const
 Get the last value for a bool property name (possibly hierarchical).
 
int getAsInt (std::string const &name) const
 Get the last value for a bool/char/short/int property name (possibly hierarchical).
 
int64_t getAsInt64 (std::string const &name) const
 Get the last value for a bool/char/short/int/int64_t property name (possibly hierarchical).
 
uint64_t getAsUInt64 (std::string const &name) const
 Get the last value for an bool/char/short/int/int64_t property name (possibly hierarchical).
 
double getAsDouble (std::string const &name) const
 Get the last value for any arithmetic property name (possibly hierarchical).
 
std::string getAsString (std::string const &name) const
 Get the last value for a string property name (possibly hierarchical).
 
std::shared_ptr< PropertySetgetAsPropertySetPtr (std::string const &name) const
 Get the last value for a subproperty name (possibly hierarchical).
 
Persistable::Ptr getAsPersistablePtr (std::string const &name) const
 Get the last value for a Persistable name (possibly hierarchical).
 
virtual std::string toString (bool topLevelOnly=false, std::string const &indent="") const
 Generate a string representation of the PropertySet.
 
template<typename T >
void set (std::string const &name, T const &value)
 Replace all values for a property name (possibly hierarchical) with a new scalar value.
 
template<typename T >
void set (std::string const &name, std::vector< T > const &value)
 Replace all values for a property name (possibly hierarchical) with a vector of new values.
 
void set (std::string const &name, char const *value)
 Replace all values for a property name (possibly hierarchical) with a string value.
 
template<typename T >
void add (std::string const &name, T const &value)
 Append a single value to the vector of values for a property name (possibly hierarchical).
 
template<typename T >
void add (std::string const &name, std::vector< T > const &value)
 Append a vector of values to the vector of values for a property name (possibly hierarchical).
 
void add (std::string const &name, char const *value)
 Append a char const* value to the vector of values for a property name (possibly hierarchical).
 
virtual void copy (std::string const &dest, PropertySet const &source, std::string const &name, bool asScalar=false)
 Replace a single value vector in the destination with one from the source.
 
virtual void combine (PropertySet const &source)
 Append all value vectors from the source to their corresponding properties.
 
virtual void remove (std::string const &name)
 Remove all values for a property name (possibly hierarchical).
 

Static Public Member Functions

template<typename T >
static std::type_info const & typeOfT ()
 Get type info for the specified class.
 

Protected Member Functions

virtual void _set (std::string const &name, std::shared_ptr< std::vector< std::any > > vp)
 
virtual void _add (std::string const &name, std::shared_ptr< std::vector< std::any > > vp)
 
virtual std::string _format (std::string const &name) const
 

Private Member Functions

virtual void _findOrInsert (std::string const &name, std::shared_ptr< std::vector< std::any > > vp)
 

Detailed Description

Class for storing generic metadata.

This class stores key/value pairs, like a Python dictionary but in C++. Keys are always C++ strings. Values can be C++ primitive data types, strings, lsst::daf::base::DateTime objects, and lsst::daf::base::Persistable subclasses (although the latter is currently discouraged). Values can also be vectors of these items.

PropertySets are hierarchical; values within a PropertySet that is contained within another PropertySet can be addressed using dotted paths ("a.b.c"). If "flat=true" is specified to the constructor, the PropertySet still takes dotted paths but is not actually hierarchical in structure. This is used to support PropertyList.

Definition at line 66 of file PropertySet.h.

Member Typedef Documentation

◆ ConstPtr

Definition at line 70 of file PropertySet.h.

◆ Ptr

Definition at line 69 of file PropertySet.h.

Constructor & Destructor Documentation

◆ PropertySet() [1/3]

lsst::daf::base::PropertySet::PropertySet ( bool flat = false)
explicit

Construct an empty PropertySet.

Parameters
[in]flatfalse (default) = flatten hierarchy by ignoring dots in names

◆ ~PropertySet()

virtual lsst::daf::base::PropertySet::~PropertySet ( )
virtualnoexcept

Destructor.

◆ PropertySet() [2/3]

lsst::daf::base::PropertySet::PropertySet ( const PropertySet & )
delete

◆ PropertySet() [3/3]

lsst::daf::base::PropertySet::PropertySet ( PropertySet && )
delete

Member Function Documentation

◆ _add()

virtual void lsst::daf::base::PropertySet::_add ( std::string const & name,
std::shared_ptr< std::vector< std::any > > vp )
protectedvirtual

◆ _findOrInsert()

virtual void lsst::daf::base::PropertySet::_findOrInsert ( std::string const & name,
std::shared_ptr< std::vector< std::any > > vp )
privatevirtual

◆ _format()

virtual std::string lsst::daf::base::PropertySet::_format ( std::string const & name) const
protectedvirtual

◆ _set()

virtual void lsst::daf::base::PropertySet::_set ( std::string const & name,
std::shared_ptr< std::vector< std::any > > vp )
protectedvirtual

Reimplemented in lsst::daf::base::PropertyList.

◆ add() [1/3]

void lsst::daf::base::PropertySet::add ( std::string const & name,
char const * value )

Append a char const* value to the vector of values for a property name (possibly hierarchical).

Sets the value if the property does not exist.

Parameters
[in]nameProperty name to append to, possibly hierarchical.
[in]valueCharacter string value to append.
Exceptions
TypeErrorType does not match existing values.
InvalidParameterErrorHierarchical name uses non-PropertySet.

◆ add() [2/3]

template<typename T >
void lsst::daf::base::PropertySet::add ( std::string const & name,
std::vector< T > const & value )

Append a vector of values to the vector of values for a property name (possibly hierarchical).

Sets the values if the property does not exist.

Parameters
[in]nameProperty name to append to, possibly hierarchical.
[in]valueVector of values to append.
Exceptions
TypeErrorType does not match existing values.
InvalidParameterErrorHierarchical name uses non-PropertySet.
Note
May only partially add the vector if an exception occurs.

◆ add() [3/3]

template<typename T >
void lsst::daf::base::PropertySet::add ( std::string const & name,
T const & value )

Append a single value to the vector of values for a property name (possibly hierarchical).

Sets the value if the property does not exist.

Parameters
[in]nameProperty name to append to, possibly hierarchical.
[in]valueValue to append.
Exceptions
TypeErrorType does not match existing values.
InvalidParameterErrorHierarchical name uses non-PropertySet.

If value is a PropertySet, the default implementation will allow it to be retreived later via get (or other methods) using the given name, and the result will be the same shared_ptr passed in, but this is not guaranteed to be the behavior for all derived classes, which may flatten out PropertySet values instead.

◆ combine()

virtual void lsst::daf::base::PropertySet::combine ( PropertySet const & source)
virtual

Append all value vectors from the source to their corresponding properties.

Sets values if a property does not exist.

If a property already exists then the types of the existing value(s) must match the type of the value(s) in source.

Parameters
[in]sourcePropertySet to extract values from.
Exceptions
TypeErrorType does not match existing values for an item.
InvalidParameterErrorHierarchical name uses non-PropertySet.
Warning
May only partially combine the PropertySets if an exception occurs.

Reimplemented in lsst::daf::base::PropertyList.

◆ copy()

virtual void lsst::daf::base::PropertySet::copy ( std::string const & dest,
PropertySet const & source,
std::string const & name,
bool asScalar = false )
virtual

Replace a single value vector in the destination with one from the source.

Parameters
[in]destDestination property name.
[in]sourcePropertySet to extract values from.
[in]nameProperty name to extract.
[in]asScalarIf true copy the item as a scalar by ignoring all but the last value (which is the value returned by get<T>(name))
Exceptions
TypeErrorType does not match existing values.
InvalidParameterErrorName does not exist in source.
InvalidParameterErrorHierarchical name uses non-PropertySet.

Reimplemented in lsst::daf::base::PropertyList.

◆ deepCopy()

virtual std::shared_ptr< PropertySet > lsst::daf::base::PropertySet::deepCopy ( ) const
virtual

Make a deep copy of the PropertySet and all of its contents.

Returns
PropertySet pointing to the new copy.

Reimplemented in lsst::daf::base::PropertyList.

◆ exists()

bool lsst::daf::base::PropertySet::exists ( std::string const & name) const

Determine if a name (possibly hierarchical) exists.

Parameters
[in]nameProperty name to examine, possibly hierarchical.
Returns
true if property exists.

◆ get() [1/2]

template<typename T >
T lsst::daf::base::PropertySet::get ( std::string const & name) const

Get the last value for a property name (possibly hierarchical).

Note that the type must be explicitly specified for this template:

int i = propertySet.get<int>("foo")
Parameters
[in]nameProperty name to examine, possibly hierarchical.
Returns
Last value set or added.
Exceptions
NotFoundErrorProperty does not exist.
TypeErrorValue does not match desired type.

◆ get() [2/2]

template<typename T >
T lsst::daf::base::PropertySet::get ( std::string const & name,
T const & defaultValue ) const

Get the last value for a property name (possibly hierarchical); return the provided defaultValue if the property does not exist.

Note that the type must be explicitly specified for this template:

int i = propertySet.get<int>("foo", 42)
Parameters
[in]nameProperty name to examine, possibly hierarchical.
[in]defaultValueDefault value to return if property does not exist.
Returns
Last value set or added.
Exceptions
TypeErrorValue does not match desired type.

◆ getArray()

template<typename T >
std::vector< T > lsst::daf::base::PropertySet::getArray ( std::string const & name) const

Get the vector of values for a property name (possibly hierarchical).

Note that the type must be explicitly specified for this template:

vector<int> v = propertySet.getArray<int>("foo")
Parameters
[in]nameProperty name to examine, possibly hierarchical.
Returns
Vector of values.
Exceptions
NotFoundErrorProperty does not exist.
TypeErrorValue does not match desired type.

◆ getAsBool()

bool lsst::daf::base::PropertySet::getAsBool ( std::string const & name) const

Get the last value for a bool property name (possibly hierarchical).

Only bool properties are supported.

Parameters
[in]nameProperty name to examine, possibly hierarchical.
Returns
Value as a bool.
Exceptions
NotFoundErrorProperty does not exist.
TypeErrorValue is not a bool.

◆ getAsDouble()

double lsst::daf::base::PropertySet::getAsDouble ( std::string const & name) const

Get the last value for any arithmetic property name (possibly hierarchical).

Parameters
[in]nameProperty name to examine, possibly hierarchical.
Returns
Value as a double.
Exceptions
NotFoundErrorProperty does not exist.
TypeErrorValue cannot be converted to double.

◆ getAsInt()

int lsst::daf::base::PropertySet::getAsInt ( std::string const & name) const

Get the last value for a bool/char/short/int property name (possibly hierarchical).

Unsigned int properties are not acceptable.

Parameters
[in]nameProperty name to examine, possibly hierarchical.
Returns
Value as an int.
Exceptions
NotFoundErrorProperty does not exist.
TypeErrorValue cannot be converted to int.

◆ getAsInt64()

int64_t lsst::daf::base::PropertySet::getAsInt64 ( std::string const & name) const

Get the last value for a bool/char/short/int/int64_t property name (possibly hierarchical).

Unsigned int64_t properties are not acceptable, but unsigned versions of smaller types are, except possibly unsigned long, depending on compiler.

Parameters
[in]nameProperty name to examine, possibly hierarchical.
Returns
Value as an int64_t.
Exceptions
NotFoundErrorProperty does not exist.
TypeErrorValue cannot be converted to int64_t.

◆ getAsPersistablePtr()

Persistable::Ptr lsst::daf::base::PropertySet::getAsPersistablePtr ( std::string const & name) const

Get the last value for a Persistable name (possibly hierarchical).

Parameters
[in]nameProperty name to examine, possibly hierarchical.
Returns
Persistable::Ptr value.
Exceptions
NotFoundErrorProperty does not exist.
TypeErrorValue is not a Persistable::Ptr.

◆ getAsPropertySetPtr()

std::shared_ptr< PropertySet > lsst::daf::base::PropertySet::getAsPropertySetPtr ( std::string const & name) const

Get the last value for a subproperty name (possibly hierarchical).

Parameters
[in]nameProperty name to examine, possibly hierarchical.
Returns
PropertySet value.
Exceptions
NotFoundErrorProperty does not exist.
TypeErrorValue is not a PropertySet.

◆ getAsString()

std::string lsst::daf::base::PropertySet::getAsString ( std::string const & name) const

Get the last value for a string property name (possibly hierarchical).

Only strings values are supported, though this does include properties set with char const*.

Parameters
[in]nameProperty name to examine, possibly hierarchical.
Returns
String value.
Exceptions
NotFoundErrorProperty does not exist.
TypeErrorValue is not a string.

◆ getAsUInt64()

uint64_t lsst::daf::base::PropertySet::getAsUInt64 ( std::string const & name) const

Get the last value for an bool/char/short/int/int64_t property name (possibly hierarchical).

Parameters
[in]nameProperty name to examine, possibly hierarchical.
Returns
Value as an uint64_t.
Exceptions
NotFoundErrorProperty does not exist.
TypeErrorValue cannot be converted to uint64_t.

◆ isArray()

bool lsst::daf::base::PropertySet::isArray ( std::string const & name) const

Determine if a name (possibly hierarchical) has multiple values.

Parameters
[in]nameProperty name to examine, possibly hierarchical.
Returns
true if property exists and has more than one value.

◆ isPropertySetPtr()

bool lsst::daf::base::PropertySet::isPropertySetPtr ( std::string const & name) const

Determine if a name (possibly hierarchical) is a subproperty.

Parameters
[in]nameProperty name to examine, possibly hierarchical.
Returns
true if property exists and its values are PropertySet:.

◆ isUndefined()

bool lsst::daf::base::PropertySet::isUndefined ( std::string const & name) const

Determine if a name (possibly hierarchical) has a defined value.

Parameters
[in]nameProperty name to examine, possibly hierarchical.
Returns
true if property exists and its values are undefined.

◆ nameCount()

size_t lsst::daf::base::PropertySet::nameCount ( bool topLevelOnly = true) const

Get the number of names in the PropertySet, optionally including those in subproperties.

Parameters
[in]topLevelOnlyIf true (default) omit names from subproperties and names of subproperties.
Returns
Number of names.

◆ names()

std::vector< std::string > lsst::daf::base::PropertySet::names ( bool topLevelOnly = true) const

Get the names in the PropertySet, optionally including those in subproperties.

Parameters
[in]topLevelOnlyIf true (default) omit names from subproperties and names of subproperties. If false subproperty names are separated by a dot, e.g. "subname.subitem1"
Returns
Vector of names.

◆ operator=() [1/2]

PropertySet & lsst::daf::base::PropertySet::operator= ( const PropertySet & )
delete

◆ operator=() [2/2]

PropertySet & lsst::daf::base::PropertySet::operator= ( PropertySet && )
delete

◆ paramNames()

std::vector< std::string > lsst::daf::base::PropertySet::paramNames ( bool topLevelOnly = true) const

A variant of names that excludes the names of subproperties.

◆ propertySetNames()

std::vector< std::string > lsst::daf::base::PropertySet::propertySetNames ( bool topLevelOnly = true) const

A variant of names that only returns the names of subproperties.

◆ remove()

virtual void lsst::daf::base::PropertySet::remove ( std::string const & name)
virtual

Remove all values for a property name (possibly hierarchical).

Does nothing if the property does not exist.

Parameters
[in]nameProperty name to remove, possibly hierarchical.

Reimplemented in lsst::daf::base::PropertyList.

◆ set() [1/3]

void lsst::daf::base::PropertySet::set ( std::string const & name,
char const * value )

Replace all values for a property name (possibly hierarchical) with a string value.

Parameters
[in]nameProperty name to set, possibly hierarchical.
[in]valueCharacter string (converted to std::string ).

◆ set() [2/3]

template<typename T >
void lsst::daf::base::PropertySet::set ( std::string const & name,
std::vector< T > const & value )

Replace all values for a property name (possibly hierarchical) with a vector of new values.

Parameters
[in]nameProperty name to set, possibly hierarchical.
[in]valueVector of values to set.
Exceptions
InvalidParameterErrorHierarchical name uses non-PropertySet.

◆ set() [3/3]

template<typename T >
void lsst::daf::base::PropertySet::set ( std::string const & name,
T const & value )

Replace all values for a property name (possibly hierarchical) with a new scalar value.

Parameters
[in]nameProperty name to set, possibly hierarchical.
[in]valueValue to set.
Exceptions
InvalidParameterErrorHierarchical name uses non-PropertySet.

If value is a PropertySet, the default implementation will allow it to be retreived later via get (or other methods) using the given name, and the result will be the same shared_ptr passed in, but this is not guaranteed to be the behavior for all derived classes, which may flatten out PropertySet values instead.

◆ toString()

virtual std::string lsst::daf::base::PropertySet::toString ( bool topLevelOnly = false,
std::string const & indent = "" ) const
virtual

Generate a string representation of the PropertySet.

Use this for debugging, not for serialization/persistence.

Parameters
[in]topLevelOnlyfalse (default) = do include subproperties.
[in]indentString to indent lines by (default none).
Returns
String representation of the PropertySet.

Reimplemented in lsst::daf::base::PropertyList.

◆ typeOf()

std::type_info const & lsst::daf::base::PropertySet::typeOf ( std::string const & name) const

Get the type of values for a property name (possibly hierarchical).

If the value is an array this returns the type of the elements.

Parameters
[in]nameProperty name to examine, possibly hierarchical.
Returns
Type of values for that property.
Exceptions
NotFoundErrorProperty does not exist.

◆ typeOfT()

template<typename T >
static std::type_info const & lsst::daf::base::PropertySet::typeOfT ( )
static

Get type info for the specified class.

◆ valueCount() [1/2]

size_t lsst::daf::base::PropertySet::valueCount ( ) const

Get the number of values in the entire PropertySet, counting each element of a vector.

Returns
Number of values.

◆ valueCount() [2/2]

size_t lsst::daf::base::PropertySet::valueCount ( std::string const & name) const

Get the number of values for a property name (possibly hierarchical).

Parameters
[in]nameProperty name to examine, possibly hierarchical.
Returns
Number of values for that property. 0 if it doesn't exist.

The documentation for this class was generated from the following file: