25 #ifndef LSST_PEX_POLICY_POLICY_H 26 #define LSST_PEX_POLICY_POLICY_H 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])); \ 220 explicit Policy(
const char *pathOrUrn);
243 const boost::filesystem::path& repository=
"");
313 const boost::filesystem::path& repos,
320 const boost::filesystem::path& repos,
363 return _data->nameCount();
384 bool topLevelOnly=
false,
387 bool topLevelOnly=
false,
390 bool topLevelOnly=
false,
393 bool topLevelOnly=
false,
409 StringArray
names(
bool topLevelOnly=
false)
const;
410 StringArray
paramNames(
bool topLevelOnly=
false)
const;
411 StringArray
policyNames(
bool topLevelOnly=
false)
const;
412 StringArray
fileNames(
bool topLevelOnly=
false)
const;
451 void validate(ValidationError *errs=0)
const;
811 ValidationError *errs=0);
860 bool append=
false,
int want=3)
const;
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);
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);
921 _names(out, topLevelOnly,
true, 7);
926 _names(out, topLevelOnly,
true, 4);
931 _names(out, topLevelOnly,
true, 1);
936 _names(out, topLevelOnly,
true, 2);
941 return _data->valueCount(name);
945 return _data->isArray(name);
949 return _data->exists(name);
954 return (_data->typeOf(name) ==
typeid(bool));
963 return (_data->typeOf(name) ==
typeid(
int));
972 return (_data->typeOf(name) ==
typeid(double));
981 return (_data->typeOf(name) ==
typeid(
std::string));
990 return _data->isPropertySetPtr(name);
1009 try {
return _data->typeOf(name); }
1045 _validate(name, value);
1046 _data->set(name, value->asPropertySet());
1049 _validate(name, value);
1050 _data->set(name, value);
1053 _validate(name, value);
1054 _data->set(name, value);
1057 _validate(name, value);
1058 _data->set(name, value);
1061 _validate(name, value);
1062 _data->set(name, value);
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)); \ 1081 POL_ADD(name, value->asPropertySet())
1107 _data->remove(name);
1113 return _createPolicy(input, doIncludes, boost::filesystem::path(), validate);
1119 return _createPolicy(input, doIncludes, boost::filesystem::path(), validate);
1123 const boost::filesystem::path& repository,
1126 return _createPolicy(input,
true, repository, validate);
1133 return _createPolicy(input,
true, boost::filesystem::path(repository), validate);
1137 const char *repository,
1140 return _createPolicy(input,
true, boost::filesystem::path(repository), validate);
1144 const boost::filesystem::path& repository,
1147 return _createPolicy(input,
true, repository, validate);
1154 return _createPolicy(input,
true, boost::filesystem::path(repository), validate);
1158 const char *repository,
1161 return _createPolicy(input,
true, boost::filesystem::path(repository), validate);
1170 template <>
bool Policy::getValue<bool>(
const std::string&
name)
const;
1172 template <>
double Policy::getValue<double>(
const std::string&
name)
const;
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);
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);
1226 #endif // LSST_PEX_POLICY_POLICY_H T getValue(const std::string &name) const
Template-ized version of getInt, getPolicy, etc.
lsst::daf::base::PropertySet::Ptr asPropertySet()
return the internal policy data as a PropertySet pointer.
void validate(ValidationError *errs=0) const
Validate this policy, using its stored dictionary.
std::vector< FilePtr > FilePtrArray
BoolArray getBoolArray(const std::string &name) const
return an array of values associated with the given name
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
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
bool exists(const std::string &name) const
return true if a value exists in this policy for the given name.
std::shared_ptr< Dictionary > DictPtr
std::vector< std::string > StringArray
std::vector< double > DoubleArray
a container for holding hierarchical configuration data in memory.
void setDictionary(const Dictionary &dict)
Update this policy'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
IntArray getIntArray(const std::string &name) const
return an array of values associated with the given name
an exception indicating that a policy parameter of a given name can not be found in a Policy object...
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.
std::vector< Ptr > PolicyPtrArray
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 .
std::shared_ptr< PolicyFile > FilePtr
DoubleArray getDoubleArray(const std::string &name) const
return an array of values associated with the given name
bool isDouble(const std::string &name) const
return true if the value pointed to by the given name is a double
std::ostream & operator<<(std::ostream &os, const Policy &p)
void addValue(const std::string &name, const T &value)
Add a value to an array of values with a given name.
an abstract class representing a source of serialized Policy parameter data.
Reports attempts to access elements using an invalid key.
std::vector< ConstPtr > ConstPolicyPtrArray
std::shared_ptr< const Policy > ConstPtr
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...
Policy()
Create an empty policy.
#define POL_GETLIST(name, type, vtype)
#define POL_ADD(name, value)
Policy(const lsst::daf::base::PropertySet::Ptr ps)
use a PropertySet as the data for a new Policy object
int names(std::list< std::string > &names, bool topLevelOnly=false, bool append=false) const
load the names of parameters into a given list.
static ValueType getValueType()
A template-ized way to get the ValueType.
std::shared_ptr< Policy > Ptr
#define POL_GETSCALAR(name, type, vtype)
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.
ConstPtr getPolicy(const std::string &name) const
return a "sub-Policy" identified by a given name.
bool getBool(const std::string &name) const
return a boolean value associated with the given name.
double getDouble(const std::string &name) const
return a double value associated with the given name.
int paramNames(std::list< std::string > &names, bool topLevelOnly=false, bool append=false) const
load the names of parameters into a given list.
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
int policyNames(std::list< std::string > &names, bool topLevelOnly=false, bool append=false) const
load the names of parameters into a given list.
bool isBool(const std::string &name) const
return true if the value pointed to by the given name is a boolean
PolicyPtrArray getPolicyArray(const std::string &name) const
return an array of Policy pointers associated with the given name.
Citizen(const std::type_info &)
std::vector< T > getValueArray(const std::string &name) const
Template-ized version of getIntArray, getPolicyPtrArray, etc.
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...
const std::type_info & typeOf(const std::string &name) const
return the type information for the underlying type associated with a given name. ...
Persistable(void)
Default constructor.
static const char *const typeName[]
c-string forms for the supported value types.
Reports invalid arguments.
int fileNames(std::list< std::string > &names, bool topLevelOnly=false, bool append=false) const
load the names of parameters into a given list.
int getInt(const std::string &name) const
return an integer value associated with the given name.
std::vector< int > IntArray
Base class for all persistable classes.
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.
Citizen is a class that should be among all LSST classes base classes, and handles basic memory manag...
void remove(const std::string &name)
Remove all values with a given name.
void setValue(const std::string &name, const T &value)
Set a value with the given name.
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
an exception indicating that a policy parameter with a given name has a type different from the one t...
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
const std::type_info & getTypeInfo(const std::string &name) const
return the type information for the underlying type associated with a given name. ...
const char * getTypeName(const std::string &name) const
return a string name for the type associated with the parameter of a given name.
StringArray getStringArray(const std::string &name) const
return an array of values associated with the given name
std::shared_ptr< const Dictionary > ConstDictPtr
int nameCount() const
How many names of parameters does this policy file have?
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
bool isArray(const std::string &name) const
return true if multiple values can be retrieved via the given name.
static Policy * createPolicy(PolicySource &input, bool doIncludes=true, bool validate=true)
create a Policy from a file.
ValueType
an enumeration for the supported policy types
void add(const std::string &name, const Ptr &value)
Add a value to an array of values with a given name.