lsst.daf.base  13.0-2-g167564e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Public Types | Public Member Functions | Protected 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::Persistable lsst::daf::base::Citizen lsst::daf::base::PropertyList

Public Types

typedef std::shared_ptr
< PropertySet
Ptr
 
typedef std::shared_ptr
< PropertySet const > 
ConstPtr
 
- Public Types inherited from lsst::daf::base::Persistable
typedef std::shared_ptr
< Persistable
Ptr
 
- Public Types inherited from lsst::daf::base::Citizen
enum  { magicSentinel = 0xdeadbeef }
 
typedef unsigned long memId
 Type of the block's ID. More...
 
typedef memId(* memNewCallback )(const memId cid)
 A function used to register a callback. More...
 
typedef memId(* memCallback )(const Citizen *ptr)
 

Public Member Functions

 PropertySet (bool flat=false)
 Constructor. More...
 
virtual ~PropertySet (void)
 Destructor. More...
 
 PropertySet (const PropertySet &)=delete
 
PropertySetoperator= (const PropertySet &)=delete
 
 PropertySet (PropertySet &&)=delete
 
PropertySetoperator= (PropertySet &&)=delete
 
virtual Ptr deepCopy (void) const
 Copy the PropertySet and all of its contents. More...
 
size_t nameCount (bool topLevelOnly=true) const
 Get the number of names in the PropertySet, optionally including those in subproperties. More...
 
std::vector< std::string > names (bool topLevelOnly=true) const
 Get the names in the PropertySet, optionally including those in subproperties. More...
 
std::vector< std::string > paramNames (bool topLevelOnly=true) const
 Get the names of parameters (non-subproperties) in the PropertySet, optionally including those in subproperties. More...
 
std::vector< std::string > propertySetNames (bool topLevelOnly=true) const
 Get the names of subproperties in the PropertySet, optionally including those in subproperties. More...
 
bool exists (std::string const &name) const
 Determine if a name (possibly hierarchical) exists. More...
 
bool isArray (std::string const &name) const
 Determine if a name (possibly hierarchical) has multiple values. More...
 
bool isPropertySetPtr (std::string const &name) const
 Determine if a name (possibly hierarchical) is a subproperty. More...
 
size_t valueCount (std::string const &name) const
 Get number of values for a property name (possibly hierarchical). More...
 
std::type_info const & typeOf (std::string const &name) const
 Get the type of values for a property name (possibly hierarchical). More...
 
template<typename T >
get (std::string const &name) const
 Get the last value for a property name (possibly hierarchical). More...
 
template<typename T >
get (std::string const &name, T const &defaultValue) const
 Get the last value for a property name (possibly hierarchical). More...
 
template<typename T >
std::vector< T > getArray (std::string const &name) const
 
bool getAsBool (std::string const &name) const
 Get the last value for a bool property name (possibly hierarchical). More...
 
int getAsInt (std::string const &name) const
 Get the last value for a bool/char/short/int property name (possibly hierarchical). More...
 
int64_t getAsInt64 (std::string const &name) const
 Get the last value for a bool/char/short/int/int64_t property name (possibly hierarchical). More...
 
double getAsDouble (std::string const &name) const
 Get the last value for any arithmetic property name (possibly hierarchical). More...
 
std::string getAsString (std::string const &name) const
 Get the last value for a string property name (possibly hierarchical). More...
 
PropertySet::Ptr getAsPropertySetPtr (std::string const &name) const
 Get the last value for a subproperty name (possibly hierarchical). More...
 
Persistable::Ptr getAsPersistablePtr (std::string const &name) const
 Get the last value for a Persistable name (possibly hierarchical). More...
 
virtual std::string toString (bool topLevelOnly=false, std::string const &indent="") const
 Generate a string representation of the PropertySet. More...
 
template<typename T >
void set (std::string const &name, T const &value)
 Replace all values for a property name (possibly hierarchical) with a new value. More...
 
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. More...
 
void set (std::string const &name, char const *value)
 Replace all values for a property name (possibly hierarchical) with a string value. More...
 
template<typename T >
void add (std::string const &name, T const &value)
 Appends a single value to the vector of values for a property name (possibly hierarchical). More...
 
