LSSTApplications  19.0.0+10,19.0.0+80,19.0.0-1-g20d9b18+31,19.0.0-1-g49a97f9+4,19.0.0-1-g8c57eb9+31,19.0.0-1-g9a028c0+13,19.0.0-1-ga72da6b+3,19.0.0-1-gb77924a+15,19.0.0-1-gbfe0924+66,19.0.0-1-gc3516c3,19.0.0-1-gefe1d0d+49,19.0.0-1-gf8cb8b4+3,19.0.0-14-g7511ce4+6,19.0.0-16-g3dc1a33c+6,19.0.0-17-g59f0e8a+4,19.0.0-17-g9c22e3c+9,19.0.0-18-g35bb99870+2,19.0.0-19-g2772d4a+9,19.0.0-2-g260436e+53,19.0.0-2-g31cdcee,19.0.0-2-g9675b69+3,19.0.0-2-gaa2795f,19.0.0-2-gbcc4de1,19.0.0-2-gd6f004e+6,19.0.0-2-gde8e5e3+5,19.0.0-2-gff6972b+15,19.0.0-21-ge306cd8,19.0.0-21-gf122e69+2,19.0.0-3-g2d43a51+2,19.0.0-3-gf3b1435+6,19.0.0-4-g56feb96,19.0.0-4-gac56cce+17,19.0.0-49-gce872c1+1,19.0.0-5-g66946eb+6,19.0.0-5-gd8897ba+6,19.0.0-51-gfc4a647e,19.0.0-7-g686a884+5,19.0.0-7-g886f805+5,19.0.0-8-g305ff64,w.2020.17
LSSTDataManagementBasePackage
Policy.h
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 details.
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 #ifndef LSST_PEX_POLICY_POLICY_H
26 #define LSST_PEX_POLICY_POLICY_H
27 
28 #include <string>
29 #include <vector>
30 #include <list>
31 #include <map>
32 
33 #include <memory>
34 #include <boost/filesystem/path.hpp>
35 #include <boost/filesystem/operations.hpp>
36 
40 
41 namespace lsst {
42 namespace pex {
43 namespace policy {
44 
45 // forward declaration
46 class PolicySource;
47 class PolicyFile;
48 class Dictionary;
49 class ValidationError;
50 
51 #define POL_GETSCALAR(name, type, vtype) \
52  try { \
53  return _data->get<type>(name); \
54  } catch (lsst::pex::exceptions::NotFoundError&) { \
55  throw LSST_EXCEPT(NameNotFound, name); \
56  } catch (lsst::pex::exceptions::TypeError&) { \
57  throw LSST_EXCEPT(TypeError, name, std::string(typeName[vtype])); \
58  } catch (boost::bad_any_cast&) { \
59  throw LSST_EXCEPT(TypeError, name, std::string(typeName[vtype])); \
60  }
61 
62 #define POL_GETLIST(name, type, vtype) \
63  try { \
64  return _data->getArray<type>(name); \
65  } catch (lsst::pex::exceptions::NotFoundError&) { \
66  throw LSST_EXCEPT(NameNotFound, name); \
67  } catch (lsst::pex::exceptions::TypeError&) { \
68  throw LSST_EXCEPT(TypeError, name, std::string(typeName[vtype])); \
69  } catch (boost::bad_any_cast&) { \
70  throw LSST_EXCEPT(TypeError, name, std::string(typeName[vtype])); \
71  }
72 
168 public:
174 
182 
187 
193  static const char* const typeName[];
194 
198  Policy();
199 
201 
207  explicit Policy(const std::string& pathOrUrn);
208  explicit Policy(const char* pathOrUrn);
210 
215  explicit Policy(const PolicySource& source);
216 
230  Policy(bool validate, const Dictionary& dict, const boost::filesystem::path& repository = "");
231 
238  Policy(Policy& pol, bool deep = false);
239 
243  Policy(const Policy& pol);
244 
246 
261  static Policy* createPolicy(PolicySource& input, bool doIncludes = true, bool validate = true);
262  static Policy* createPolicy(const std::string& input, bool doIncludes = true, bool validate = true);
264 
279  static Policy* createPolicyFromUrn(const std::string& urn, bool validate = true);
280 
282 
296  static Policy* createPolicy(PolicySource& input, const boost::filesystem::path& repos,
297  bool validate = true);
298  static Policy* createPolicy(PolicySource& input, const std::string& repos, bool validate = true);
299  static Policy* createPolicy(PolicySource& input, const char* repos, bool validate = true);
300  static Policy* createPolicy(const std::string& input, const boost::filesystem::path& repos,
301  bool validate = true);
302  static Policy* createPolicy(const std::string& input, const std::string& repos, bool validate = true);
303  static Policy* createPolicy(const std::string& input, const char* repos, bool validate = true);
305 
314  static FilePtr createPolicyFile(const std::string& pathOrUrn, bool strict = false);
315 
322  template <typename T>
323  static ValueType getValueType();
324 
330  static ValueType getTypeByName(const std::string& name);
331  // throw(BadNameError) // swig doesn't like this
332 
336  virtual ~Policy();
337 
341  int nameCount() const { return _data->nameCount(); }
342 
344 
360  int names(std::list<std::string>& names, bool topLevelOnly = false,
361  bool append = false) const; // inlined below
362  int paramNames(std::list<std::string>& names, bool topLevelOnly = false,
363  bool append = false) const; // inlined below
364  int policyNames(std::list<std::string>& names, bool topLevelOnly = false,
365  bool append = false) const; // inlined below
366  int fileNames(std::list<std::string>& names, bool topLevelOnly = false,
367  bool append = false) const; // inlined below
369 
371 
382  StringArray names(bool topLevelOnly = false) const; // inlined below
383  StringArray paramNames(bool topLevelOnly = false) const; // inlined below
384  StringArray policyNames(bool topLevelOnly = false) const; // inlined below
385  StringArray fileNames(bool topLevelOnly = false) const; // inlined below
387 
392  bool isDictionary() const { return exists("definitions"); }
393 
399  bool canValidate() const;
400 
405  const ConstDictPtr getDictionary() const;
406 
412  void setDictionary(const Dictionary& dict);
413 
424  void validate(ValidationError* errs = 0) const;
425 
431  size_t valueCount(const std::string& name) const; // inlined below
432 
440  bool isArray(const std::string& name) const; // inlined below
441 
449  bool exists(const std::string& name) const; // inlined below
450 
454  bool isBool(const std::string& name) const; // inlined below
455 
459  bool isInt(const std::string& name) const; // inlined below
460 
464  bool isDouble(const std::string& name) const; // inlined below
465 
469  bool isString(const std::string& name) const; // inlined below
470 
474  bool isPolicy(const std::string& name) const; // inlined below
475 
479  bool isFile(const std::string& name) const; // inlined below
480 
486  const std::type_info& getTypeInfo(const std::string& name) const; // inlined
487 
493  const std::type_info& typeOf(const std::string& name) const; // inlined
494 
500  ValueType getValueType(const std::string& name) const;
501 
507  const char* getTypeName(const std::string& name) const {
508  try {
509  return typeName[getValueType(name)];
510  } catch (NameNotFound&) {
511  return typeName[UNDEF];
512  }
513  }
514 
521  template <typename T>
522  T getValue(const std::string& name) const;
523 
530  template <typename T>
531  std::vector<T> getValueArray(const std::string& name) const;
532 
534 
542  ConstPtr getPolicy(const std::string& name) const; // inlined below
543  Ptr getPolicy(const std::string& name); // inlined below
545 
555  FilePtr getFile(const std::string& name) const;
556 
567  bool getBool(const std::string& name) const { POL_GETSCALAR(name, bool, BOOL) }
568 
579  int getInt(const std::string& name) const { POL_GETSCALAR(name, int, INT) }
580 
591  double getDouble(const std::string& name) const { POL_GETSCALAR(name, double, DOUBLE) }
592 
604 
606 
618  PolicyPtrArray getPolicyArray(const std::string& name) const;
619  ConstPolicyPtrArray getConstPolicyArray(const std::string& name) const;
621 
635  FilePtrArray getFileArray(const std::string& name) const;
636 
638 
646  BoolArray getBoolArray(const std::string& name) const; // inlined
647  IntArray getIntArray(const std::string& name) const; // inlined
648  DoubleArray getDoubleArray(const std::string& name) const; // inlined
649  StringArray getStringArray(const std::string& name) const; // inlined
651 
653 
678  template <typename T>
679  void setValue(const std::string& name, const T& value);
680  void set(const std::string& name, const Ptr& value); // inlined below
681  void set(const std::string& name, const FilePtr& value); // inlined below
682  void set(const std::string& name, bool value); // inlined below
683  void set(const std::string& name, int value); // inlined below
684  void set(const std::string& name, double value); // inlined below
685  void set(const std::string& name, const std::string& value); // inlined
686  void set(const std::string& name, const char* value); // inlined below
688 
690 
715  // avoid name confusion with appended T
716  template <typename T>
717  void addValue(const std::string& name, const T& value);
718  void add(const std::string& name, const Ptr& value); // inlined below
719  void add(const std::string& name, const FilePtr& value); // inlined below
720  void add(const std::string& name, bool value); // inlined below
721  void add(const std::string& name, int value); // inlined below
722  void add(const std::string& name, double value); // inlined below
723  void add(const std::string& name, const std::string& value); // inlined
724  void add(const std::string& name, const char* value); // inlined below
726 
732  void remove(const std::string& name); // inlined below
733 
747  int loadPolicyFiles(bool strict = true) { return loadPolicyFiles(boost::filesystem::path(), strict); }
748 
756  virtual int loadPolicyFiles(const boost::filesystem::path& repository, bool strict = true);
757 
779  int mergeDefaults(const Policy& defaultPol, bool keepForValidation = true, ValidationError* errs = 0);
780 
789  virtual std::string str(const std::string& name, const std::string& indent = "") const;
790 
798  virtual void print(std::ostream& out, const std::string& label = "Policy",
799  const std::string& indent = "") const;
800 
805  std::string toString() const;
806 
812 
813 protected:
817  Policy(const lsst::daf::base::PropertySet::Ptr ps) : lsst::daf::base::Persistable(), _data(ps) {}
818 
819 private:
821 
822  DictPtr _dictionary;
823 
824  int _names(std::list<std::string>& names, bool topLevelOnly = false, bool append = false,
825  int want = 3) const;
826  int _names(std::vector<std::string>& names, bool topLevelOnly = false, bool append = false,
827  int want = 3) const;
828 
833  template <typename T>
834  void _validate(const std::string& name, const T& value, int curCount = 0);
835 
837  const {POL_GETLIST(name, Persistable::Ptr, FILE)} std::vector<
838  lsst::daf::base::PropertySet::Ptr> _getPropSetList(const std::string& name) const {
840  }
841 
842  static Policy* _createPolicy(PolicySource& input, bool doIncludes, const boost::filesystem::path& repos,
843  bool validate);
844  static Policy* _createPolicy(const std::string& input, bool doIncludes,
845  const boost::filesystem::path& repos, bool validate);
846 };
847 
849  p.print(os);
850  return os;
851 }
852 
853 /* ************** Inline Class functions ******************** */
854 
855 inline int Policy::names(std::list<std::string>& names, bool topLevelOnly, bool append) const {
856  return _names(names, topLevelOnly, append, 7);
857 }
858 inline int Policy::paramNames(std::list<std::string>& names, bool topLevelOnly, bool append) const {
859  return _names(names, topLevelOnly, append, 4);
860 }
861 inline int Policy::policyNames(std::list<std::string>& names, bool topLevelOnly, bool append) const {
862  return _names(names, topLevelOnly, append, 1);
863 }
864 inline int Policy::fileNames(std::list<std::string>& names, bool topLevelOnly, bool append) const {
865  return _names(names, topLevelOnly, append, 2);
866 }
867 
868 inline Policy::StringArray Policy::names(bool topLevelOnly) const {
869  StringArray out;
870  _names(out, topLevelOnly, true, 7);
871  return out;
872 }
873 inline Policy::StringArray Policy::paramNames(bool topLevelOnly) const {
874  StringArray out;
875  _names(out, topLevelOnly, true, 4);
876  return out;
877 }
878 inline Policy::StringArray Policy::policyNames(bool topLevelOnly) const {
879  StringArray out;
880  _names(out, topLevelOnly, true, 1);
881  return out;
882 }
883 inline Policy::StringArray Policy::fileNames(bool topLevelOnly) const {
884  StringArray out;
885  _names(out, topLevelOnly, true, 2);
886  return out;
887 }
888 
889 inline size_t Policy::valueCount(const std::string& name) const { return _data->valueCount(name); }
890 
891 inline bool Policy::isArray(const std::string& name) const { return _data->isArray(name); }
892 
893 inline bool Policy::exists(const std::string& name) const { return _data->exists(name); }
894 
895 inline bool Policy::isBool(const std::string& name) const {
896  try {
897  return (_data->typeOf(name) == typeid(bool));
898  } catch (...) {
899  return false;
900  }
901 }
902 
903 inline bool Policy::isInt(const std::string& name) const {
904  try {
905  return (_data->typeOf(name) == typeid(int));
906  } catch (...) {
907  return false;
908  }
909 }
910 
911 inline bool Policy::isDouble(const std::string& name) const {
912  try {
913  return (_data->typeOf(name) == typeid(double));
914  } catch (...) {
915  return false;
916  }
917 }
918 
919 inline bool Policy::isString(const std::string& name) const {
920  try {
921  return (_data->typeOf(name) == typeid(std::string));
922  } catch (...) {
923  return false;
924  }
925 }
926 
927 inline bool Policy::isPolicy(const std::string& name) const {
928  try {
929  return _data->isPropertySetPtr(name);
930  } catch (...) {
931  return false;
932  }
933 }
934 
935 inline bool Policy::isFile(const std::string& name) const {
936  try {
937  return (getValueType(name) == FILE);
938  } catch (...) {
939  return false;
940  }
941 }
942 
943 inline const std::type_info& Policy::getTypeInfo(const std::string& name) const {
944  try {
945  return _data->typeOf(name);
947  throw LSST_EXCEPT(NameNotFound, name);
948  }
949 }
950 
951 inline const std::type_info& Policy::typeOf(const std::string& name) const { return getTypeInfo(name); }
952 
954  return ConstPtr(new Policy(_data->get<lsst::daf::base::PropertySet::Ptr>(name)));
955 }
957  return Ptr(new Policy(_data->get<lsst::daf::base::PropertySet::Ptr>(name)));
958 }
959 
961  return _data->getArray<std::string>(name);
962 }
963 
965 
967 
969  POL_GETLIST(name, double, DOUBLE)
970 }
971 
972 inline void Policy::set(const std::string& name, const Ptr& value) {
973  _validate(name, value);
974  _data->set(name, value->asPropertySet());
975 }
976 inline void Policy::set(const std::string& name, bool value) {
977  _validate(name, value);
978  _data->set(name, value);
979 }
980 inline void Policy::set(const std::string& name, int value) {
981  _validate(name, value);
982  _data->set(name, value);
983 }
984 inline void Policy::set(const std::string& name, double value) {
985  _validate(name, value);
986  _data->set(name, value);
987 }
988 inline void Policy::set(const std::string& name, const std::string& value) {
989  _validate(name, value);
990  _data->set(name, value);
991 }
992 inline void Policy::set(const std::string& name, const char* value) {
993  if (value == NULL)
995  std::string("Attempted to assign NULL value to ") + name + ".");
996  _validate(name, std::string(value));
997  _data->set(name, std::string(value));
998 }
999 
1000 #define POL_ADD(name, value) \
1001  try { \
1002  _data->add(name, value); \
1003  } catch (lsst::pex::exceptions::TypeError&) { \
1004  throw LSST_EXCEPT(TypeError, name, getTypeName(name)); \
1005  }
1006 
1007 inline void Policy::add(const std::string& name, const Ptr& value) {
1008  _validate(name, value, valueCount(name));
1009  POL_ADD(name, value->asPropertySet())
1010 }
1011 inline void Policy::add(const std::string& name, bool value) {
1012  _validate(name, value, valueCount(name));
1013  POL_ADD(name, value);
1014 }
1015 inline void Policy::add(const std::string& name, int value) {
1016  _validate(name, value, valueCount(name));
1017  POL_ADD(name, value);
1018 }
1019 inline void Policy::add(const std::string& name, double value) {
1020  _validate(name, value, valueCount(name));
1021  POL_ADD(name, value);
1022 }
1023 inline void Policy::add(const std::string& name, const std::string& value) {
1024  _validate(name, value, valueCount(name));
1025  POL_ADD(name, value);
1026 }
1027 inline void Policy::add(const std::string& name, const char* value) {
1028  std::string v(value);
1029  _validate(name, v, valueCount(name));
1030  POL_ADD(name, v);
1031 }
1032 
1033 // TODO: validate if required value?
1034 inline void Policy::remove(const std::string& name) { _data->remove(name); }
1035 
1036 inline Policy* Policy::createPolicy(PolicySource& input, bool doIncludes, bool validate) {
1037  return _createPolicy(input, doIncludes, boost::filesystem::path(), validate);
1038 }
1039 
1040 inline Policy* Policy::createPolicy(const std::string& input, bool doIncludes, bool validate) {
1041  return _createPolicy(input, doIncludes, boost::filesystem::path(), validate);
1042 }
1043 
1044 inline Policy* Policy::createPolicy(PolicySource& input, const boost::filesystem::path& repository,
1045  bool validate) {
1046  return _createPolicy(input, true, repository, validate);
1047 }
1048 
1049 inline Policy* Policy::createPolicy(PolicySource& input, const std::string& repository, bool validate) {
1050  return _createPolicy(input, true, boost::filesystem::path(repository), validate);
1051 }
1052 
1053 inline Policy* Policy::createPolicy(PolicySource& input, const char* repository, bool validate) {
1054  return _createPolicy(input, true, boost::filesystem::path(repository), validate);
1055 }
1056 
1057 inline Policy* Policy::createPolicy(const std::string& input, const boost::filesystem::path& repository,
1058  bool validate) {
1059  return _createPolicy(input, true, repository, validate);
1060 }
1061 
1062 inline Policy* Policy::createPolicy(const std::string& input, const std::string& repository, bool validate) {
1063  return _createPolicy(input, true, boost::filesystem::path(repository), validate);
1064 }
1065 
1066 inline Policy* Policy::createPolicy(const std::string& input, const char* repository, bool validate) {
1067  return _createPolicy(input, true, boost::filesystem::path(repository), validate);
1068 }
1069 
1071 
1072 // general case is disallowed; known types are specialized
1073 template <typename T>
1074 T Policy::getValue(const std::string& name) const {
1075  throw LSST_EXCEPT(TypeError, name, "not implemented for this type");
1076 }
1077 template <>
1078 bool Policy::getValue<bool>(const std::string& name) const;
1079 template <>
1080 int Policy::getValue<int>(const std::string& name) const;
1081 template <>
1082 double Policy::getValue<double>(const std::string& name) const;
1083 template <>
1084 std::string Policy::getValue<std::string>(const std::string& name) const;
1085 template <>
1086 Policy::FilePtr Policy::getValue<Policy::FilePtr>(const std::string& name) const;
1087 template <>
1088 Policy::ConstPtr Policy::getValue<Policy::ConstPtr>(const std::string& name) const;
1089 
1090 // general case is disallowed; known types are specialized
1091 template <typename T>
1093  throw LSST_EXCEPT(TypeError, name, "not implemented for this type");
1094 }
1095 template <>
1096 std::vector<bool> Policy::getValueArray<bool>(const std::string& name) const;
1097 template <>
1098 std::vector<int> Policy::getValueArray<int>(const std::string& name) const;
1099 template <>
1100 std::vector<double> Policy::getValueArray<double>(const std::string& name) const;
1101 template <>
1102 std::vector<std::string> Policy::getValueArray<std::string>(const std::string& name) const;
1103 template <>
1104 Policy::FilePtrArray Policy::getValueArray<Policy::FilePtr>(const std::string& name) const;
1105 template <>
1106 Policy::PolicyPtrArray Policy::getValueArray<Policy::Ptr>(const std::string& name) const;
1107 template <>
1108 Policy::ConstPolicyPtrArray Policy::getValueArray<Policy::ConstPtr>(const std::string& name) const;
1109 
1110 // general case is disallowed; known types are specialized
1111 template <typename T>
1113  throw LSST_EXCEPT(TypeError, "unknown", "not implemented for this type");
1114 }
1115 template <>
1116 Policy::ValueType Policy::getValueType<bool>();
1117 template <>
1118 Policy::ValueType Policy::getValueType<int>();
1119 template <>
1120 Policy::ValueType Policy::getValueType<double>();
1121 template <>
1122 Policy::ValueType Policy::getValueType<std::string>();
1123 template <>
1124 Policy::ValueType Policy::getValueType<Policy>();
1125 template <>
1126 Policy::ValueType Policy::getValueType<Policy::FilePtr>();
1127 template <>
1128 Policy::ValueType Policy::getValueType<Policy::Ptr>();
1129 template <>
1130 Policy::ValueType Policy::getValueType<Policy::ConstPtr>();
1131 
1132 // general case is disallowed; known types are specialized
1133 template <typename T>
1134 void Policy::setValue(const std::string& name, const T& value) {
1135  throw LSST_EXCEPT(TypeError, name, "not implemented for this type");
1136 }
1137 template <>
1138 void Policy::setValue<bool>(const std::string& name, const bool& value);
1139 template <>
1140 void Policy::setValue<int>(const std::string& name, const int& value);
1141 template <>
1142 void Policy::setValue<double>(const std::string& name, const double& value);
1143 template <>
1144 void Policy::setValue<std::string>(const std::string& name, const std::string& value);
1145 template <>
1146 void Policy::setValue<Policy::Ptr>(const std::string& name, const Policy::Ptr& value);
1147 template <>
1148 void Policy::setValue<Policy::FilePtr>(const std::string& name, const Policy::FilePtr& value);
1149 
1150 // general case is disallowed; known types are specialized
1151 template <typename T>
1152 void Policy::addValue(const std::string& name, const T& value) {
1153  throw LSST_EXCEPT(TypeError, name, "not implemented for this type");
1154 }
1155 template <>
1156 void Policy::addValue<bool>(const std::string& name, const bool& value);
1157 template <>
1158 void Policy::addValue<int>(const std::string& name, const int& value);
1159 template <>
1160 void Policy::addValue<double>(const std::string& name, const double& value);
1161 template <>
1162 void Policy::addValue<std::string>(const std::string& name, const std::string& value);
1163 template <>
1164 void Policy::addValue<Policy::Ptr>(const std::string& name, const Policy::Ptr& value);
1165 template <>
1166 void Policy::addValue<Policy::FilePtr>(const std::string& name, const Policy::FilePtr& value);
1167 
1168 } // namespace policy
1169 } // namespace pex
1170 } // namespace lsst
1171 
1172 #endif // LSST_PEX_POLICY_POLICY_H
std::vector< int > IntArray
Definition: Policy.h:176
bool isDictionary() const
return true if it appears that this Policy actually contains dictionary definition data...
Definition: Policy.h:392
std::shared_ptr< PolicyFile > FilePtr
Definition: Policy.h:173
std::shared_ptr< Policy > Ptr
Definition: Policy.h:169
void set(const std::string &name, const Ptr &value)
Set a value with the given name.
Definition: Policy.h:972
std::vector< Ptr > PolicyPtrArray
Definition: Policy.h:179
bool isString(const std::string &name) const
return true if the value pointed to by the given name is a string
Definition: Policy.h:919
static Policy * createPolicyFromUrn(const std::string &urn, bool validate=true)
Create a Policy from a file specified by a URN.
const ConstDictPtr getDictionary() const
The dictionary (if any) that this policy uses to validate itself, including checking set() and add() ...
static Policy * createPolicy(PolicySource &input, bool doIncludes=true, bool validate=true)
create a Policy from a file.
Definition: Policy.h:1036
bool isInt(const std::string &name) const
return true if the value pointed to by the given name is an integer
Definition: Policy.h:903
size_t valueCount(const std::string &name) const
return the number of values currently associated with a given name
Definition: Policy.h:889
bool canValidate() const
Can this policy validate itself – that is, does it have a dictionary that it can use to validate its...
int policyNames(std::list< std::string > &names, bool topLevelOnly=false, bool append=false) const
load the names of parameters into a given list.
Definition: Policy.h:861
lsst::daf::base::PropertySet::Ptr asPropertySet()
return the internal policy data as a PropertySet pointer.
Definition: Policy.h:1070
a container for holding hierarchical configuration data in memory.
Definition: Policy.h:167
std::shared_ptr< const Dictionary > ConstDictPtr
Definition: Policy.h:172
std::vector< T > getValueArray(const std::string &name) const
Template-ized version of getIntArray, getPolicyPtrArray, etc.
Definition: Policy.h:1092
const std::type_info & typeOf(const std::string &name) const
return the type information for the underlying type associated with a given name. ...
Definition: Policy.h:951
FilePtrArray getFileArray(const std::string &name) const
return an array of PolicyFile pointers associated with the given name.
void setDictionary(const Dictionary &dict)
Update this policy&#39;s dictionary that it uses to validate itself.
an exception indicating that a policy parameter of a given name can not be found in a Policy object...
Definition: exceptions.h:83
PolicyPtrArray getPolicyArray(const std::string &name) const
return an array of Policy pointers associated with the given name.
void validate(ValidationError *errs=0) const
Validate this policy, using its stored dictionary.
std::shared_ptr< FrameSet > append(FrameSet const &first, FrameSet const &second)
Construct a FrameSet that performs two transformations in series.
Definition: functional.cc:33
static const char *const typeName[]
c-string forms for the supported value types.
Definition: Policy.h:193
bool isFile(const std::string &name) const
return true if the value pointed to by the given name is a PolicyFile
Definition: Policy.h:935
DoubleArray getDoubleArray(const std::string &name) const
return an array of values associated with the given name
Definition: Policy.h:968
std::shared_ptr< Dictionary > DictPtr
Definition: Policy.h:171
std::ostream & operator<<(std::ostream &os, const Policy &p)
Definition: Policy.h:848
FilePtr getFile(const std::string &name) const
return a PolicyFile (a reference to a file with "sub-Policy" data) identified by a given name...
definition of Policy-specific exceptions classes
int paramNames(std::list< std::string > &names, bool topLevelOnly=false, bool append=false) const
load the names of parameters into a given list.
Definition: Policy.h:858
STL class.
StringArray getStringArray(const std::string &name) const
return an array of values associated with the given name
Definition: Policy.h:960
an abstract class representing a source of serialized Policy parameter data.
Definition: PolicySource.h:52
bool getBool(const std::string &name) const
return a boolean value associated with the given name.
Definition: Policy.h:567
Reports attempts to access elements using an invalid key.
Definition: Runtime.h:151
static FilePtr createPolicyFile(const std::string &pathOrUrn, bool strict=false)
Create a PolicyFile or UrnPolicyFile from pathOrUrn.
A base class for image defects.
bool exists(const std::string &name) const
return true if a value exists in this policy for the given name.
Definition: Policy.h:893
std::vector< std::string > StringArray
Definition: Policy.h:178
#define POL_GETLIST(name, type, vtype)
Definition: Policy.h:62
ConstPtr getPolicy(const std::string &name) const
return a "sub-Policy" identified by a given name.
Definition: Policy.h:953
#define POL_ADD(name, value)
Definition: Policy.h:1000
int getInt(const std::string &name) const
return an integer value associated with the given name.
Definition: Policy.h:579
T getValue(const std::string &name) const
Template-ized version of getInt, getPolicy, etc.
Definition: Policy.h:1074
bool isArray(const std::string &name) const
return true if multiple values can be retrieved via the given name.
Definition: Policy.h:891
int fileNames(std::list< std::string > &names, bool topLevelOnly=false, bool append=false) const
load the names of parameters into a given list.
Definition: Policy.h:864
void addValue(const std::string &name, const T &value)
Add a value to an array of values with a given name.
Definition: Policy.h:1152
#define POL_GETSCALAR(name, type, vtype)
Definition: Policy.h:51
const char * source()
Source function that allows astChannel to source from a Stream.
Definition: Stream.h:224
bool isDouble(const std::string &name) const
return true if the value pointed to by the given name is a double
Definition: Policy.h:911
const std::string getString(const std::string &name) const
return a string value associated with the given name .
Definition: Policy.h:603
void setValue(const std::string &name, const T &value)
Set a value with the given name.
Definition: Policy.h:1134
int mergeDefaults(const Policy &defaultPol, bool keepForValidation=true, ValidationError *errs=0)
use the values found in the given policy as default values for parameters not specified in this polic...
bool isPolicy(const std::string &name) const
return true if the value pointed to by the given name is a Policy
Definition: Policy.h:927
Interface for Persistable base class.
Policy(const lsst::daf::base::PropertySet::Ptr ps)
use a PropertySet as the data for a new Policy object
Definition: Policy.h:817
double getDouble(const std::string &name) const
return a double value associated with the given name.
Definition: Policy.h:591
T get(T... args)
BoolArray getBoolArray(const std::string &name) const
return an array of values associated with the given name
Definition: Policy.h:964
Definition: __init__.py:1
Definition: __init__.py:1
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
std::vector< FilePtr > FilePtrArray
Definition: Policy.h:180
STL class.
bool isBool(const std::string &name) const
return true if the value pointed to by the given name is a boolean
Definition: Policy.h:895
const char * getTypeName(const std::string &name) const
return a string name for the type associated with the parameter of a given name.
Definition: Policy.h:507
int names(std::list< std::string > &names, bool topLevelOnly=false, bool append=false) const
load the names of parameters into a given list.
Definition: Policy.h:855
std::vector< double > DoubleArray
Definition: Policy.h:177
virtual void print(std::ostream &out, const std::string &label="Policy", const std::string &indent="") const
print the contents of this policy to an output stream.
void remove(const std::string &name)
Remove all values with a given name.
Definition: Policy.h:1034
const std::type_info & getTypeInfo(const std::string &name) const
return the type information for the underlying type associated with a given name. ...
Definition: Policy.h:943
Persistable(void)
Default constructor.
Definition: Persistable.cc:45
static ValueType getTypeByName(const std::string &name)
Given the human-readable name of a type ("bool", "int", "policy", etc), what is its ValueType (BOOL...
Reports invalid arguments.
Definition: Runtime.h:66
static ValueType getValueType()
A template-ized way to get the ValueType.
Definition: Policy.h:1112
Base class for all persistable classes.
Definition: Persistable.h:75
virtual std::string str(const std::string &name, const std::string &indent="") const
return a string representation of the value given by a name.
int loadPolicyFiles(bool strict=true)
Recursively replace all PolicyFile values with the contents of the files they refer to...
Definition: Policy.h:747
std::vector< bool > BoolArray
Definition: Policy.h:175
an exception indicating that a policy parameter with a given name has a type different from the one t...
Definition: exceptions.h:98
std::ostream * os
Definition: Schema.cc:746
ConstPolicyPtrArray getConstPolicyArray(const std::string &name) const
return an array of Policy pointers associated with the given name.
STL class.
std::string toString() const
convert the entire contents of this policy to a string.
void add(const std::string &name, const Ptr &value)
Add a value to an array of values with a given name.
Definition: Policy.h:1007
int nameCount() const
How many names of parameters does this policy file have?
Definition: Policy.h:341
std::shared_ptr< const Policy > ConstPtr
Definition: Policy.h:170
IntArray getIntArray(const std::string &name) const
return an array of values associated with the given name
Definition: Policy.h:966
Policy()
Create an empty policy.
std::vector< ConstPtr > ConstPolicyPtrArray
Definition: Policy.h:181
ValueType
an enumeration for the supported policy types
Definition: Policy.h:186
virtual ~Policy()
destroy this policy