LSSTApplications  17.0+11,17.0+34,17.0+56,17.0+57,17.0+59,17.0+7,17.0-1-g377950a+33,17.0.1-1-g114240f+2,17.0.1-1-g4d4fbc4+28,17.0.1-1-g55520dc+49,17.0.1-1-g5f4ed7e+52,17.0.1-1-g6dd7d69+17,17.0.1-1-g8de6c91+11,17.0.1-1-gb9095d2+7,17.0.1-1-ge9fec5e+5,17.0.1-1-gf4e0155+55,17.0.1-1-gfc65f5f+50,17.0.1-1-gfc6fb1f+20,17.0.1-10-g87f9f3f+1,17.0.1-11-ge9de802+16,17.0.1-16-ga14f7d5c+4,17.0.1-17-gc79d625+1,17.0.1-17-gdae4c4a+8,17.0.1-2-g26618f5+29,17.0.1-2-g54f2ebc+9,17.0.1-2-gf403422+1,17.0.1-20-g2ca2f74+6,17.0.1-23-gf3eadeb7+1,17.0.1-3-g7e86b59+39,17.0.1-3-gb5ca14a,17.0.1-3-gd08d533+40,17.0.1-30-g596af8797,17.0.1-4-g59d126d+4,17.0.1-4-gc69c472+5,17.0.1-6-g5afd9b9+4,17.0.1-7-g35889ee+1,17.0.1-7-gc7c8782+18,17.0.1-9-gc4bbfb2+3,w.2019.22
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 
37 #include "lsst/daf/base/Citizen.h"
41 
42 namespace lsst {
43 namespace pex {
44 namespace policy {
45 
46 // forward declaration
47 class PolicySource;
48 class PolicyFile;
49 class Dictionary;
50 class ValidationError;
51 
52 #define POL_GETSCALAR(name, type, vtype) \
53  try { \
54  return _data->get<type>(name); \
55  } catch (lsst::pex::exceptions::NotFoundError&) { \
56  throw LSST_EXCEPT(NameNotFound, name); \
57  } catch (lsst::pex::exceptions::TypeError&) { \
58  throw LSST_EXCEPT(TypeError, name, std::string(typeName[vtype])); \
59  } catch (boost::bad_any_cast&) { \
60  throw LSST_EXCEPT(TypeError, name, std::string(typeName[vtype])); \
61  }
62 
63 #define POL_GETLIST(name, type, vtype) \
64  try { \
65  return _data->getArray<type>(name); \
66  } catch (lsst::pex::exceptions::NotFoundError&) { \
67  throw LSST_EXCEPT(NameNotFound, name); \
68  } catch (lsst::pex::exceptions::TypeError&) { \
69  throw LSST_EXCEPT(TypeError, name, std::string(typeName[vtype])); \
70  } catch (boost::bad_any_cast&) { \
71  throw LSST_EXCEPT(TypeError, name, std::string(typeName[vtype])); \
72  }
73 
74 
170 public:
171 
177 
185 
189  enum ValueType {
198  };
199 
205  static const char * const typeName[];
206 
210  Policy();
211 
213 
219  explicit Policy(const std::string& pathOrUrn);
220  explicit Policy(const char *pathOrUrn);
222 
227  explicit Policy(const PolicySource& source);
228 
242  Policy(bool validate, const Dictionary& dict,
243  const boost::filesystem::path& repository="");
244 
251  Policy(Policy& pol, bool deep=false);
252 
256  Policy(const Policy& pol);
257 
259 
274  static Policy *createPolicy(PolicySource& input, bool doIncludes=true,
275  bool validate=true);
276  static Policy *createPolicy(const std::string& input, bool doIncludes=true,
277  bool validate=true);
279 
294  static Policy *createPolicyFromUrn(const std::string& urn,
295  bool validate=true);
296 
298 
312  static Policy *createPolicy(PolicySource& input,
313  const boost::filesystem::path& repos,
314  bool validate=true);
315  static Policy *createPolicy(PolicySource& input, const std::string& repos,
316  bool validate=true);
317  static Policy *createPolicy(PolicySource& input, const char *repos,
318  bool validate=true);
319  static Policy *createPolicy(const std::string& input,
320  const boost::filesystem::path& repos,
321  bool validate=true);
322  static Policy *createPolicy(const std::string& input,
323  const std::string& repos, bool validate=true);
324  static Policy *createPolicy(const std::string& input, const char *repos,
325  bool validate=true);
327 
336  static FilePtr createPolicyFile(const std::string& pathOrUrn, bool strict=false);
337 
344  template <typename T> static ValueType getValueType();
345 
351  static ValueType getTypeByName(const std::string& name);
352  // throw(BadNameError) // swig doesn't like this
353 
357  virtual ~Policy();
358 
362  int nameCount() const {
363  return _data->nameCount();
364  }
365 
367 
384  bool topLevelOnly=false,
385  bool append=false) const; // inlined below
387  bool topLevelOnly=false,
388  bool append=false) const; // inlined below
390  bool topLevelOnly=false,
391  bool append=false) const; // inlined below
393  bool topLevelOnly=false,
394  bool append=false) const; // inlined below
396 
398 
409  StringArray names(bool topLevelOnly=false) const; // inlined below
410  StringArray paramNames(bool topLevelOnly=false) const; // inlined below
411  StringArray policyNames(bool topLevelOnly=false) const; // inlined below
412  StringArray fileNames(bool topLevelOnly=false) const; // inlined below
414 
419  bool isDictionary() const { return exists("definitions"); }
420 
426  bool canValidate() const;
427 
432  const ConstDictPtr getDictionary() const;
433 
439  void setDictionary(const Dictionary& dict);
440 
451  void validate(ValidationError *errs=0) const;
452 
458  size_t valueCount(const std::string& name) const; // inlined below
459 
467  bool isArray(const std::string& name) const; // inlined below
468 
476  bool exists(const std::string& name) const; // inlined below
477 
481  bool isBool(const std::string& name) const; // inlined below
482 
486  bool isInt(const std::string& name) const; // inlined below
487 
491  bool isDouble(const std::string& name) const; // inlined below
492 
496  bool isString(const std::string& name) const; // inlined below
497 
501  bool isPolicy(const std::string& name) const; // inlined below
502 
506  bool isFile(const std::string& name) const; // inlined below
507 
513  const std::type_info& getTypeInfo(const std::string& name) const; //inlined
514 
520  const std::type_info& typeOf(const std::string& name) const; // inlined
521 
527  ValueType getValueType(const std::string& name) const;
528 
534  const char *getTypeName(const std::string& name) const {
535  try { return typeName[getValueType(name)]; }
536  catch (NameNotFound&) { return typeName[UNDEF]; }
537  }
538 
545  template <typename T> T getValue(const std::string& name) const;
546 
553  template <typename T> std::vector<T> getValueArray(const std::string& name) const;
554 
556 
564  ConstPtr getPolicy(const std::string& name) const; // inlined below
565  Ptr getPolicy(const std::string& name); // inlined below
567 
577  FilePtr getFile(const std::string& name) const;
578 
589  bool getBool(const std::string& name) const {
590  POL_GETSCALAR(name, bool, BOOL)
591  }
592 
603  int getInt(const std::string& name) const {
604  POL_GETSCALAR(name, int, INT)
605  }
606 
617  double getDouble(const std::string& name) const {
618  POL_GETSCALAR(name, double, DOUBLE)
619  }
620 
631  const std::string getString(const std::string& name) const {
633  }
634 
636 
648  PolicyPtrArray getPolicyArray(const std::string& name) const;
649  ConstPolicyPtrArray getConstPolicyArray(const std::string& name) const;
651 
665  FilePtrArray getFileArray(const std::string& name) const;
666 
668 
676  BoolArray getBoolArray(const std::string& name) const; // inlined
677  IntArray getIntArray(const std::string& name) const; // inlined
678  DoubleArray getDoubleArray(const std::string& name) const; // inlined
679  StringArray getStringArray(const std::string& name) const; //inlined
681 
683 
708  template <typename T> void setValue(const std::string& name, const T& value);
709  void set(const std::string& name, const Ptr& value); // inlined below
710  void set(const std::string& name, const FilePtr& value); // inlined below
711  void set(const std::string& name, bool value); // inlined below
712  void set(const std::string& name, int value); // inlined below
713  void set(const std::string& name, double value); // inlined below
714  void set(const std::string& name, const std::string& value); // inlined
715  void set(const std::string& name, const char *value); // inlined below
717 
719 
744  // avoid name confusion with appended T
745  template <typename T> void addValue(const std::string& name, const T& value);
746  void add(const std::string& name, const Ptr& value); // inlined below
747  void add(const std::string& name, const FilePtr& value); // inlined below
748  void add(const std::string& name, bool value); // inlined below
749  void add(const std::string& name, int value); // inlined below
750  void add(const std::string& name, double value); // inlined below
751  void add(const std::string& name, const std::string& value); // inlined
752  void add(const std::string& name, const char *value); // inlined below
754 
760  void remove(const std::string& name); // inlined below
761 
775  int loadPolicyFiles(bool strict=true) {
776  return loadPolicyFiles(boost::filesystem::path(), strict);
777  }
778 
786  virtual int loadPolicyFiles(const boost::filesystem::path& repository,
787  bool strict=true);
788 
810  int mergeDefaults(const Policy& defaultPol, bool keepForValidation=true,
811  ValidationError *errs=0);
812 
821  virtual std::string str(const std::string& name,
822  const std::string& indent="") const;
823 
831  virtual void print(std::ostream& out, const std::string& label="Policy",
832  const std::string& indent="") const;
833 
838  std::string toString() const;
839 
845 
846 protected:
851  : Citizen(typeid(this)), lsst::daf::base::Persistable(), _data(ps)
852  { }
853 
854 private:
856 
857  DictPtr _dictionary;
858 
859  int _names(std::list<std::string>& names, bool topLevelOnly=false,
860  bool append=false, int want=3) const;
861  int _names(std::vector<std::string>& names, bool topLevelOnly=false,
862  bool append=false, int want=3) const;
863 
868  template <typename T>
869  void _validate(const std::string& name, const T& value, int curCount=0);
870 
872  _getPersistList(const std::string& name) const
873  {
874  POL_GETLIST(name, Persistable::Ptr, FILE)
875  }
877  _getPropSetList(const std::string& name) const
878  {
880  }
881 
882  static Policy *_createPolicy(PolicySource& input, bool doIncludes,
883  const boost::filesystem::path& repos,
884  bool validate);
885  static Policy *_createPolicy(const std::string& input, bool doIncludes,
886  const boost::filesystem::path& repos,
887  bool validate);
888 };
889 
891  p.print(os);
892  return os;
893 }
894 
895 /* ************** Inline Class functions ******************** */
896 
897 inline int Policy::names(std::list<std::string>& names, bool topLevelOnly,
898  bool append) const
899 {
900  return _names(names, topLevelOnly, append, 7);
901 }
902 inline int Policy::paramNames(std::list<std::string>& names, bool topLevelOnly,
903  bool append) const
904 {
905  return _names(names, topLevelOnly, append, 4);
906 }
908  bool topLevelOnly,
909  bool append) const
910 {
911  return _names(names, topLevelOnly, append, 1);
912 }
913 inline int Policy::fileNames(std::list<std::string>& names, bool topLevelOnly,
914  bool append) const
915 {
916  return _names(names, topLevelOnly, append, 2);
917 }
918 
919 inline Policy::StringArray Policy::names(bool topLevelOnly) const {
920  StringArray out;
921  _names(out, topLevelOnly, true, 7);
922  return out;
923 }
924 inline Policy::StringArray Policy::paramNames(bool topLevelOnly) const {
925  StringArray out;
926  _names(out, topLevelOnly, true, 4);
927  return out;
928 }
929 inline Policy::StringArray Policy::policyNames(bool topLevelOnly) const {
930  StringArray out;
931  _names(out, topLevelOnly, true, 1);
932  return out;
933 }
934 inline Policy::StringArray Policy::fileNames(bool topLevelOnly) const {
935  StringArray out;
936  _names(out, topLevelOnly, true, 2);
937  return out;
938 }
939 
940 inline size_t Policy::valueCount(const std::string& name) const {
941  return _data->valueCount(name);
942 }
943 
944 inline bool Policy::isArray(const std::string& name) const {
945  return _data->isArray(name);
946 }
947 
948 inline bool Policy::exists(const std::string& name) const {
949  return _data->exists(name);
950 }
951 
952 inline bool Policy::isBool(const std::string& name) const {
953  try {
954  return (_data->typeOf(name) == typeid(bool));
955  }
956  catch (...) {
957  return false;
958  }
959 }
960 
961 inline bool Policy::isInt(const std::string& name) const {
962  try {
963  return (_data->typeOf(name) == typeid(int));
964  }
965  catch (...) {
966  return false;
967  }
968 }
969 
970 inline bool Policy::isDouble(const std::string& name) const {
971  try {
972  return (_data->typeOf(name) == typeid(double));
973  }
974  catch (...) {
975  return false;
976  }
977 }
978 
979 inline bool Policy::isString(const std::string& name) const {
980  try {
981  return (_data->typeOf(name) == typeid(std::string));
982  }
983  catch (...) {
984  return false;
985  }
986 }
987 
988 inline bool Policy::isPolicy(const std::string& name) const {
989  try {
990  return _data->isPropertySetPtr(name);
991  }
992  catch (...) {
993  return false;
994  }
995 }
996 
997 inline bool Policy::isFile(const std::string& name) const {
998 
999  try {
1000  return (getValueType(name) == FILE);
1001  }
1002  catch (...) {
1003  return false;
1004  }
1005 }
1006 
1008 {
1009  try { return _data->typeOf(name); }
1011  throw LSST_EXCEPT(NameNotFound, name);
1012  }
1013 }
1014 
1015 inline const std::type_info& Policy::typeOf(const std::string& name) const {
1016  return getTypeInfo(name);
1017 }
1018 
1020  return ConstPtr(new Policy(_data->get<lsst::daf::base::PropertySet::Ptr>(name)));
1021 }
1023  return Ptr(new Policy(_data->get<lsst::daf::base::PropertySet::Ptr>(name)));
1024 }
1025 
1026 inline
1028  return _data->getArray<std::string>(name);
1029 }
1030 
1032  POL_GETLIST(name, bool, BOOL)
1033 }
1034 
1036  POL_GETLIST(name, int, INT)
1037 }
1038 
1039 inline
1041  POL_GETLIST(name, double, DOUBLE)
1042 }
1043 
1044 inline void Policy::set(const std::string& name, const Ptr& value) {
1045  _validate(name, value);
1046  _data->set(name, value->asPropertySet());
1047 }
1048 inline void Policy::set(const std::string& name, bool value) {
1049  _validate(name, value);
1050  _data->set(name, value);
1051 }
1052 inline void Policy::set(const std::string& name, int value) {
1053  _validate(name, value);
1054  _data->set(name, value);
1055 }
1056 inline void Policy::set(const std::string& name, double value) {
1057  _validate(name, value);
1058  _data->set(name, value);
1059 }
1060 inline void Policy::set(const std::string& name, const std::string& value) {
1061  _validate(name, value);
1062  _data->set(name, value);
1063 }
1064 inline void Policy::set(const std::string& name, const char *value) {
1065  if (value == NULL)
1067  std::string("Attempted to assign NULL value to ")
1068  + name + ".");
1069  _validate(name, std::string(value));
1070  _data->set(name, std::string(value));
1071 }
1072 
1073 #define POL_ADD(name, value) \
1074  try { _data->add(name, value); } \
1075  catch(lsst::pex::exceptions::TypeError&) { \
1076  throw LSST_EXCEPT(TypeError, name, getTypeName(name)); \
1077  }
1078 
1079 inline void Policy::add(const std::string& name, const Ptr& value) {
1080  _validate(name, value, valueCount(name));
1081  POL_ADD(name, value->asPropertySet())
1082 }
1083 inline void Policy::add(const std::string& name, bool value) {
1084  _validate(name, value, valueCount(name));
1085  POL_ADD(name, value);
1086 }
1087 inline void Policy::add(const std::string& name, int value) {
1088  _validate(name, value, valueCount(name));
1089  POL_ADD(name, value);
1090 }
1091 inline void Policy::add(const std::string& name, double value) {
1092  _validate(name, value, valueCount(name));
1093  POL_ADD(name, value);
1094 }
1095 inline void Policy::add(const std::string& name, const std::string& value) {
1096  _validate(name, value, valueCount(name));
1097  POL_ADD(name, value);
1098 }
1099 inline void Policy::add(const std::string& name, const char *value) {
1100  std::string v(value);
1101  _validate(name, v, valueCount(name));
1102  POL_ADD(name, v);
1103 }
1104 
1105 // TODO: validate if required value?
1106 inline void Policy::remove(const std::string& name) {
1107  _data->remove(name);
1108 }
1109 
1110 inline Policy* Policy::createPolicy(PolicySource& input, bool doIncludes,
1111  bool validate)
1112 {
1113  return _createPolicy(input, doIncludes, boost::filesystem::path(), validate);
1114 }
1115 
1116 inline Policy* Policy::createPolicy(const std::string& input, bool doIncludes,
1117  bool validate)
1118 {
1119  return _createPolicy(input, doIncludes, boost::filesystem::path(), validate);
1120 }
1121 
1123  const boost::filesystem::path& repository,
1124  bool validate)
1125 {
1126  return _createPolicy(input, true, repository, validate);
1127 }
1128 
1130  const std::string& repository,
1131  bool validate)
1132 {
1133  return _createPolicy(input, true, boost::filesystem::path(repository), validate);
1134 }
1135 
1137  const char *repository,
1138  bool validate)
1139 {
1140  return _createPolicy(input, true, boost::filesystem::path(repository), validate);
1141 }
1142 
1144  const boost::filesystem::path& repository,
1145  bool validate)
1146 {
1147  return _createPolicy(input, true, repository, validate);
1148 }
1149 
1151  const std::string& repository,
1152  bool validate)
1153 {
1154  return _createPolicy(input, true, boost::filesystem::path(repository), validate);
1155 }
1156 
1158  const char *repository,
1159  bool validate)
1160 {
1161  return _createPolicy(input, true, boost::filesystem::path(repository), validate);
1162 }
1163 
1165 
1166 // general case is disallowed; known types are specialized
1167 template <typename T> T Policy::getValue(const std::string& name) const {
1168  throw LSST_EXCEPT(TypeError, name, "not implemented for this type");
1169 }
1170 template <> bool Policy::getValue<bool>(const std::string& name) const;
1171 template <> int Policy::getValue<int>(const std::string& name) const;
1172 template <> double Policy::getValue<double>(const std::string& name) const;
1173 template <> std::string Policy::getValue<std::string>(const std::string& name) const;
1174 template <> Policy::FilePtr Policy::getValue<Policy::FilePtr>(const std::string& name) const;
1175 template <> Policy::ConstPtr Policy::getValue<Policy::ConstPtr>(const std::string& name) const;
1176 
1177 // general case is disallowed; known types are specialized
1178 template <typename T> std::vector<T> Policy::getValueArray(const std::string& name) const {
1179  throw LSST_EXCEPT(TypeError, name, "not implemented for this type");
1180 }
1181 template <> std::vector<bool> Policy::getValueArray<bool>(const std::string& name) const;
1182 template <> std::vector<int> Policy::getValueArray<int>(const std::string& name) const;
1183 template <> std::vector<double> Policy::getValueArray<double>(const std::string& name) const;
1184 template <> std::vector<std::string> Policy::getValueArray<std::string>(const std::string& name) const;
1185 template <> Policy::FilePtrArray Policy::getValueArray<Policy::FilePtr>(const std::string& name) const;
1186 template <> Policy::PolicyPtrArray Policy::getValueArray<Policy::Ptr>(const std::string& name) const;
1187 template <> Policy::ConstPolicyPtrArray Policy::getValueArray<Policy::ConstPtr>(const std::string& name) const;
1188 
1189 // general case is disallowed; known types are specialized
1190 template <typename T> Policy::ValueType Policy::getValueType() {
1191  throw LSST_EXCEPT(TypeError, "unknown", "not implemented for this type");
1192 }
1193 template <> Policy::ValueType Policy::getValueType<bool>();
1194 template <> Policy::ValueType Policy::getValueType<int>();
1195 template <> Policy::ValueType Policy::getValueType<double>();
1196 template <> Policy::ValueType Policy::getValueType<std::string>();
1197 template <> Policy::ValueType Policy::getValueType<Policy>();
1198 template <> Policy::ValueType Policy::getValueType<Policy::FilePtr>();
1199 template <> Policy::ValueType Policy::getValueType<Policy::Ptr>();
1200 template <> Policy::ValueType Policy::getValueType<Policy::ConstPtr>();
1201 
1202 // general case is disallowed; known types are specialized
1203 template <typename T> void Policy::setValue(const std::string& name, const T& value) {
1204  throw LSST_EXCEPT(TypeError, name, "not implemented for this type");
1205 }
1206 template <> void Policy::setValue<bool>(const std::string& name, const bool& value);
1207 template <> void Policy::setValue<int>(const std::string& name, const int& value);
1208 template <> void Policy::setValue<double>(const std::string& name, const double& value);
1209 template <> void Policy::setValue<std::string>(const std::string& name, const std::string& value);
1210 template <> void Policy::setValue<Policy::Ptr>(const std::string& name, const Policy::Ptr& value);
1211 template <> void Policy::setValue<Policy::FilePtr>(const std::string& name, const Policy::FilePtr& value);
1212 
1213 // general case is disallowed; known types are specialized
1214 template <typename T> void Policy::addValue(const std::string& name, const T& value) {
1215  throw LSST_EXCEPT(TypeError, name, "not implemented for this type");
1216 }
1217 template <> void Policy::addValue<bool>(const std::string& name, const bool& value);
1218 template <> void Policy::addValue<int>(const std::string& name, const int& value);
1219 template <> void Policy::addValue<double>(const std::string& name, const double& value);
1220 template <> void Policy::addValue<std::string>(const std::string& name, const std::string& value);
1221 template <> void Policy::addValue<Policy::Ptr>(const std::string& name, const Policy::Ptr& value);
1222 template <> void Policy::addValue<Policy::FilePtr>(const std::string& name, const Policy::FilePtr& value);
1223 
1224 }}} // end namespace lsst::pex::policy
1225 
1226 #endif // LSST_PEX_POLICY_POLICY_H
T getValue(const std::string &name) const
Template-ized version of getInt, getPolicy, etc.
Definition: Policy.h:1167
lsst::daf::base::PropertySet::Ptr asPropertySet()
return the internal policy data as a PropertySet pointer.
Definition: Policy.h:1164
void validate(ValidationError *errs=0) const
Validate this policy, using its stored dictionary.
std::vector< FilePtr > FilePtrArray
Definition: Policy.h:183
BoolArray getBoolArray(const std::string &name) const
return an array of values associated with the given name
Definition: Policy.h:1031
Interface for Persistable base class.
definition of Policy-specific exceptions classes
static FilePtr createPolicyFile(const std::string &pathOrUrn, bool strict=false)
Create a PolicyFile or UrnPolicyFile from pathOrUrn.
FilePtr getFile(const std::string &name) const
return a PolicyFile (a reference to a file with "sub-Policy" data) identified by a given name...
std::vector< bool > BoolArray
Definition: Policy.h:178
virtual ~Policy()
destroy this policy
bool isString(const std::string &name) const
return true if the value pointed to by the given name is a string
Definition: Policy.h:979
bool exists(const std::string &name) const
return true if a value exists in this policy for the given name.
Definition: Policy.h:948
std::shared_ptr< Dictionary > DictPtr
Definition: Policy.h:174
std::vector< std::string > StringArray
Definition: Policy.h:181
std::vector< double > DoubleArray
Definition: Policy.h:180
a container for holding hierarchical configuration data in memory.
Definition: Policy.h:169
void setDictionary(const Dictionary &dict)
Update this policy&#39;s dictionary that it uses to validate itself.
bool isPolicy(const std::string &name) const
return true if the value pointed to by the given name is a Policy
Definition: Policy.h:988
IntArray getIntArray(const std::string &name) const
return an array of values associated with the given name
Definition: Policy.h:1035
an exception indicating that a policy parameter of a given name can not be found in a Policy object...
Definition: exceptions.h:91
virtual std::string str(const std::string &name, const std::string &indent="") const
return a string representation of the value given by a name.
static Policy * createPolicyFromUrn(const std::string &urn, bool validate=true)
Create a Policy from a file specified by a URN.
std::shared_ptr< FrameSet > append(FrameSet const &first, FrameSet const &second)
Construct a FrameSet that performs two transformations in series.
Definition: functional.cc:33
std::vector< Ptr > PolicyPtrArray
Definition: Policy.h:182
const ConstDictPtr getDictionary() const
The dictionary (if any) that this policy uses to validate itself, including checking set() and add() ...
const std::string getString(const std::string &name) const
return a string value associated with the given name .
Definition: Policy.h:631
std::shared_ptr< PolicyFile > FilePtr
Definition: Policy.h:176
DoubleArray getDoubleArray(const std::string &name) const
return an array of values associated with the given name
Definition: Policy.h:1040
bool isDouble(const std::string &name) const
return true if the value pointed to by the given name is a double
Definition: Policy.h:970
std::ostream & operator<<(std::ostream &os, const Policy &p)
Definition: Policy.h:890
void addValue(const std::string &name, const T &value)
Add a value to an array of values with a given name.
Definition: Policy.h:1214
STL class.
an abstract class representing a source of serialized Policy parameter data.
Definition: PolicySource.h:53
Reports attempts to access elements using an invalid key.
Definition: Runtime.h:151
std::vector< ConstPtr > ConstPolicyPtrArray
Definition: Policy.h:184
std::shared_ptr< const Policy > ConstPtr
Definition: Policy.h:173
A base class for image defects.
int loadPolicyFiles(bool strict=true)
Recursively replace all PolicyFile values with the contents of the files they refer to...
Definition: Policy.h:775
Policy()
Create an empty policy.
#define POL_GETLIST(name, type, vtype)
Definition: Policy.h:63
#define POL_ADD(name, value)
Definition: Policy.h:1073
Policy(const lsst::daf::base::PropertySet::Ptr ps)
use a PropertySet as the data for a new Policy object
Definition: Policy.h:850
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:897
static ValueType getValueType()
A template-ized way to get the ValueType.
Definition: Policy.h:1190
std::shared_ptr< Policy > Ptr
Definition: Policy.h:172
#define POL_GETSCALAR(name, type, vtype)
Definition: Policy.h:52
std::string toString() const
convert the entire contents of this policy to a string.
const char * source()
Source function that allows astChannel to source from a Stream.
Definition: Stream.h:224
ConstPtr getPolicy(const std::string &name) const
return a "sub-Policy" identified by a given name.
Definition: Policy.h:1019
bool getBool(const std::string &name) const
return a boolean value associated with the given name.
Definition: Policy.h:589
double getDouble(const std::string &name) const
return a double value associated with the given name.
Definition: Policy.h:617
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:902
T get(T... args)
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
STL class.
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:907
bool isBool(const std::string &name) const
return true if the value pointed to by the given name is a boolean
Definition: Policy.h:952
PolicyPtrArray getPolicyArray(const std::string &name) const
return an array of Policy pointers associated with the given name.
Citizen(const std::type_info &)
Definition: Citizen.cc:163
std::vector< T > getValueArray(const std::string &name) const
Template-ized version of getIntArray, getPolicyPtrArray, etc.
Definition: Policy.h:1178
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.
bool isDictionary() const
return true if it appears that this Policy actually contains dictionary definition data...
Definition: Policy.h:419
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:1015
Persistable(void)
Default constructor.
Definition: Persistable.cc:45
static const char *const typeName[]
c-string forms for the supported value types.
Definition: Policy.h:205
Reports invalid arguments.
Definition: Runtime.h:66
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:913
int getInt(const std::string &name) const
return an integer value associated with the given name.
Definition: Policy.h:603
std::vector< int > IntArray
Definition: Policy.h:179
Base class for all persistable classes.
Definition: Persistable.h:75
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...
void set(const std::string &name, const Ptr &value)
Set a value with the given name.
Definition: Policy.h:1044
Citizen is a class that should be among all LSST classes base classes, and handles basic memory manag...
Definition: Citizen.h:55
void remove(const std::string &name)
Remove all values with a given name.
Definition: Policy.h:1106
void setValue(const std::string &name, const T &value)
Set a value with the given name.
Definition: Policy.h:1203
static ValueType getTypeByName(const std::string &name)
Given the human-readable name of a type ("bool", "int", "policy", etc), what is its ValueType (BOOL...
bool isInt(const std::string &name) const
return true if the value pointed to by the given name is an integer
Definition: Policy.h:961
an exception indicating that a policy parameter with a given name has a type different from the one t...
Definition: exceptions.h:109
bool canValidate() const
Can this policy validate itself – that is, does it have a dictionary that it can use to validate its...
ConstPolicyPtrArray getConstPolicyArray(const std::string &name) const
return an array of Policy pointers associated with the given name.
bool isFile(const std::string &name) const
return true if the value pointed to by the given name is a PolicyFile
Definition: Policy.h:997
STL class.
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:1007
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:534
StringArray getStringArray(const std::string &name) const
return an array of values associated with the given name
Definition: Policy.h:1027
std::shared_ptr< const Dictionary > ConstDictPtr
Definition: Policy.h:175
int nameCount() const
How many names of parameters does this policy file have?
Definition: Policy.h:362
FilePtrArray getFileArray(const std::string &name) const
return an array of PolicyFile pointers associated with the given name.
size_t valueCount(const std::string &name) const
return the number of values currently associated with a given name
Definition: Policy.h:940
std::ostream * os
Definition: Schema.cc:746
bool isArray(const std::string &name) const
return true if multiple values can be retrieved via the given name.
Definition: Policy.h:944
static Policy * createPolicy(PolicySource &input, bool doIncludes=true, bool validate=true)
create a Policy from a file.
Definition: Policy.h:1110
ValueType
an enumeration for the supported policy types
Definition: Policy.h:189
void add(const std::string &name, const Ptr &value)
Add a value to an array of values with a given name.
Definition: Policy.h:1079