25 #ifndef LSST_PEX_POLICY_POLICY_H
26 #define LSST_PEX_POLICY_POLICY_H
33 #include <boost/shared_ptr.hpp>
34 #include <boost/filesystem/path.hpp>
35 #include <boost/filesystem/operations.hpp>
50 class ValidationError;
52 #define POL_GETSCALAR(name, type, vtype) \
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])); \
63 #define POL_GETLIST(name, type, vtype) \
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])); \
172 typedef boost::shared_ptr<Policy>
Ptr;
174 typedef boost::shared_ptr<Dictionary>
DictPtr;
176 typedef boost::shared_ptr<PolicyFile>
FilePtr;
219 explicit Policy(
const std::string& pathOrUrn);
220 explicit Policy(
const char *pathOrUrn);
243 const boost::filesystem::path& repository=
"");
313 const boost::filesystem::path& repos,
320 const boost::filesystem::path& repos,
323 const std::string& repos,
bool validate=
true);
363 return _data->nameCount();
384 bool topLevelOnly=
false,
385 bool append=
false)
const;
387 bool topLevelOnly=
false,
388 bool append=
false)
const;
390 bool topLevelOnly=
false,
391 bool append=
false)
const;
393 bool topLevelOnly=
false,
394 bool append=
false)
const;
451 void validate(ValidationError *errs=0)
const;
486 bool isInt(
const std::string&
name)
const;
520 const std::type_info&
typeOf(
const std::string&
name)
const;
545 template <
typename T> T
getValue(
const std::string&
name)
const;
553 template <
typename T> std::vector<T>
getValueArray(
const std::string&
name)
const;
708 template <
typename T>
void setValue(
const std::string&
name,
const T& value);
709 void set(
const std::string&
name,
const Ptr& value);
711 void set(
const std::string&
name,
bool value);
712 void set(
const std::string&
name,
int value);
713 void set(
const std::string&
name,
double value);
714 void set(
const std::string&
name,
const std::string& value);
715 void set(
const std::string&
name,
const char *value);
745 template <
typename T>
void addValue(
const std::string&
name,
const T& value);
746 void add(
const std::string&
name,
const Ptr& value);
748 void add(
const std::string&
name,
bool value);
749 void add(
const std::string&
name,
int value);
750 void add(
const std::string&
name,
double value);
751 void add(
const std::string&
name,
const std::string& value);
752 void add(
const std::string&
name,
const char *value);
760 void remove(
const std::string&
name);
811 ValidationError *errs=0);
821 virtual std::string
str(
const std::string&
name,
822 const std::string& indent=
"")
const;
831 virtual void print(std::ostream& out,
const std::string& label=
"Policy",
832 const std::string& indent=
"")
const;
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;
868 template <
typename T>
869 void _validate(
const std::string&
name,
const T& value,
int curCount=0);
871 std::vector<lsst::daf::base::Persistable::Ptr>
876 std::vector<lsst::daf::base::PropertySet::Ptr>
883 const boost::filesystem::path& repos,
886 const boost::filesystem::path& repos,
900 return _names(names, topLevelOnly, append, 7);
905 return _names(names, topLevelOnly, append, 4);
911 return _names(names, topLevelOnly, append, 1);
916 return _names(names, topLevelOnly, append, 2);
920 return _data->names();
924 _names(out, topLevelOnly,
true, 4);
928 return _data->propertySetNames(topLevelOnly);
932 _names(out, topLevelOnly,
true, 2);
937 return _data->valueCount(name);
941 return _data->isArray(name);
945 return _data->exists(name);
950 return (
_data->typeOf(name) ==
typeid(bool));
959 return (
_data->typeOf(name) ==
typeid(int));
968 return (
_data->typeOf(name) ==
typeid(double));
977 return (
_data->typeOf(name) ==
typeid(std::string));
1005 try {
return _data->typeOf(name); }
1006 catch (lsst::pex::exceptions::NotFoundError& e) {
1024 return _data->getArray<std::string>(
name);
1042 _data->set(name, value->asPropertySet());
1046 _data->set(name, value);
1050 _data->set(name, value);
1054 _data->set(name, value);
1058 _data->set(name, value);
1062 throw LSST_EXCEPT(lsst::pex::exceptions::InvalidParameterError,
1063 std::string(
"Attempted to assign NULL value to ")
1066 _data->set(name, std::string(value));
1069 #define POL_ADD(name, value) \
1070 try { _data->add(name, value); } \
1071 catch(lsst::pex::exceptions::TypeError&) { \
1072 throw LSST_EXCEPT(TypeError, name, getTypeName(name)); \
1077 POL_ADD(name, value->asPropertySet())
1091 inline void Policy::add(
const std::string& name,
const std::string& value) {
1096 std::string v(value);
1103 _data->remove(name);
1109 return _createPolicy(input, doIncludes, boost::filesystem::path(), validate);
1115 return _createPolicy(input, doIncludes, boost::filesystem::path(), validate);
1119 const boost::filesystem::path& repository,
1126 const std::string& repository,
1129 return _createPolicy(input,
true, boost::filesystem::path(repository), validate);
1133 const char *repository,
1136 return _createPolicy(input,
true, boost::filesystem::path(repository), validate);
1140 const boost::filesystem::path& repository,
1147 const std::string& repository,
1150 return _createPolicy(input,
true, boost::filesystem::path(repository), validate);
1154 const char *repository,
1157 return _createPolicy(input,
true, boost::filesystem::path(repository), validate);
1166 template <>
bool Policy::getValue<bool>(
const std::string&
name)
const;
1167 template <>
int Policy::getValue<int>(
const std::string&
name)
const;
1168 template <>
double Policy::getValue<double>(
const std::string&
name)
const;
1169 template <> std::string Policy::getValue<std::string>(
const std::string&
name)
const;
1170 template <>
Policy::FilePtr Policy::getValue<Policy::FilePtr>(
const std::string&
name)
const;
1171 template <>
Policy::ConstPtr Policy::getValue<Policy::ConstPtr>(
const std::string&
name)
const;
1177 template <> std::vector<bool> Policy::getValueArray<bool>(
const std::string&
name)
const;
1178 template <> std::vector<int> Policy::getValueArray<int>(
const std::string&
name)
const;
1179 template <> std::vector<double> Policy::getValueArray<double>(
const std::string&
name)
const;
1180 template <> std::vector<std::string> Policy::getValueArray<std::string>(
const std::string&
name)
const;
1202 template <>
void Policy::setValue<bool>(
const std::string&
name,
const bool& value);
1203 template <>
void Policy::setValue<int>(
const std::string&
name,
const int& value);
1204 template <>
void Policy::setValue<double>(
const std::string&
name,
const double& value);
1205 template <>
void Policy::setValue<std::string>(
const std::string&
name,
const std::string& value);
1206 template <>
void Policy::setValue<Policy::Ptr>(
const std::string&
name,
const Policy::Ptr& value);
1207 template <>
void Policy::setValue<Policy::FilePtr>(
const std::string&
name,
const Policy::FilePtr& value);
1213 template <>
void Policy::addValue<bool>(
const std::string&
name,
const bool& value);
1214 template <>
void Policy::addValue<int>(
const std::string&
name,
const int& value);
1215 template <>
void Policy::addValue<double>(
const std::string&
name,
const double& value);
1216 template <>
void Policy::addValue<std::string>(
const std::string&
name,
const std::string& value);
1217 template <>
void Policy::addValue<Policy::Ptr>(
const std::string&
name,
const Policy::Ptr& value);
1218 template <>
void Policy::addValue<Policy::FilePtr>(
const std::string&
name,
const Policy::FilePtr& value);
1222 #endif // LSST_PEX_POLICY_POLICY_H
void addValue(const std::string &name, const T &value)
static Policy * createPolicy(PolicySource &input, bool doIncludes=true, bool validate=true)
ConstPolicyPtrArray getConstPolicyArray(const std::string &name) const
StringArray getStringArray(const std::string &name) const
int paramNames(std::list< std::string > &names, bool topLevelOnly=false, bool append=false) const
boost::shared_ptr< const Dictionary > ConstDictPtr
std::vector< bool > BoolArray
table::Key< std::string > name
boost::shared_ptr< PolicyFile > FilePtr
T getValue(const std::string &name) const
std::vector< std::string > StringArray
static FilePtr createPolicyFile(const std::string &pathOrUrn, bool strict=false)
#define POL_ADD(name, value)
definition of Policy-specific exceptions classes
ConstPtr getPolicy(const std::string &name) const
IntArray getIntArray(const std::string &name) const
bool isInt(const std::string &name) const
int names(std::list< std::string > &names, bool topLevelOnly=false, bool append=false) const
FilePtr getFile(const std::string &name) const
bool isArray(const std::string &name) const
bool isPolicy(const std::string &name) const
int _names(std::list< std::string > &names, bool topLevelOnly=false, bool append=false, int want=3) const
a container for holding hierarchical configuration data in memory.
boost::shared_ptr< PropertySet > Ptr
const std::string getString(const std::string &name) const
virtual std::string str(const std::string &name, const std::string &indent="") const
const std::type_info & getTypeInfo(const std::string &name) const
PolicyPtrArray getPolicyArray(const std::string &name) const
void set(const std::string &name, const Ptr &value)
boost::shared_ptr< Policy > Ptr
Policy(const lsst::daf::base::PropertySet::Ptr ps)
double getDouble(const std::string &name) const
int getInt(const std::string &name) const
void remove(const std::string &name)
static ValueType getTypeByName(const std::string &name)
std::vector< FilePtr > FilePtrArray
static Policy * createPolicyFromUrn(const std::string &urn, bool validate=true)
std::ostream & operator<<(std::ostream &os, const Policy &p)
DoubleArray getDoubleArray(const std::string &name) const
std::vector< Ptr > PolicyPtrArray
const std::type_info & typeOf(const std::string &name) const
std::vector< int > IntArray
an abstract class representing a source of serialized Policy parameter data. This might be a file or ...
void add(const std::string &name, const Ptr &value)
static const char *const typeName[]
int mergeDefaults(const Policy &defaultPol, bool keepForValidation=true, ValidationError *errs=0)
std::vector< lsst::daf::base::Persistable::Ptr > _getPersistList(const std::string &name) const
static Policy * _createPolicy(PolicySource &input, bool doIncludes, const boost::filesystem::path &repos, bool validate)
std::vector< T > getValueArray(const std::string &name) const
#define POL_GETSCALAR(name, type, vtype)
boost::shared_ptr< Persistable > Ptr
std::vector< double > DoubleArray
virtual void print(std::ostream &out, const std::string &label="Policy", const std::string &indent="") const
std::vector< ConstPtr > ConstPolicyPtrArray
bool getBool(const std::string &name) const
#define POL_GETLIST(name, type, vtype)
const ConstDictPtr getDictionary() const
bool isBool(const std::string &name) const
Interface for Persistable base class.
size_t valueCount(const std::string &name) const
#define LSST_EXCEPT(type,...)
boost::shared_ptr< const Policy > ConstPtr
bool isDictionary() const
bool isDouble(const std::string &name) const
Citizen(const std::type_info &)
lsst::daf::base::PropertySet::Ptr _data
void validate(ValidationError *errs=0) const
boost::shared_ptr< Dictionary > DictPtr
std::vector< lsst::daf::base::PropertySet::Ptr > _getPropSetList(const std::string &name) const
std::string toString() const
void _validate(const std::string &name, const T &value, int curCount=0)
int fileNames(std::list< std::string > &names, bool topLevelOnly=false, bool append=false) const
Interface for PropertySet class.
static ValueType getValueType()
Base class for all persistable classes.
void setDictionary(const Dictionary &dict)
BoolArray getBoolArray(const std::string &name) const
Citizen is a class that should be among all LSST classes base classes, and handles basic memory manag...
bool isString(const std::string &name) const
int loadPolicyFiles(bool strict=true)
void setValue(const std::string &name, const T &value)
bool isFile(const std::string &name) const
int policyNames(std::list< std::string > &names, bool topLevelOnly=false, bool append=false) const
const char * getTypeName(const std::string &name) const
bool exists(const std::string &name) const
FilePtrArray getFileArray(const std::string &name) const
lsst::daf::base::PropertySet::Ptr asPropertySet()