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));
576void PropertySet::combine(PropertySet
const & source) {
580 _add(
name, sp->second);
586 std::string::size_type i =
name.find(
'.');
587 if (_flat || i ==
name.npos) {
592 AnyMap::iterator j = _map.find(
prefix);
596 auto p = std::any_cast<std::shared_ptr<PropertySet>>(j->second->back());
607PropertySet::AnyMap::iterator PropertySet::_find(
std::string const&
name) {
608 std::string::size_type i =
name.find(
'.');
609 if (_flat || i ==
name.npos) {
610 return _map.find(
name);
613 AnyMap::iterator j = _map.find(
prefix);
617 auto p = std::any_cast<std::shared_ptr<PropertySet>>(j->second->back());
622 AnyMap::iterator
x = p->_find(suffix);
623 if (
x == p->_map.end()) {
629PropertySet::AnyMap::const_iterator PropertySet::_find(
std::string const&
name)
const {
630 std::string::size_type i =
name.find(
'.');
631 if (_flat || i ==
name.npos) {
632 return _map.find(
name);
635 auto const j = _map.find(
prefix);
639 auto p = std::any_cast<std::shared_ptr<PropertySet>>(j->second->back());
644 auto const x = p->_find(suffix);
645 if (
x == p->_map.end()) {
652 _findOrInsert(
name, vp);
656 auto const dp = _find(
name);
657 if (dp == _map.end()) {
660 if (vp->back().type() != dp->second->back().type()) {
661 throw LSST_EXCEPT(pex::exceptions::TypeError,
name +
" has mismatched type");
665 _cycleCheckAnyVec(*vp,
name);
667 _append(*(dp->second), *vp);
674 auto source = std::any_cast<std::shared_ptr<PropertySet>>(vp->back());
676 for (
auto const& i :
names) {
677 auto const sp =
source->_find(i);
678 _add(
name +
"." + i, sp->second);
684 _cycleCheckAnyVec(*vp,
name);
687 std::string::size_type i =
name.find(
'.');
688 if (_flat || i ==
name.npos) {
694 AnyMap::iterator j = _map.find(
prefix);
695 if (j == _map.end()) {
696 auto pp = std::make_shared<PropertySet>();
697 pp->_findOrInsert(suffix, vp);
703 throw LSST_EXCEPT(pex::exceptions::InvalidParameterError,
704 prefix +
" exists but does not contain PropertySets");
706 auto p = std::any_cast<std::shared_ptr<PropertySet>>(j->second->back());
708 throw LSST_EXCEPT(pex::exceptions::InvalidParameterError,
709 prefix +
" exists but contains a null PropertySet");
711 p->_findOrInsert(suffix, vp);
714void PropertySet::_cycleCheckPtrVec(
718 for (
auto const& i : v) {
719 _cycleCheckPtr(i,
name);
724 for (
auto const& i : v) {
730 if (v.
get() ==
this) {
731 throw LSST_EXCEPT(pex::exceptions::InvalidParameterError,
name +
" would cause a cycle");
734 for (
auto const& i : sets) {
735 if (v->getAsPropertySetPtr(i).
get() ==
this) {
736 throw LSST_EXCEPT(pex::exceptions::InvalidParameterError,
name +
" would cause a cycle");
748#define INSTANTIATE(t) \
749 template std::type_info const& PropertySet::typeOfT<t>(); \
750 template t PropertySet::get<t>(std::string const& name) const; \
751 template t PropertySet::get<t>(std::string const& name, t const& defaultValue) const; \
752 template std::vector<t> PropertySet::getArray<t>(std::string const& name) const; \
753 template void PropertySet::set<t>(std::string const& name, t const& value); \
754 template void PropertySet::set<t>(std::string const& name, std::vector<t> const& value); \
755 template void PropertySet::add<t>(std::string const& name, t const& value); \
756 template void PropertySet::add<t>(std::string const& name, std::vector<t> const& value);
758#define INSTANTIATE_PROPERTY_SET(t) \
759 template std::type_info const& PropertySet::typeOfT<t>(); \
760 template t PropertySet::get<t>(std::string const& name) const; \
761 template t PropertySet::get<t>(std::string const& name, t const& defaultValue) const; \
762 template std::vector<t> PropertySet::getArray<t>(std::string const& name) const; \
763 template void PropertySet::set<t>(std::string const& name, t const& value); \
764 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)