template<typename T >
void add (std::string const &name, std::vector< T > const &value)
 Appends a vector of values to the vector of values for a property name (possibly hierarchical). More...
 
void add (std::string const &name, char const *value)
 Appends a char const* value to the vector of values for a property name (possibly hierarchical). More...
 
virtual void copy (std::string const &dest, ConstPtr source, std::string const &name)
 Replaces a single value vector in the destination with one from the source. More...
 
virtual void combine (ConstPtr source)
 Appends all value vectors from the source to their corresponding properties. More...
 
virtual void remove (std::string const &name)
 Removes all values for a property name (possibly hierarchical). More...
 
template<typename T >
vector< T > getArray (string const &name) const
 Get the vector of values for a property name (possibly hierarchical). More...
 
- Public Member Functions inherited from lsst::daf::base::Persistable
 Persistable (void)
 Default constructor. More...
 
virtual ~Persistable (void)
 Destructor. More...
 
template<class Archive >
void serialize (Archive &, unsigned int const)
 Template boost::serialization function for the base class. More...
 
- Public Member Functions inherited from lsst::daf::base::Citizen
 Citizen (const std::type_info &)
 
 Citizen (Citizen const &)
 
 ~Citizen ()
 
Citizenoperator= (Citizen const &)
 
std::string repr () const
 Return a string representation of a Citizen. More...
 
void markPersistent (void)
 Mark a Citizen as persistent and not destroyed until process end. More...
 
memId getId () const
 Return the Citizen's ID. More...
 

Protected Member Functions

virtual void _set (std::string const &name, std::shared_ptr< std::vector< boost::any > > vp)
 Finds the property name (possibly hierarchical) and sets or replaces its value with the given vector of values. More...
 
virtual void _add (std::string const &name, std::shared_ptr< std::vector< boost::any > > vp)
 Finds the property name (possibly hierarchical) and appends or sets its value with the given vector of values. More...
 
virtual std::string _format (std::string const &name) const
 

Additional Inherited Members

- Static Public Member Functions inherited from lsst::daf::base::Citizen
static bool hasBeenCorrupted ()
 Check all allocated blocks for corruption. More...
 
static memId getNextMemId ()
 Return the memId of the next object to be allocated. More...
 
static int init ()
 Called once when the memory system is being initialised. More...
 
static int census (int, memId startingMemId=0)
 How many active Citizens are there? More...
 
static void census (std::ostream &stream, memId startingMemId=0)
 Print a list of all active Citizens to stream, sorted by ID. More...
 
static const std::vector
< const Citizen * > * 
census ()
 Return a (newly allocated) std::vector of active Citizens sorted by ID. More...
 
static memId setNewCallbackId (memId id)
 Call the NewCallback when block is allocated. More...
 
static memId setDeleteCallbackId (memId id)
 Call the current DeleteCallback when block is deleted. More...
 
static memNewCallback setNewCallback (memNewCallback func)
 Set the NewCallback function. More...
 
static memCallback setDeleteCallback (memCallback func)
 Set the DeleteCallback function. More...
 
static memCallback setCorruptionCallback (memCallback func)
 Set the CorruptionCallback function. More...
 

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 82 of file PropertySet.h.

Member Typedef Documentation

typedef std::shared_ptr<PropertySet const> lsst::daf::base::PropertySet::ConstPtr

Definition at line 86 of file PropertySet.h.

Definition at line 85 of file PropertySet.h.

Constructor & Destructor Documentation

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

Constructor.

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

Definition at line 55 of file PropertySet.cc.

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

Destructor.

Definition at line 60 of file PropertySet.cc.

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

Member Function Documentation

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

Finds the property name (possibly hierarchical) and appends or sets its value with the given vector of values.

Parameters
[in]nameProperty name to find, possibly hierarchical.
[in]vpshared_ptr to vector of values.
Exceptions
InvalidParameterErrorHierarchical name uses non-PropertySet.

Definition at line 848 of file PropertySet.cc.

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

Definition at line 507 of file PropertySet.cc.

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

Finds the property name (possibly hierarchical) and sets or replaces its value with the given vector of values.

Hook for subclass overrides of top-level setting.

Parameters
[in]nameProperty name to find, possibly hierarchical.
[in]vpshared_ptr to vector of values.
Exceptions
InvalidParameterErrorHierarchical name uses non-PropertySet.

