LSSTApplications  10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
LSSTDataManagementBasePackage
PropertySet.cc
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 
3 /*
4  * LSST Data Management System
5  * Copyright 2008, 2009, 2010 LSST Corporation.
6  *
7  * This product includes software developed by the
8  * LSST Project (http://www.lsst.org/).
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more detailTypeErrors.
19  *
20  * You should have received a copy of the LSST License Statement and
21  * the GNU General Public License along with this program. If not,
22  * see <http://www.lsstcorp.org/LegalNotices/>.
23  */
24 
25 
38 
39 #include <algorithm>
40 #include <iomanip>
41 #include <sstream>
42 #include <stdexcept>
43 
45 #include "lsst/daf/base/DateTime.h"
46 
47 namespace dafBase = lsst::daf::base;
48 namespace pexExcept = lsst::pex::exceptions;
49 
50 using namespace std;
51 
55 dafBase::PropertySet::PropertySet(bool flat) : Citizen(typeid(*this)), _flat(flat) {
56 }
57 
61 }
62 
64 // Accessors
66 
71  Ptr n(new PropertySet(_flat));
72  for (AnyMap::const_iterator i = _map.begin(); i != _map.end(); ++i) {
73  if (i->second->back().type() == typeid(Ptr)) {
74  for (vector<boost::any>::const_iterator j =
75  i->second->begin(); j != i->second->end(); ++j) {
76  Ptr p = boost::any_cast<Ptr>(*j);
77  if (p.get() == 0) {
78  n->add(i->first, Ptr());
79  } else {
80  n->add(i->first, p->deepCopy());
81  }
82  }
83  } else {
84  boost::shared_ptr< vector<boost::any> > vp(
85  new vector<boost::any>(*(i->second)));
86  n->_map[i->first] = vp;
87  }
88  }
89  return n;
90 }
91 
97 size_t dafBase::PropertySet::nameCount(bool topLevelOnly) const {
98  int n = 0;
99  for (AnyMap::const_iterator i = _map.begin(); i != _map.end(); ++i) {
100  ++n;
101  if (!topLevelOnly && i->second->back().type() == typeid(Ptr)) {
102  Ptr p = boost::any_cast<Ptr>(i->second->back());
103  if (p.get() != 0) {
104  n += p->nameCount(false);
105  }
106  }
107  }
108  return n;
109 }
110 
117 vector<string> dafBase::PropertySet::names(bool topLevelOnly) const {
118  vector<string> v;
119  for (AnyMap::const_iterator i = _map.begin(); i != _map.end(); ++i) {
120  v.push_back(i->first);
121  if (!topLevelOnly && i->second->back().type() == typeid(Ptr)) {
122  Ptr p = boost::any_cast<Ptr>(i->second->back());
123  if (p.get() != 0) {
124  vector<string> w = p->names(false);
125  for (vector<string>::const_iterator k = w.begin();
126  k != w.end(); ++k) {
127  v.push_back(i->first + "." + *k);
128  }
129  }
130  }
131  }
132  return v;
133 }
134 
141 vector<string>
142 dafBase::PropertySet::paramNames(bool topLevelOnly) const {
143  vector<string> v;
144  for (AnyMap::const_iterator i = _map.begin(); i != _map.end(); ++i) {
145  if (i->second->back().type() == typeid(Ptr)) {
146  Ptr p = boost::any_cast<Ptr>(i->second->back());
147  if (p.get() != 0 && !topLevelOnly) {
148  vector<string> w = p->paramNames(false);
149  for (vector<string>::const_iterator k = w.begin();
150  k != w.end(); ++k) {
151  v.push_back(i->first + "." + *k);
152  }
153  }
154  } else {
155  v.push_back(i->first);
156  }
157  }
158  return v;
159 }
160 
167 vector<string>
168 dafBase::PropertySet::propertySetNames(bool topLevelOnly) const {
169  vector<string> v;
170  for (AnyMap::const_iterator i = _map.begin(); i != _map.end(); ++i) {
171  if (i->second->back().type() == typeid(Ptr)) {
172  v.push_back(i->first);
173  Ptr p = boost::any_cast<Ptr>(i->second->back());
174  if (p.get() != 0 && !topLevelOnly) {
175  vector<string> w = p->propertySetNames(false);
176  for (vector<string>::const_iterator k = w.begin();
177  k != w.end(); ++k) {
178  v.push_back(i->first + "." + *k);
179  }
180  }
181  }
182  }
183  return v;
184 }
185 
190 bool dafBase::PropertySet::exists(std::string const& name) const {
191  return _find(name) != _map.end();
192 }
193 
198 bool dafBase::PropertySet::isArray(std::string const& name) const {
199  AnyMap::const_iterator i = _find(name);
200  return i != _map.end() && i->second->size() > 1U;
201 }
202 
207 bool dafBase::PropertySet::isPropertySetPtr(std::string const& name) const {
208  AnyMap::const_iterator i = _find(name);
209  return i != _map.end() && i->second->back().type() == typeid(Ptr);
210 }
211 
216 size_t dafBase::PropertySet::valueCount(std::string const& name) const {
217  AnyMap::const_iterator i = _find(name);
218  if (i == _map.end()) return 0;
219  return i->second->size();
220 }
221 
227 type_info const& dafBase::PropertySet::typeOf(std::string const& name) const {
228  AnyMap::const_iterator i = _find(name);
229  if (i == _map.end()) {
230  throw LSST_EXCEPT(pexExcept::NotFoundError, name + " not found");
231  }
232  return i->second->back().type();
233 }
234 
235 // The following throw an exception if the type does not match exactly.
236 
245 template <typename T>
246 T dafBase::PropertySet::get(string const& name) const { /* parasoft-suppress LsstDm-3-4a LsstDm-4-6 "allow template over bool" */
247  AnyMap::const_iterator i = _find(name);
248  if (i == _map.end()) {
249  throw LSST_EXCEPT(pexExcept::NotFoundError, name + " not found");
250  }
251  try {
252  return boost::any_cast<T>(i->second->back());
253  }
254  catch (boost::bad_any_cast) {
255  throw LSST_EXCEPT(pexExcept::TypeError, name);
256  }
257  // not reached
258  return boost::any_cast<T>(i->second->back());
259 }
260 
270 template <typename T>
271 T dafBase::PropertySet::get(string const& name, T const& defaultValue) const { /* parasoft-suppress LsstDm-3-4a LsstDm-4-6 "allow template over bool" */
272  AnyMap::const_iterator i = _find(name);
273  if (i == _map.end()) {
274  return defaultValue;
275  }
276  try {
277  return boost::any_cast<T>(i->second->back());
278  }
279  catch (boost::bad_any_cast) {
280  throw LSST_EXCEPT(pexExcept::TypeError, name);
281  }
282  // not reached
283  return boost::any_cast<T>(i->second->back());
284 }
285 
294 template <typename T>
295 vector<T> dafBase::PropertySet::getArray(string const& name) const {
296  AnyMap::const_iterator i = _find(name);
297  if (i == _map.end()) {
298  throw LSST_EXCEPT(pexExcept::NotFoundError, name + " not found");
299  }
300  vector<T> v;
301  for (vector<boost::any>::const_iterator j = i->second->begin();
302  j != i->second->end(); ++j) {
303  try {
304  v.push_back(boost::any_cast<T>(*j));
305  }
306  catch (boost::bad_any_cast) {
307  throw LSST_EXCEPT(pexExcept::TypeError, name);
308  }
309  }
310  return v;
311 }
312 
313 // The following throw an exception if the conversion is inappropriate.
314 
321 bool dafBase::PropertySet::getAsBool(std::string const& name) const { /* parasoft-suppress LsstDm-3-4a LsstDm-4-6 "for symmetry with other types" */
322  return get<bool>(name);
323 }
324 
333 int dafBase::PropertySet::getAsInt(std::string const& name) const {
334  AnyMap::const_iterator i = _find(name);
335  if (i == _map.end()) {
336  throw LSST_EXCEPT(pexExcept::NotFoundError, name + " not found");
337  }
338  boost::any v = i->second->back();
339  type_info const& t = v.type();
340  if (t == typeid(bool)) {
341  return boost::any_cast<bool>(v);
342  } else if (t == typeid(char)) {
343  return boost::any_cast<char>(v);
344  } else if (t == typeid(signed char)) {
345  return boost::any_cast<signed char>(v);
346  } else if (t == typeid(unsigned char)) {
347  return boost::any_cast<unsigned char>(v);
348  } else if (t == typeid(short)) {
349  return boost::any_cast<short>(v);
350  } else if (t == typeid(unsigned short)) {
351  return boost::any_cast<unsigned short>(v);
352  }
353  try {
354  return boost::any_cast<int>(v);
355  }
356  catch (boost::bad_any_cast) {
357  throw LSST_EXCEPT(pexExcept::TypeError, name);
358  }
359  // not reached
360  return boost::any_cast<int>(v);
361 }
362 
372 int64_t dafBase::PropertySet::getAsInt64(std::string const& name) const {
373  AnyMap::const_iterator i = _find(name);
374  if (i == _map.end()) {
375  throw LSST_EXCEPT(pexExcept::NotFoundError, name + " not found");
376  }
377  boost::any v = i->second->back();
378  type_info const& t = v.type();
379  if (t == typeid(bool)) return boost::any_cast<bool>(v);
380  if (t == typeid(char)) return boost::any_cast<char>(v);
381  if (t == typeid(signed char)) return boost::any_cast<signed char>(v);
382  if (t == typeid(unsigned char)) return boost::any_cast<unsigned char>(v);
383  if (t == typeid(short)) return boost::any_cast<short>(v);
384  if (t == typeid(unsigned short)) return boost::any_cast<unsigned short>(v);
385  if (t == typeid(int)) return boost::any_cast<int>(v);
386  if (t == typeid(unsigned int)) return boost::any_cast<unsigned int>(v);
387  if (t == typeid(long)) return boost::any_cast<long>(v);
388  if (t == typeid(long long)) return boost::any_cast<long long>(v);
389  try {
390  return boost::any_cast<int64_t>(v);
391  }
392  catch (boost::bad_any_cast) {
393  throw LSST_EXCEPT(pexExcept::TypeError, name);
394  }
395  // not reached
396  return boost::any_cast<int64_t>(v);
397 }
398 
406 double dafBase::PropertySet::getAsDouble(std::string const& name) const {
407  AnyMap::const_iterator i = _find(name);
408  if (i == _map.end()) {
409  throw LSST_EXCEPT(pexExcept::NotFoundError, name + " not found");
410  }
411  boost::any v = i->second->back();
412  type_info const& t = v.type();
413  if (t == typeid(bool)) return boost::any_cast<bool>(v);
414  if (t == typeid(char)) return boost::any_cast<char>(v);
415  if (t == typeid(signed char)) return boost::any_cast<signed char>(v);
416  if (t == typeid(unsigned char)) return boost::any_cast<unsigned char>(v);
417  if (t == typeid(short)) return boost::any_cast<short>(v);
418  if (t == typeid(unsigned short)) return boost::any_cast<unsigned short>(v);
419  if (t == typeid(int)) return boost::any_cast<int>(v);
420  if (t == typeid(unsigned int)) return boost::any_cast<unsigned int>(v);
421  if (t == typeid(long)) return boost::any_cast<long>(v);
422  if (t == typeid(unsigned long)) return boost::any_cast<unsigned long>(v);
423  if (t == typeid(long long)) return boost::any_cast<long long>(v);
424  if (t == typeid(unsigned long long)) return boost::any_cast<unsigned long long>(v);
425  if (t == typeid(float)) return boost::any_cast<float>(v);
426  try {
427  return boost::any_cast<double>(v);
428  }
429  catch (boost::bad_any_cast) {
430  throw LSST_EXCEPT(pexExcept::TypeError, name);
431  }
432  // not reached
433  return boost::any_cast<double>(v);
434 }
435 
444 std::string dafBase::PropertySet::getAsString(std::string const& name) const {
445  return get<string>(name);
446 }
447 
456  return get<Ptr>(name);
457 }
458 
467  return get<Persistable::Ptr>(name);
468 }
469 
476 std::string dafBase::PropertySet::toString(bool topLevelOnly,
477  std::string const& indent) const {
478  ostringstream s;
479  vector<string> nv = names();
480  sort(nv.begin(), nv.end());
481  for (vector<string>::const_iterator i = nv.begin(); i != nv.end(); ++i) {
482  boost::shared_ptr< vector<boost::any> > vp = _map.find(*i)->second;
483  type_info const& t = vp->back().type();
484  if (t == typeid(Ptr)) {
485  s << indent << *i << " = ";
486  if (topLevelOnly) {
487  s << "{ ... }";
488  } else {
489  Ptr p = boost::any_cast<Ptr>(vp->back());
490  if (p.get() == 0) {
491  s << "{ NULL }";
492  } else {
493  s << '{' << endl;
494  s << p->toString(false, indent + "..");
495  s << indent << '}';
496  }
497  }
498  s << endl;
499  }
500  else {
501  s << indent << _format(*i);
502  }
503  }
504  return s.str();
505 }
506 
507 std::string dafBase::PropertySet::_format(std::string const& name) const {
508  ostringstream s;
509  s << std::showpoint; // Always show a decimal point for floats
510  AnyMap::const_iterator j = _map.find(name);
511  s << j->first << " = ";
512  boost::shared_ptr< vector<boost::any> > vp = j->second;
513  if (vp->size() > 1) {
514  s << "[ ";
515  }
516  type_info const& t = vp->back().type();
517  for (vector<boost::any>::const_iterator k = vp->begin();
518  k != vp->end(); ++k) {
519  if (k != vp->begin()) {
520  s << ", ";
521  }
522  boost::any const& v(*k);
523  if (t == typeid(bool)) {
524  s << boost::any_cast<bool>(v);
525  } else if (t == typeid(char)) {
526  s << '\'' << boost::any_cast<char>(v) << '\'';
527  } else if (t == typeid(signed char)) {
528  s << '\'' << boost::any_cast<signed char>(v) << '\'';
529  } else if (t == typeid(unsigned char)) {
530  s << '\'' << boost::any_cast<unsigned char>(v) << '\'';
531  } else if (t == typeid(short)) {
532  s << boost::any_cast<short>(v);
533  } else if (t == typeid(unsigned short)) {
534  s << boost::any_cast<unsigned short>(v);
535  } else if (t == typeid(int)) {
536  s << boost::any_cast<int>(v);
537  } else if (t == typeid(unsigned int)) {
538  s << boost::any_cast<unsigned int>(v);
539  } else if (t == typeid(long)) {
540  s << boost::any_cast<long>(v);
541  } else if (t == typeid(unsigned long)) {
542  s << boost::any_cast<unsigned long>(v);
543  } else if (t == typeid(long long)) {
544  s << boost::any_cast<long long>(v);
545  } else if (t == typeid(unsigned long long)) {
546  s << boost::any_cast<unsigned long long>(v);
547  } else if (t == typeid(float)) {
548  s << std::setprecision(7) << boost::any_cast<float>(v);
549  } else if (t == typeid(double)) {
550  s << std::setprecision(14) << boost::any_cast<double>(v);
551  } else if (t == typeid(string)) {
552  s << '"' << boost::any_cast<string>(v) << '"';
553  } else if (t == typeid(dafBase::DateTime)) {
554  s << boost::any_cast<dafBase::DateTime>(v).toString();
555  } else if (t == typeid(Ptr)) {
556  s << "{ ... }";
557  } else if (t == typeid(Persistable::Ptr)) {
558  s << "<Persistable>";
559  } else {
560  s << "<Unknown>";
561  }
562  }
563  if (j->second->size() > 1) {
564  s << " ]";
565  }
566  s << endl;
567  return s.str();
568 }
569 
571 // Modifiers
573 
580 template <typename T>
581 void dafBase::PropertySet::set(std::string const& name, T const& value) {
582  boost::shared_ptr< vector<boost::any> > vp(new vector<boost::any>);
583  vp->push_back(value);
584  _set(name, vp);
585 }
586 
593 template <typename T>
594 void dafBase::PropertySet::set(std::string const& name,
595  vector<T> const& value) {
596  if (value.empty()) return;
597  boost::shared_ptr< vector<boost::any> > vp(new vector<boost::any>);
598  vp->insert(vp->end(), value.begin(), value.end());
599  _set(name, vp);
600 }
601 
607 void dafBase::PropertySet::set(std::string const& name, char const* value) {
608  set(name, string(value));
609 }
610 
618 template <typename T>
619 void dafBase::PropertySet::add(std::string const& name, T const& value) {
620  AnyMap::iterator i = _find(name);
621  if (i == _map.end()) {
622  set(name, value);
623  }
624  else {
625  if (i->second->back().type() != typeid(T)) {
626  throw LSST_EXCEPT(pexExcept::TypeError,
627  name + " has mismatched type");
628  }
629  i->second->push_back(value);
630  }
631 }
632 
633 // Specialize for Ptrs to check for cycles.
634 template <> void dafBase::PropertySet::add<dafBase::PropertySet::Ptr>(
635  std::string const& name, Ptr const& value) {
636  AnyMap::iterator i = _find(name);
637  if (i == _map.end()) {
638  set(name, value);
639  }
640  else {
641  if (i->second->back().type() != typeid(Ptr)) {
642  throw LSST_EXCEPT(pexExcept::TypeError,
643  name + " has mismatched type");
644  }
645  _cycleCheckPtr(value, name);
646  i->second->push_back(value);
647  }
648 }
649 
659 template <typename T>
660 void dafBase::PropertySet::add(std::string const& name,
661  vector<T> const& value) {
662  AnyMap::iterator i = _find(name);
663  if (i == _map.end()) {
664  set(name, value);
665  }
666  else {
667  if (i->second->back().type() != typeid(T)) {
668  throw LSST_EXCEPT(pexExcept::TypeError,
669  name + " has mismatched type");
670  }
671  i->second->insert(i->second->end(), value.begin(), value.end());
672  }
673 }
674 
675 // Specialize for Ptrs to check for cycles.
676 template<> void dafBase::PropertySet::add<dafBase::PropertySet::Ptr>(
677  std::string const& name, vector<Ptr> const& value) {
678  AnyMap::iterator i = _find(name);
679  if (i == _map.end()) {
680  set(name, value);
681  }
682  else {
683  if (i->second->back().type() != typeid(Ptr)) {
684  throw LSST_EXCEPT(pexExcept::TypeError,
685  name + " has mismatched type");
686  }
687  _cycleCheckPtrVec(value, name);
688  i->second->insert(i->second->end(), value.begin(), value.end());
689  }
690 }
691 
700 void dafBase::PropertySet::add(std::string const& name, char const* value) {
701  add(name, string(value));
702 }
703 
713 void dafBase::PropertySet::copy(std::string const& dest,
714  ConstPtr source, std::string const& name) {
715  if (source.get() == 0) {
716  throw LSST_EXCEPT(pexExcept::InvalidParameterError,
717  "Missing source");
718  }
719  AnyMap::const_iterator sj = source->_find(name);
720  if (sj == source->_map.end()) {
721  throw LSST_EXCEPT(pexExcept::InvalidParameterError,
722  name + " not in source");
723  }
724  remove(dest);
725  boost::shared_ptr< vector<boost::any> > vp(
726  new vector<boost::any>(*(sj->second)));
727  _set(dest, vp);
728 }
729 
739  if (source.get() == 0) {
740  return;
741  }
742  vector<string> names = source->paramNames(false);
743  for (vector<string>::const_iterator i = names.begin();
744  i != names.end(); ++i) {
745  AnyMap::const_iterator sp = source->_find(*i);
746  _add(*i, sp->second);
747  }
748 }
749 
754 void dafBase::PropertySet::remove(std::string const& name) {
755  string::size_type i = name.find('.');
756  if (_flat || i == name.npos) {
757  _map.erase(name);
758  return;
759  }
760  string prefix(name, 0, i);
761  AnyMap::iterator j = _map.find(prefix);
762  if (j == _map.end() || j->second->back().type() != typeid(Ptr)) {
763  return;
764  }
765  Ptr p = boost::any_cast<Ptr>(j->second->back());
766  if (p.get() != 0) {
767  string suffix(name, i + 1);
768  p->remove(suffix);
769  }
770 }
771 
773 // Private member functions
775 
780 dafBase::PropertySet::AnyMap::iterator
781 dafBase::PropertySet::_find(std::string const& name) {
782  string::size_type i = name.find('.');
783  if (_flat || i == name.npos) {
784  return _map.find(name);
785  }
786  string prefix(name, 0, i);
787  AnyMap::iterator j = _map.find(prefix);
788  if (j == _map.end() || j->second->back().type() != typeid(Ptr)) {
789  return _map.end();
790  }
791  Ptr p = boost::any_cast<Ptr>(j->second->back());
792  if (p.get() == 0) {
793  return _map.end();
794  }
795  string suffix(name, i + 1);
796  AnyMap::iterator x = p->_find(suffix);
797  if (x == p->_map.end()) {
798  return _map.end();
799  }
800  return x;
801 }
802 
807 dafBase::PropertySet::AnyMap::const_iterator
808 dafBase::PropertySet::_find(std::string const& name) const {
809  string::size_type i = name.find('.');
810  if (_flat || i == name.npos) {
811  return _map.find(name);
812  }
813  string prefix(name, 0, i);
814  AnyMap::const_iterator j = _map.find(prefix);
815  if (j == _map.end() || j->second->back().type() != typeid(Ptr)) {
816  return _map.end();
817  }
818  Ptr p = boost::any_cast<Ptr>(j->second->back());
819  if (p.get() == 0) {
820  return _map.end();
821  }
822  string suffix(name, i + 1);
823  AnyMap::const_iterator x = p->_find(suffix);
824  if (x == p->_map.end()) {
825  return _map.end();
826  }
827  return x;
828 }
829 
838  std::string const& name, boost::shared_ptr< std::vector<boost::any> > vp) {
839  _findOrInsert(name, vp);
840 }
841 
849  std::string const& name, boost::shared_ptr< std::vector<boost::any> > vp) {
850 
851  AnyMap::const_iterator dp = _find(name);
852  if (dp == _map.end()) {
853  _set(name, vp);
854  }
855  else {
856  if (vp->back().type() != dp->second->back().type()) {
857  throw LSST_EXCEPT(pexExcept::TypeError,
858  name + " has mismatched type");
859  }
860  // Check for cycles
861  if (vp->back().type() == typeid(Ptr)) {
862  _cycleCheckAnyVec(*vp, name);
863  }
864  dp->second->insert(dp->second->end(), vp->begin(), vp->end());
865  }
866 }
867 
875  std::string const& name, boost::shared_ptr< std::vector<boost::any> > vp) {
876  if (vp->back().type() == typeid(Ptr)) {
877  if (_flat) {
878  Ptr source = boost::any_cast<Ptr>(vp->back());
879  vector<string> names = source->paramNames(false);
880  for (vector<string>::const_iterator i = names.begin();
881  i != names.end(); ++i) {
882  AnyMap::const_iterator sp = source->_find(*i);
883  _add(name + "." + *i, sp->second);
884  }
885  return;
886  }
887 
888  // Check for cycles
889  _cycleCheckAnyVec(*vp, name);
890  }
891 
892  string::size_type i = name.find('.');
893  if (_flat || i == name.npos) {
894  _map[name] = vp;
895  return;
896  }
897  string prefix(name, 0, i);
898  string suffix(name, i + 1);
899  AnyMap::iterator j = _map.find(prefix);
900  if (j == _map.end()) {
902  pp->_findOrInsert(suffix, vp);
903  boost::shared_ptr< vector<boost::any> > temp(new vector<boost::any>);
904  temp->push_back(pp);
905  _map[prefix] = temp;
906  return;
907  }
908  else if (j->second->back().type() != typeid(Ptr)) {
909  throw LSST_EXCEPT(pexExcept::InvalidParameterError,
910  prefix +
911  " exists but does not contain PropertySet::Ptrs");
912  }
913  Ptr p = boost::any_cast<Ptr>(j->second->back());
914  if (p.get() == 0) {
915  throw LSST_EXCEPT(pexExcept::InvalidParameterError,
916  prefix +
917  " exists but contains null PropertySet::Ptr");
918  }
919  p->_findOrInsert(suffix, vp);
920 }
921 
922 void dafBase::PropertySet::_cycleCheckPtrVec(std::vector<Ptr> const& v,
923  std::string const& name) {
924  for (vector<Ptr>::const_iterator i = v.begin(); i != v.end(); ++i) {
925  _cycleCheckPtr(*i, name);
926  }
927 }
928 
929 void dafBase::PropertySet::_cycleCheckAnyVec(std::vector<boost::any> const& v,
930  std::string const& name) {
931  for (vector<boost::any>::const_iterator i = v.begin(); i != v.end(); ++i) {
932  _cycleCheckPtr(boost::any_cast<Ptr>(*i), name);
933  }
934 }
935 
937  std::string const& name) {
938  if (v.get() == this) {
939  throw LSST_EXCEPT(pexExcept::InvalidParameterError,
940  name + " would cause a cycle");
941  }
942  vector<string> sets = v->propertySetNames(false);
943  for (vector<string>::const_iterator i = sets.begin();
944  i != sets.end(); ++i) {
945  if (v->getAsPropertySetPtr(*i).get() == this) {
946  throw LSST_EXCEPT(pexExcept::InvalidParameterError,
947  name + " would cause a cycle");
948  }
949  }
950 }
951 
953 // Explicit template instantiations
955 
957 // Explicit template instantiations are not well understood by doxygen.
958 
959 #define INSTANTIATE(t) \
960  template t dafBase::PropertySet::get<t>(string const& name) const; \
961  template t dafBase::PropertySet::get<t>(string const& name, t const& defaultValue) const; \
962  template vector<t> dafBase::PropertySet::getArray<t>(string const& name) const; \
963  template void dafBase::PropertySet::set<t>(string const& name, t const& value); \
964  template void dafBase::PropertySet::set<t>(string const& name, vector<t> const& value); \
965  template void dafBase::PropertySet::add<t>(string const& name, t const& value); \
966  template void dafBase::PropertySet::add<t>(string const& name, vector<t> const& value);
967 
968 INSTANTIATE(bool)
969 INSTANTIATE(char)
970 INSTANTIATE(signed char)
971 INSTANTIATE(unsigned char)
972 INSTANTIATE(short)
973 INSTANTIATE(unsigned short)
974 INSTANTIATE(int)
975 INSTANTIATE(unsigned int)
976 INSTANTIATE(long)
977 INSTANTIATE(unsigned long)
978 INSTANTIATE(long long)
979 INSTANTIATE(unsigned long long)
980 INSTANTIATE(float)
981 INSTANTIATE(double)
982 INSTANTIATE(string)
986 
bool getAsBool(std::string const &name) const
Definition: PropertySet.cc:321
std::vector< std::string > paramNames(bool topLevelOnly=true) const
Definition: PropertySet.cc:142
Class for handling dates/times, including MJD, UTC, and TAI.
Definition: DateTime.h:58
void _cycleCheckPtr(Ptr const &v, std::string const &name)
Definition: PropertySet.cc:936
table::Key< std::string > name
Definition: ApCorrMap.cc:71
virtual void _add(std::string const &name, boost::shared_ptr< std::vector< boost::any > > vp)
Definition: PropertySet.cc:848
int64_t getAsInt64(std::string const &name) const
Definition: PropertySet.cc:372
Persistable::Ptr getAsPersistablePtr(std::string const &name) const
Definition: PropertySet.cc:466
bool isPropertySetPtr(std::string const &name) const
Definition: PropertySet.cc:207
virtual void remove(std::string const &name)
Definition: PropertySet.cc:754
size_t nameCount(bool topLevelOnly=true) const
Definition: PropertySet.cc:97
std::vector< std::string > propertySetNames(bool topLevelOnly=true) const
Definition: PropertySet.cc:168
virtual void copy(std::string const &dest, ConstPtr source, std::string const &name)
Definition: PropertySet.cc:713
void _cycleCheckPtrVec(std::vector< Ptr > const &v, std::string const &name)
Definition: PropertySet.cc:922
boost::shared_ptr< PropertySet > Ptr
Definition: PropertySet.h:90
boost::shared_ptr< PropertySet const > ConstPtr
Definition: PropertySet.h:91
PropertySet(bool flat=false)
Definition: PropertySet.cc:55
void set(std::string const &name, T const &value)
Definition: PropertySet.cc:581
std::vector< std::string > names(bool topLevelOnly=true) const
Definition: PropertySet.cc:117
size_t valueCount(std::string const &name) const
Definition: PropertySet.cc:216
bool isArray(std::string const &name) const
Definition: PropertySet.cc:198
lsst::daf::base::PropertySet PropertySet
Definition: Wcs.cc:58
bool any(CoordinateExpr< N > const &expr)
Return true if any elements are true.
int getAsInt(std::string const &name) const
Definition: PropertySet.cc:333
double w
Definition: CoaddPsf.cc:57
virtual void combine(ConstPtr source)
Definition: PropertySet.cc:738
boost::shared_ptr< Persistable > Ptr
Definition: Persistable.h:76
virtual std::string _format(std::string const &name) const
Definition: PropertySet.cc:507
T get(std::string const &name) const
Definition: PropertySet.cc:246
PropertySet::Ptr getAsPropertySetPtr(std::string const &name) const
Definition: PropertySet.cc:455
Interface for DateTime class.
virtual void _findOrInsert(std::string const &name, boost::shared_ptr< std::vector< boost::any > > vp)
Definition: PropertySet.cc:874
int x
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
#define INSTANTIATE(T)
std::type_info const & typeOf(std::string const &name) const
Definition: PropertySet.cc:227
double getAsDouble(std::string const &name) const
Definition: PropertySet.cc:406
Class for storing generic metadata.
Definition: PropertySet.h:82
virtual Ptr deepCopy(void) const
Definition: PropertySet.cc:70
virtual std::string toString(bool topLevelOnly=false, std::string const &indent="") const
Definition: PropertySet.cc:476
std::string getAsString(std::string const &name) const
Definition: PropertySet.cc:444
virtual void _set(std::string const &name, boost::shared_ptr< std::vector< boost::any > > vp)
Definition: PropertySet.cc:837
Interface for PropertySet class.
Base class for all persistable classes.
Definition: Persistable.h:74
void _cycleCheckAnyVec(std::vector< boost::any > const &v, std::string const &name)
Definition: PropertySet.cc:929
Citizen is a class that should be among all LSST classes base classes, and handles basic memory manag...
Definition: Citizen.h:56
AnyMap::iterator _find(std::string const &name)
Definition: PropertySet.cc:781
void add(std::string const &name, T const &value)
Definition: PropertySet.cc:619
std::vector< T > getArray(std::string const &name) const
bool exists(std::string const &name) const
Definition: PropertySet.cc:190