44 #include "lsst/pex/exceptions/Runtime.h"
47 namespace pexExcept = lsst::pex::exceptions;
76 n->_comments = _comments;
92 return PropertySet::get<T>(name);
104 template <
typename T>
106 return PropertySet::get<T>(name, defaultValue);
117 template <
typename T>
119 return PropertySet::getArray<T>(name);
129 std::string
const& name)
const {
130 return _comments.find(name)->second;
134 std::vector<std::string> v;
135 for (std::list<std::string>::const_iterator i = _order.begin();
136 i != _order.end(); ++i) {
142 std::list<std::string>::const_iterator
144 return _order.begin();
147 std::list<std::string>::const_iterator
159 std::string
const& indent)
const {
161 for (std::list<std::string>::const_iterator i = _order.begin();
162 i != _order.end(); ++i) {
164 std::string
const& comment = _comments.find(*i)->second;
165 if (comment.size()) {
166 s <<
"// " << comment << std::endl;
186 template <
typename T>
188 std::string
const& name, T
const& value) {
196 _comments.erase(name);
198 vector<string>
names = value->paramNames(
false);
199 for (vector<string>::const_iterator i = names.begin();
200 i != names.end(); ++i) {
202 _commentOrderFix(name +
"." + *i, pl->getComment(*i));
214 std::string
const& name,
char const* value) {
215 set(name,
string(value));
224 template <
typename T>
226 std::string
const& name, vector<T>
const& value) {
237 template <
typename T>
239 std::string
const& name, T
const& value) {
252 std::string
const& name,
char const* value) {
253 add(name,
string(value));
265 template <
typename T>
267 std::string
const& name, vector<T>
const& value) {
282 template <
typename T>
284 std::string
const& name, T
const& value,
285 std::string
const& comment) {
287 _commentOrderFix(name, comment);
298 std::string
const& name,
char const* value,
299 std::string
const& comment) {
300 set(name,
string(value), comment);
310 template <
typename T>
312 std::string
const& name, vector<T>
const& value,
313 std::string
const& comment) {
315 _commentOrderFix(name, comment);
326 template <
typename T>
328 std::string
const& name, T
const& value,
329 std::string
const& comment) {
331 _commentOrderFix(name, comment);
345 std::string
const& name,
char const* value,
346 std::string
const& comment) {
347 add(name,
string(value), comment);
360 template <
typename T>
362 std::string
const& name, vector<T>
const& value,
363 std::string
const& comment) {
365 _commentOrderFix(name, comment);
383 std::string
const& name) {
389 _comments[name] = pl->_comments.find(name)->second;
405 std::list<std::string> newOrder;
408 for (std::list<std::string>::const_iterator i = pl->begin();
409 i != pl->end(); ++i) {
410 bool present = _comments.find(*i) != _comments.end();
412 newOrder.push_back(*i);
419 for (std::list<std::string>::const_iterator i = pl->begin();
420 i != pl->end(); ++i) {
421 _comments[*i] = pl->_comments.find(*i)->second;
432 _comments.erase(name);
440 void PropertyList::_set(std::string
const& name,
441 std::shared_ptr< std::vector<boost::any> > vp) {
443 if (_comments.find(name) == _comments.end()) {
444 _comments.insert(std::make_pair(name, std::string()));
445 _order.push_back(name);
449 void PropertyList::_moveToEnd(std::string
const& name) {
451 _order.push_back(name);
454 void PropertyList::_commentOrderFix(
455 std::string
const& name, std::string
const& comment) {
456 _comments[name] = comment;
466 #define INSTANTIATE(t) \
467 template t PropertyList::get<t>(string const& name) const; \
468 template t PropertyList::get<t>(string const& name, t const& defaultValue) const; \
469 template vector<t> PropertyList::getArray<t>(string const& name) const; \
470 template void PropertyList::set<t>(string const& name, t const& value); \
471 template void PropertyList::set<t>(string const& name, vector<t> const& value); \
472 template void PropertyList::add<t>(string const& name, t const& value); \
473 template void PropertyList::add<t>(string const& name, vector<t> const& value); \
474 template void PropertyList::set<t>(string const& name, t const& value, string const& comment); \
475 template void PropertyList::set<t>(string const& name, vector<t> const& value, string const& comment); \
476 template void PropertyList::add<t>(string const& name, t const& value, string const& comment); \
477 template void PropertyList::add<t>(string const& name, vector<t> const& value, string const& comment); \
478 template void PropertyList::set<t>(string const& name, t const& value, char const* comment); \
479 template void PropertyList::set<t>(string const& name, vector<t> const& value, char const* comment); \
480 template void PropertyList::add<t>(string const& name, t const& value, char const* comment); \
481 template void PropertyList::add<t>(string const& name, vector<t> const& value, char const* comment);
485 INSTANTIATE(
signed char)
486 INSTANTIATE(
unsigned char)
488 INSTANTIATE(
unsigned short)
490 INSTANTIATE(
unsigned int)
492 INSTANTIATE(
unsigned long)
493 INSTANTIATE(
long long)
494 INSTANTIATE(
unsigned long long)
498 INSTANTIATE(Persistable::Ptr)
499 INSTANTIATE(DateTime)
std::shared_ptr< PropertySet > Ptr
std::string const & getComment(std::string const &name) const
Get the comment for a string property name (possibly hierarchical).
std::vector< T > getArray(std::string const &name) const
virtual void remove(std::string const &name)
Removes all values for a property name (possibly hierarchical).
Class for storing ordered metadata with comments.
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.
virtual void combine(PropertySet::ConstPtr source)
Appends all value vectors from the source to their corresponding properties.
Interface for PropertyList class.
T get(std::string const &name) const
Get the last value for a property name (possibly hierarchical).
void set(std::string const &name, T const &value)
Replace all values for a property name (possibly hierarchical) with a new value.
virtual void copy(std::string const &dest, PropertySet::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
std::list< std::string >::const_iterator begin(void) const
PropertyList(void)
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.
virtual void remove(std::string const &name)
Removes all values for a property name (possibly hierarchical).
std::shared_ptr< PropertyList const > ConstPtr
virtual void combine(ConstPtr source)
Appends all value vectors from the source to their corresponding properties.
void add(std::string const &name, T const &value)
Appends a single value to the vector of values for a property name (possibly hierarchical).
virtual std::string _format(std::string const &name) const
virtual ~PropertyList(void)
Destructor.
std::vector< std::string > getOrderedNames(void) const
Interface for DateTime class.
std::list< std::string >::const_iterator end(void) const
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 ...
virtual std::string toString(bool topLevelOnly=false, std::string const &indent="") const
Generate a string representation of the PropertyList.
Class for storing generic metadata.
virtual Ptr deepCopy(void) const
Copy the PropertySet and all of its contents.
std::shared_ptr< Persistable > Ptr
void add(std::string const &name, T const &value)
Appends a single value to the vector of values for a property name (possibly hierarchical).
virtual PropertySet::Ptr deepCopy(void) const
Copy the PropertyList and all of its contents.