60PropertySet::~PropertySet() noexcept = default;
66std::shared_ptr<PropertySet> PropertySet::deepCopy()
const {
67 auto n = std::make_shared<PropertySet>(_flat);
68 for (
auto const& elt : _map) {
70 for (
auto const& j : *elt.second) {
71 auto p = std::any_cast<std::shared_ptr<PropertySet>>(j);
75 n->add(elt.first, p->deepCopy());
80 n->_map[elt.first] = vp;
86size_t PropertySet::nameCount(
bool topLevelOnly)
const {
88 for (
auto const& elt : _map) {
91 auto p = std::any_cast<std::shared_ptr<PropertySet>>(elt.second->back());
93 n += p->nameCount(
false);
102 for (
auto const& elt : _map) {
105 auto p = std::any_cast<std::shared_ptr<PropertySet>>(elt.second->back());
108 for (
auto const& k :
w) {
119 for (
auto const& elt : _map) {
121 auto p = std::any_cast<std::shared_ptr<PropertySet>>(elt.second->back());
122 if (p.get() != 0 && !topLevelOnly) {
124 for (
auto const& k :
w) {
137 for (
auto const& elt : _map) {
140 auto p = std::any_cast<std::shared_ptr<PropertySet>>(elt.second->back());
141 if (p.get() != 0 && !topLevelOnly) {
143 for (
auto const& k :
w) {
155 auto const i = _find(
name);
156 return i != _map.end() && i->second->size() > 1U;
160 auto const i = _find(
name);
165 auto const i = _find(
name);
166 return i != _map.end() && i->second->back().type() ==
typeid(
nullptr);
169size_t PropertySet::valueCount()
const {
171 for (
auto const&
name : paramNames(
false)) {
172 sum += valueCount(
name);
178 auto const i = _find(
name);
179 if (i == _map.end())
return 0;
180 return i->second->size();
184 auto const i = _find(
name);
185 if (i == _map.end()) {
186 throw LSST_EXCEPT(pex::exceptions::NotFoundError,
name +
" not found");
188 return i->second->back().type();
201 auto const i = _find(
name);
202 if (i == _map.end()) {
203 throw LSST_EXCEPT(pex::exceptions::NotFoundError,
name +
" not found");
206 return std::any_cast<T>(i->second->back());
207 }
catch (std::bad_any_cast &) {
211 return std::any_cast<T>(i->second->back());
217 auto const i = _find(
name);
218 if (i == _map.end()) {
222 return std::any_cast<T>(i->second->back());
223 }
catch (std::bad_any_cast &) {
227 return std::any_cast<T>(i->second->back());
232 auto const i = _find(
name);
233 if (i == _map.end()) {
234 throw LSST_EXCEPT(pex::exceptions::NotFoundError,
name +
" not found");
237 for (
auto const& j : *(i->second)) {
240 }
catch (std::bad_any_cast &) {
251 return get<bool>(
name);
255 auto const i = _find(
name);
256 if (i == _map.end()) {
257 throw LSST_EXCEPT(pex::exceptions::NotFoundError,
name +
" not found");
259 std::any v = i->second->
back();
261 if (t ==
typeid(
bool)) {
262 return std::any_cast<bool>(v);
263 }
else if (t ==
typeid(
char)) {
264 return std::any_cast<char>(v);
265 }
else if (t ==
typeid(
signed char)) {
266 return std::any_cast<signed char>(v);
267 }
else if (t ==
typeid(
unsigned char)) {
268 return std::any_cast<unsigned char>(v);
269 }
else if (t ==
typeid(
short)) {
270 return std::any_cast<short>(v);
271 }
else if (t ==
typeid(
unsigned short)) {
272 return std::any_cast<unsigned short>(v);
275 return std::any_cast<int>(v);
276 }
catch (std::bad_any_cast &) {
280 return std::any_cast<int>(v);
284 auto const i = _find(
name);
285 if (i == _map.end()) {
286 throw LSST_EXCEPT(pex::exceptions::NotFoundError,
name +
" not found");
288 std::any v = i->second->back();
290 if (t ==
typeid(
bool))
return std::any_cast<bool>(v);
291 if (t ==
typeid(
char))
return std::any_cast<char>(v);
292 if (t ==
typeid(
signed char))
return std::any_cast<signed char>(v);
293 if (t ==
typeid(
unsigned char))
return std::any_cast<unsigned char>(v);
294 if (t ==
typeid(
short))
return std::any_cast<short>(v);
295 if (t ==
typeid(
unsigned short))
return std::any_cast<unsigned short>(v);
296 if (t ==
typeid(
int))
return std::any_cast<int>(v);
297 if (t ==
typeid(
unsigned int))
return std::any_cast<unsigned int>(v);
298 if (t ==
typeid(
long))
return std::any_cast<long>(v);
299 if (t ==
typeid(
long long))
return std::any_cast<long long>(v);
301 return std::any_cast<int64_t>(v);
302 }
catch (std::bad_any_cast &) {
306 return std::any_cast<int64_t>(v);
310 auto const i = _find(
name);
311 if (i == _map.end()) {
312 throw LSST_EXCEPT(pex::exceptions::NotFoundError,
name +
" not found");
314 std::any v = i->second->back();
316 if (t ==
typeid(
bool))
return std::any_cast<bool>(v);
317 if (t ==
typeid(
char))
return std::any_cast<char>(v);
318 if (t ==
typeid(
signed char))
return std::any_cast<signed char>(v);
319 if (t ==
typeid(
unsigned char))
return std::any_cast<unsigned char>(v);
320 if (t ==
typeid(
short))
return std::any_cast<short>(v);
321 if (t ==
typeid(
unsigned short))
return std::any_cast<unsigned short>(v);
322 if (t ==
typeid(
int))
return std::any_cast<int>(v);
323 if (t ==
typeid(
unsigned int))
return std::any_cast<unsigned int>(v);
324 if (t ==
typeid(
long))
return std::any_cast<long>(v);
325 if (t ==
typeid(
long long))
return std::any_cast<long long>(v);
326 if (t ==
typeid(
unsigned long long))
return std::any_cast<unsigned long long>(v);
328 return std::any_cast<uint64_t>(v);
329 }
catch (std::bad_any_cast &) {
333 return std::any_cast<uint64_t>(v);
337 auto const i = _find(
name);
338 if (i == _map.end()) {
339 throw LSST_EXCEPT(pex::exceptions::NotFoundError,
name +
" not found");
341 std::any v = i->second->back();
343 if (t ==
typeid(
bool))
return std::any_cast<bool>(v);
344 if (t ==
typeid(
char))
return std::any_cast<char>(v);
345 if (t ==
typeid(
signed char))
return std::any_cast<signed char>(v);
346 if (t ==
typeid(
unsigned char))
return std::any_cast<unsigned char>(v);
347 if (t ==
typeid(
short))
return std::any_cast<short>(v);
348 if (t ==
typeid(
unsigned short))
return std::any_cast<unsigned short>(v);
349 if (t ==
typeid(
int))
return std::any_cast<int>(v);
350 if (t ==
typeid(
unsigned int))
return std::any_cast<unsigned int>(v);
351 if (t ==
typeid(
long))
return std::any_cast<long>(v);
352 if (t ==
typeid(
unsigned long))
return std::any_cast<unsigned long>(v);
353 if (t ==
typeid(
long long))
return std::any_cast<long long>(v);
354 if (t ==
typeid(
unsigned long long))
return std::any_cast<unsigned long long>(v);
355 if (t ==
typeid(
float))
return std::any_cast<float>(v);
357 return std::any_cast<double>(v);
358 }
catch (std::bad_any_cast &) {
362 return std::any_cast<double>(v);
368 return get<std::shared_ptr<PropertySet>>(
name);
371Persistable::Ptr PropertySet::getAsPersistablePtr(
std::string const&
name)
const {
372 return get<Persistable::Ptr>(
name);
379 for (
auto const& i : nv) {
383 s << indent << i <<
" = ";
387 auto p = std::any_cast<std::shared_ptr<PropertySet>>(vp->back());
392 s << p->toString(
false, indent +
"..");
398 s << indent << _format(i);
407 auto const j = _map.find(
name);
408 s << j->first <<
" = ";
410 if (vp->size() > 1) {
415 for (
auto const& k : *vp) {
421 std::any
const& v(k);
422 if (t ==
typeid(
bool)) {
423 s << std::any_cast<bool>(v);
424 }
else if (t ==
typeid(
char)) {
425 s << '\'' << std::any_cast<char>(v) <<
'\'';
426 }
else if (t ==
typeid(
signed char)) {
427 s << '\'' << std::any_cast<signed char>(v) <<
'\'';
428 }
else if (t ==
typeid(
unsigned char)) {
429 s << '\'' << std::any_cast<unsigned char>(v) <<
'\'';
430 }
else if (t ==
typeid(
short)) {
431 s << std::any_cast<short>(v);
432 }
else if (t ==
typeid(
unsigned short)) {
433 s << std::any_cast<unsigned short>(v);
434 }
else if (t ==
typeid(
int)) {
435 s << std::any_cast<int>(v);
436 }
else if (t ==
typeid(
unsigned int)) {
437 s << std::any_cast<unsigned int>(v);
438 }
else if (t ==
typeid(
long)) {
439 s << std::any_cast<long>(v);
440 }
else if (t ==
typeid(
unsigned long)) {
441 s << std::any_cast<unsigned long>(v);
442 }
else if (t ==
typeid(
long long)) {
443 s << std::any_cast<long long>(v);
444 }
else if (t ==
typeid(
unsigned long long)) {
445 s << std::any_cast<unsigned long long>(v);
446 }
else if (t ==
typeid(
float)) {
447 s << std::setprecision(7) << std::any_cast<float>(v);
448 }
else if (t ==
typeid(
double)) {
449 s << std::setprecision(14) << std::any_cast<double>(v);
451 s <<
'"' << std::any_cast<std::string>(v) <<
'"';
452 }
else if (t ==
typeid(DateTime)) {
453 s << std::any_cast<DateTime>(v).toString(DateTime::UTC);
456 }
else if (t ==
typeid(Persistable::Ptr)) {
457 s <<
"<Persistable>";
462 if (j->second->size() > 1) {
476 vp->push_back(value);
482 if (value.
empty())
return;
492 AnyMap::iterator i = _find(
name);
493 if (i == _map.end()) {
496 if (i->second->back().type() !=
typeid(T)) {
497 throw LSST_EXCEPT(pex::exceptions::TypeError,
name +
" has mismatched type");
499 i->second->push_back(value);
505void PropertySet::add<std::shared_ptr<PropertySet>>(
509 AnyMap::iterator i = _find(
name);
510 if (i == _map.end()) {
514 throw LSST_EXCEPT(pex::exceptions::TypeError,
name +
" has mismatched type");
516 _cycleCheckPtr(value,
name);
517 i->second->push_back(value);
523 AnyMap::iterator i = _find(
name);
524 if (i == _map.end()) {
527 if (i->second->back().type() !=
typeid(T)) {
528 throw LSST_EXCEPT(pex::exceptions::TypeError,
name +
" has mismatched type");
530 _append(*(i->second), value);
536void PropertySet::add<std::shared_ptr<PropertySet>>(
540 AnyMap::iterator i = _find(
name);
541 if (i == _map.end()) {
545 throw LSST_EXCEPT(pex::exceptions::TypeError,
name +
" has mismatched type");
547 _cycleCheckPtrVec(value,
name);
548 _append(*(i->second), value);
554void PropertySet::copy(
556 PropertySet
const& source,
561 if (sj ==
source._map.end()) {
562 throw LSST_EXCEPT(pex::exceptions::InvalidParameterError,
name +
" not in source");
566 auto vp = std::make_shared<std::vector<std::any>>();
567 vp->push_back(sj->second->back());
570 auto vp = std::make_shared<std::vector<std::any>>(*(sj->second));
578 throw LSST_EXCEPT(pex::exceptions::InvalidParameterError,
"Missing source");
580 copy(dest, *source,
name, asScalar);
583void PropertySet::combine(PropertySet
const & source) {
585 for (
auto const&
name : names) {
587 _add(
name, sp->second);
599 std::string::size_type i =
name.find(
'.');
600 if (_flat || i ==
name.npos) {
605 AnyMap::iterator j = _map.find(
prefix);
609 auto p = std::any_cast<std::shared_ptr<PropertySet>>(j->second->back());
620PropertySet::AnyMap::iterator PropertySet::_find(
std::string const&
name) {
621 std::string::size_type i =
name.find(
'.');
622 if (_flat || i ==
name.npos) {
623 return _map.find(
name);
626 AnyMap::iterator j = _map.find(
prefix);
630 auto p = std::any_cast<std::shared_ptr<PropertySet>>(j->second->back());
635 AnyMap::iterator
x = p->_find(suffix);
636 if (
x == p->_map.end()) {
642PropertySet::AnyMap::const_iterator PropertySet::_find(
std::string const&
name)
const {
643 std::string::size_type i =
name.find(
'.');
644 if (_flat || i ==
name.npos) {
645 return _map.find(
name);
648 auto const j = _map.find(
prefix);
652 auto p = std::any_cast<std::shared_ptr<PropertySet>>(j->second->back());
657 auto const x = p->_find(suffix);
658 if (
x == p->_map.end()) {
665 _findOrInsert(
name, vp);
669 auto const dp = _find(
name);
670 if (dp == _map.end()) {
673 if (vp->back().type() != dp->second->back().type()) {
674 throw LSST_EXCEPT(pex::exceptions::TypeError,
name +
" has mismatched type");
678 _cycleCheckAnyVec(*vp,
name);
680 _append(*(dp->second), *vp);
687 auto source = std::any_cast<std::shared_ptr<PropertySet>>(vp->back());
689 for (
auto const& i : names) {
690 auto const sp =
source->_find(i);
691 _add(
name +
"." + i, sp->second);
697 _cycleCheckAnyVec(*vp,
name);
700 std::string::size_type i =
name.find(
'.');
701 if (_flat || i ==
name.npos) {
707 AnyMap::iterator j = _map.find(
prefix);
708 if (j == _map.end()) {
709 auto pp = std::make_shared<PropertySet>();
710 pp->_findOrInsert(suffix, vp);
716 throw LSST_EXCEPT(pex::exceptions::InvalidParameterError,
717 prefix +
" exists but does not contain PropertySets");
719 auto p = std::any_cast<std::shared_ptr<PropertySet>>(j->second->back());
721 throw LSST_EXCEPT(pex::exceptions::InvalidParameterError,
722 prefix +
" exists but contains a null PropertySet");
724 p->_findOrInsert(suffix, vp);
727void PropertySet::_cycleCheckPtrVec(
731 for (
auto const& i : v) {
732 _cycleCheckPtr(i,
name);
737 for (
auto const& i : v) {
743 if (v.
get() ==
this) {
744 throw LSST_EXCEPT(pex::exceptions::InvalidParameterError,
name +
" would cause a cycle");
747 for (
auto const& i : sets) {
748 if (v->getAsPropertySetPtr(i).
get() ==
this) {
749 throw LSST_EXCEPT(pex::exceptions::InvalidParameterError,
name +
" would cause a cycle");
761#define INSTANTIATE(t) \
762 template std::type_info const& PropertySet::typeOfT<t>(); \
763 template t PropertySet::get<t>(std::string const& name) const; \
764 template t PropertySet::get<t>(std::string const& name, t const& defaultValue) const; \
765 template std::vector<t> PropertySet::getArray<t>(std::string const& name) const; \
766 template void PropertySet::set<t>(std::string const& name, t const& value); \
767 template void PropertySet::set<t>(std::string const& name, std::vector<t> const& value); \
768 template void PropertySet::add<t>(std::string const& name, t const& value); \
769 template void PropertySet::add<t>(std::string const& name, std::vector<t> const& value);
771#define INSTANTIATE_PROPERTY_SET(t) \
772 template std::type_info const& PropertySet::typeOfT<t>(); \
773 template t PropertySet::get<t>(std::string const& name) const; \
774 template t PropertySet::get<t>(std::string const& name, t const& defaultValue) const; \
775 template std::vector<t> PropertySet::getArray<t>(std::string const& name) const; \
776 template void PropertySet::set<t>(std::string const& name, t const& value); \
777 template void PropertySet::set<t>(std::string const& name, std::vector<t> const& value);
table::Key< std::string > name
Interface for DateTime class.
#define INSTANTIATE(FROMSYS, TOSYS)
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
std::shared_ptr< RecordT > src
PropertySet(bool flat=false)
Construct an empty PropertySet.
daf::base::PropertySet * set
const char * source()
Source function that allows astChannel to source from a Stream.
T throw_with_nested(T... args)