25 #ifndef LSST_DAF_BASE_PROPERTYSET
26 #define LSST_DAF_BASE_PROPERTYSET
58 #include <unordered_map>
61 #include "boost/any.hpp"
65 #include "lsst/pex/exceptions.h"
70 namespace persistence {
71 class PropertySetFormatter;
78 #pragma warning (push)
79 #pragma warning (disable: 444)
85 typedef std::shared_ptr<PropertySet>
Ptr;
86 typedef std::shared_ptr<PropertySet const>
ConstPtr;
105 size_t nameCount(
bool topLevelOnly =
true)
const;
106 std::vector<std::string>
names(
bool topLevelOnly =
true)
const;
107 std::vector<std::string>
paramNames(
bool topLevelOnly =
true)
const;
110 bool exists(std::string
const& name)
const;
111 bool isArray(std::string
const& name)
const;
114 size_t valueCount(std::string
const& name)
const;
115 std::type_info
const&
typeOf(std::string
const& name)
const;
120 template <
typename T> T
get(std::string
const& name)
const;
123 template <
typename T>
124 T
get(std::string
const& name, T
const& defaultValue)
const;
126 template <
typename T>
127 std::vector<T>
getArray(std::string
const& name)
const;
130 bool getAsBool(std::string
const& name)
const;
131 int getAsInt(std::string
const& name)
const;
132 int64_t
getAsInt64(std::string
const& name)
const;
134 std::string
getAsString(std::string
const& name)
const;
139 virtual std::string
toString(
bool topLevelOnly =
false,
140 std::string
const& indent =
"")
const;
143 template <
typename T>
void set(std::string
const& name, T
const& value);
144 template <
typename T>
void set(std::string
const& name,
145 std::vector<T>
const& value);
146 void set(std::string
const& name,
char const* value);
147 template <
typename T>
void add(std::string
const& name, T
const& value);
148 template <
typename T>
void add(std::string
const& name,
149 std::vector<T>
const& value);
150 void add(std::string
const& name,
char const* value);
152 virtual void copy(std::string
const& dest,
ConstPtr source,
153 std::string
const& name);
158 virtual void remove(std::string
const& name);
161 virtual void _set(std::string
const& name,
162 std::shared_ptr< std::vector<boost::any> > vp);
163 virtual void _add(std::string
const& name,
164 std::shared_ptr< std::vector<boost::any> > vp);
165 virtual std::string
_format(std::string
const& name)
const;
170 typedef std::unordered_map<std::
string,
171 std::shared_ptr< std::vector<boost::any> > > AnyMap;
173 AnyMap::iterator _find(std::
string const& name);
174 AnyMap::const_iterator _find(std::
string const& name) const;
175 virtual
void _findOrInsert(std::
string const& name,
176 std::shared_ptr< std::vector<boost::any> > vp);
177 void _cycleCheckPtrVec(std::vector<
Ptr> const& v, std::
string const& name);
178 void _cycleCheckAnyVec(std::vector<boost::any> const& v,
179 std::
string const& name);
180 void _cycleCheckPtr(
Ptr const& v, std::
string const& name);
187 #pragma warning (pop)
190 template<>
void PropertySet::add<PropertySet::Ptr>(
191 std::string
const& name,
Ptr const& value);
192 template<>
void PropertySet::add<PropertySet::Ptr>(
193 std::string
const& name, std::vector<Ptr>
const& value);
bool getAsBool(std::string const &name) const
Get the last value for a bool property name (possibly hierarchical).
std::vector< std::string > paramNames(bool topLevelOnly=true) const
Get the names of parameters (non-subproperties) in the PropertySet, optionally including those in sub...
std::shared_ptr< PropertySet > Ptr
int64_t getAsInt64(std::string const &name) const
Get the last value for a bool/char/short/int/int64_t property name (possibly hierarchical).
Persistable::Ptr getAsPersistablePtr(std::string const &name) const
Get the last value for a Persistable name (possibly hierarchical).
bool isPropertySetPtr(std::string const &name) const
Determine if a name (possibly hierarchical) is a subproperty.
size_t nameCount(bool topLevelOnly=true) const
Get the number of names in the PropertySet, optionally including those in subproperties.
std::vector< std::string > propertySetNames(bool topLevelOnly=true) const
Get the names of subproperties in the PropertySet, optionally including those in subproperties.
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 o...
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.
std::shared_ptr< PropertySet const > ConstPtr
PropertySet & operator=(const PropertySet &)=delete
PropertySet(bool flat=false)
Constructor.
void set(std::string const &name, T const &value)
Replace all values for a property name (possibly hierarchical) with a new value.
std::vector< std::string > names(bool topLevelOnly=true) const
Get the names in the PropertySet, optionally including those in subproperties.
size_t valueCount(std::string const &name) const
Get number of values for a property name (possibly hierarchical).
bool isArray(std::string const &name) const
Determine if a name (possibly hierarchical) has multiple values.
int getAsInt(std::string const &name) const
Get the last value for a bool/char/short/int property name (possibly hierarchical).
virtual void combine(ConstPtr source)
Appends all value vectors from the source to their corresponding properties.
Interface for Persistable base class.
virtual std::string _format(std::string const &name) const
PropertySet::Ptr getAsPropertySetPtr(std::string const &name) const
Get the last value for a subproperty name (possibly hierarchical).
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 ...
std::type_info const & typeOf(std::string const &name) const
Get the type of values for a property name (possibly hierarchical).
double getAsDouble(std::string const &name) const
Get the last value for any arithmetic property name (possibly hierarchical).
Class for storing generic metadata.
virtual Ptr deepCopy(void) const
Copy the PropertySet and all of its contents.
virtual std::string toString(bool topLevelOnly=false, std::string const &indent="") const
Generate a string representation of the PropertySet.
std::string getAsString(std::string const &name) const
Get the last value for a string property name (possibly hierarchical).
#define LSST_PERSIST_FORMATTER(formatter...)
Macro used to connect the persistable class with the Formatter and boost::serialization.
std::shared_ptr< Persistable > Ptr
virtual ~PropertySet(void)
Destructor.
Base class for all persistable classes.
Citizen is a class that should be among all LSST classes base classes, and handles basic memory manag...
void add(std::string const &name, T const &value)
Appends a single value to the vector of values for a property name (possibly hierarchical).
std::vector< T > getArray(std::string const &name) const
bool exists(std::string const &name) const
Determine if a name (possibly hierarchical) exists.