Definition at line 837 of file PropertySet.cc.

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

Appends 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.

Definition at line 619 of file PropertySet.cc.

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

Appends 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.

Definition at line 660 of file PropertySet.cc.

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

Appends 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.

Definition at line 700 of file PropertySet.cc.

void lsst::daf::base::PropertySet::combine ( ConstPtr  source)
virtual

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

Sets values if a property does not exist.

Parameters
[in]sourcePropertySet::Ptr for the source PropertySet.
Exceptions
TypeErrorType does not match existing values.
InvalidParameterErrorHierarchical name uses non-PropertySet.
Note
May only partially combine the PropertySets if an exception occurs.

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

Definition at line 738 of file PropertySet.cc.

void lsst::daf::base::PropertySet::copy ( std::string const &  dest,
ConstPtr  source,
std::string const &  name 
)
virtual

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

Parameters
[in]destDestination property name.
[in]sourcePropertySet::Ptr for the source PropertySet.
[in]nameProperty name to extract.
Exceptions
TypeErrorType does not match existing values.
InvalidParameterErrorName does not exist in source.
InvalidParameterErrorHierarchical name uses non-PropertySet.

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

Definition at line 713 of file PropertySet.cc.

dafBase::PropertySet::Ptr lsst::daf::base::PropertySet::deepCopy ( void  ) const
virtual

Copy the PropertySet and all of its contents.

Returns
PropertySet::Ptr pointing to the new copy.

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

Definition at line 70 of file PropertySet.cc.

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.

Definition at line 190 of file PropertySet.cc.

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.

Definition at line 246 of file PropertySet.cc.

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).

Returns 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.

Definition at line 271 of file PropertySet.cc.

template<typename T >
std::vector<T> lsst::daf::base::PropertySet::getArray ( std::string const &  name) const
template<typename T >
vector<T> lsst::daf::base::PropertySet::getArray ( 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.

Definition at line 295 of file PropertySet.cc.

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

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

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

Definition at line 321 of file PropertySet.cc.

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.

Definition at line 406 of file PropertySet.cc.

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, but unsigned versions of smaller types are.

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

Definition at line 333 of file PropertySet.cc.

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.

Definition at line 372 of file PropertySet.cc.

dafBase::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.

Definition at line 466 of file PropertySet.cc.

dafBase::PropertySet::Ptr 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::Ptr value.
Exceptions
NotFoundErrorProperty does not exist.
TypeErrorValue is not a PropertySet::Ptr.

Definition at line 455 of file PropertySet.cc.

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

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

Note that properties set with char const* can be retrieved as strings using this method.

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

Definition at line 444 of file PropertySet.cc.

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.

Definition at line 198 of file PropertySet.cc.

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::Ptrs.

Definition at line 207 of file PropertySet.cc.

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

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

The name of the subproperty is counted in that case.

Parameters
[in]topLevelOnlytrue (default) = don't include subproperties.
Returns
Number of names.

Definition at line 97 of file PropertySet.cc.

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

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

The name of the subproperty is included in that case. Hierarchical subproperty names are separated by a period.

Parameters
[in]topLevelOnlytrue (default) = don't include subproperties.
Returns
Vector of names.

Definition at line 117 of file PropertySet.cc.

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

Get the names of parameters (non-subproperties) in the PropertySet, optionally including those in subproperties.

Hierarchical subproperty names are separated by a period.

Parameters
[in]topLevelOnlytrue (default) = don't include subproperties.
Returns
Vector of parameter names.

Definition at line 142 of file PropertySet.cc.

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

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

Hierarchical subproperty names are separated by a period.

Parameters
[in]topLevelOnlytrue (default) = don't include subproperties.
Returns
Vector of subproperty names.

Definition at line 168 of file PropertySet.cc.

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

Removes 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.

Definition at line 754 of file PropertySet.cc.

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 value.

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

Definition at line 581 of file PropertySet.cc.

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.

Definition at line 594 of file PropertySet.cc.

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 ).

Definition at line 607 of file PropertySet.cc.

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.

Definition at line 476 of file PropertySet.cc.

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

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

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

Definition at line 227 of file PropertySet.cc.

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

Get 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.

Definition at line 216 of file PropertySet.cc.


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