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> 49 class ValidationError;
51 #define POL_GETSCALAR(name, type, vtype) \ 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])); \ 62 #define POL_GETLIST(name, type, vtype) \ 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])); \ 208 explicit Policy(
const char* pathOrUrn);
230 Policy(
bool validate,
const Dictionary& dict,
const boost::filesystem::path& repository =
"");
322 template <
typename T>
361 bool append =
false)
const;
363 bool append =
false)
const;
365 bool append =
false)
const;
367 bool append =
false)
const;
382 StringArray
names(
bool topLevelOnly =
false)
const;
383 StringArray
paramNames(
bool topLevelOnly =
false)
const;
384 StringArray
policyNames(
bool topLevelOnly =
false)
const;
385 StringArray
fileNames(
bool topLevelOnly =
false)
const;
424 void validate(ValidationError* errs = 0)
const;
511 return typeName[
UNDEF];
521 template <
typename T>
530 template <
typename T>
678 template <
typename T>
716 template <
typename T>
756 virtual int loadPolicyFiles(
const boost::filesystem::path& repository,
bool strict =
true);
779 int mergeDefaults(
const Policy& defaultPol,
bool keepForValidation =
true, ValidationError* errs = 0);
833 template <
typename T>
834 void _validate(
const std::string& name,
const T& value,
int curCount = 0);
842 static Policy* _createPolicy(
PolicySource& input,
bool doIncludes,
const boost::filesystem::path& repos,
845 const boost::filesystem::path& repos,
bool validate);
856 return _names(names, topLevelOnly, append, 7);
859 return _names(names, topLevelOnly, append, 4);
862 return _names(names, topLevelOnly, append, 1);
865 return _names(names, topLevelOnly, append, 2);
870 _names(out, topLevelOnly,
true, 7);
875 _names(out, topLevelOnly,
true, 4);
880 _names(out, topLevelOnly,
true, 1);
885 _names(out, topLevelOnly,
true, 2);
897 return (_data->typeOf(name) ==
typeid(bool));
905 return (_data->typeOf(name) ==
typeid(int));
913 return (_data->typeOf(name) ==
typeid(double));
921 return (_data->typeOf(name) ==
typeid(
std::string));
929 return _data->isPropertySetPtr(name);
945 return _data->typeOf(name);
973 _validate(name, value);
974 _data->set(name, value->asPropertySet());
977 _validate(name, value);
978 _data->set(name, value);
981 _validate(name, value);
982 _data->set(name, value);
985 _validate(name, value);
986 _data->set(name, value);
989 _validate(name, value);
990 _data->set(name, value);
995 std::string(
"Attempted to assign NULL value to ") + name +
".");
1000 #define POL_ADD(name, value) \ 1002 _data->add(name, value); \ 1003 } catch (lsst::pex::exceptions::TypeError&) { \ 1004 throw LSST_EXCEPT(TypeError, name, getTypeName(name)); \ 1009 POL_ADD(name, value->asPropertySet())
1037 return _createPolicy(input, doIncludes, boost::filesystem::path(), validate);
1041 return _createPolicy(input, doIncludes, boost::filesystem::path(), validate);
1046 return _createPolicy(input,
true, repository, validate);
1050 return _createPolicy(input,
true, boost::filesystem::path(repository), validate);
1054 return _createPolicy(input,
true, boost::filesystem::path(repository), validate);
1059 return _createPolicy(input,
true, repository, validate);
1063 return _createPolicy(input,
true, boost::filesystem::path(repository), validate);
1067 return _createPolicy(input,
true, boost::filesystem::path(repository), validate);
1073 template <
typename T>
1091 template <
typename T>
1111 template <
typename T>
1133 template <
typename T>
1138 void Policy::setValue<bool>(
const std::string&
name,
const bool& value);
1140 void Policy::setValue<int>(
const std::string&
name,
const int& value);
1142 void Policy::setValue<double>(
const std::string&
name,
const double& value);
1151 template <
typename T>
1156 void Policy::addValue<bool>(
const std::string&
name,
const bool& value);
1158 void Policy::addValue<int>(
const std::string&
name,
const int& value);
1160 void Policy::addValue<double>(
const std::string&
name,
const double& value);
1172 #endif // LSST_PEX_POLICY_POLICY_H std::vector< int > IntArray
bool isDictionary() const
return true if it appears that this Policy actually contains dictionary definition data...
std::shared_ptr< PolicyFile > FilePtr
std::shared_ptr< Policy > Ptr
void set(const std::string &name, const Ptr &value)
Set a value with the given name.
std::vector< Ptr > PolicyPtrArray
bool isString(const std::string &name) const
return true if the value pointed to by the given name is a string
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.
bool isInt(const std::string &name) const
return true if the value pointed to by the given name is an integer
size_t valueCount(const std::string &name) const
return the number of values currently associated with a given name
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.
lsst::daf::base::PropertySet::Ptr asPropertySet()
return the internal policy data as a PropertySet pointer.
a container for holding hierarchical configuration data in memory.
std::shared_ptr< const Dictionary > ConstDictPtr
std::vector< T > getValueArray(const std::string &name) const
Template-ized version of getIntArray, getPolicyPtrArray, etc.
const std::type_info & typeOf(const std::string &name) const
return the type information for the underlying type associated with a given name. ...
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'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...
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.
static const char *const typeName[]
c-string forms for the supported value types.
bool isFile(const std::string &name) const
return true if the value pointed to by the given name is a PolicyFile
DoubleArray getDoubleArray(const std::string &name) const
return an array of values associated with the given name
std::shared_ptr< Dictionary > DictPtr
std::ostream & operator<<(std::ostream &os, const Policy &p)
FilePtr getFile(const std::string &name) const
return a PolicyFile (a reference to a file with "sub-Policy" data) identified by a 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.
StringArray getStringArray(const std::string &name) const
return an array of values associated with the given name
an abstract class representing a source of serialized Policy parameter data.
bool getBool(const std::string &name) const
return a boolean value associated with the given name.
Reports attempts to access elements using an invalid key.
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.
std::vector< std::string > StringArray
#define POL_GETLIST(name, type, vtype)
ConstPtr getPolicy(const std::string &name) const
return a "sub-Policy" identified by a given name.
#define POL_ADD(name, value)
int getInt(const std::string &name) const
return an integer value associated with the given name.
T getValue(const std::string &name) const
Template-ized version of getInt, getPolicy, etc.
bool isArray(const std::string &name) const
return true if multiple values can be retrieved via the given name.
int fileNames(std::list< std::string > &names, bool topLevelOnly=false, bool append=false) const
load the names of parameters into a given list.
void addValue(const std::string &name, const T &value)
Add a value to an array of values with a given name.
#define POL_GETSCALAR(name, type, vtype)
const char * source()
Source function that allows astChannel to source from a Stream.
bool isDouble(const std::string &name) const
return true if the value pointed to by the given name is a double
const std::string getString(const std::string &name) const
return a string value associated with the given name .
void setValue(const std::string &name, const T &value)
Set a value with the given name.
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
Policy(const lsst::daf::base::PropertySet::Ptr ps)
use a PropertySet as the data for a new Policy object
double getDouble(const std::string &name) const
return a double value associated with the given name.
Interface for Persistable base class.
BoolArray getBoolArray(const std::string &name) const
return an array of values associated with the given name
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
std::vector< FilePtr > FilePtrArray
bool isBool(const std::string &name) const
return true if the value pointed to by the given name is a boolean
const char * getTypeName(const std::string &name) const
return a string name for the type associated with the parameter of a given name.
int names(std::list< std::string > &names, bool topLevelOnly=false, bool append=false) const
load the names of parameters into a given list.
std::vector< double > DoubleArray
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.
const std::type_info & getTypeInfo(const std::string &name) const
return the type information for the underlying type associated with a given name. ...
Persistable(void)
Default constructor.
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.
static ValueType getValueType()
A template-ized way to get the ValueType.
Base class for all persistable classes.
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 of Policy-specific exceptions classes
std::vector< bool > BoolArray
an exception indicating that a policy parameter with a given name has a type different from the one t...
ConstPolicyPtrArray getConstPolicyArray(const std::string &name) const
return an array of Policy pointers associated with the given name.
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.
int nameCount() const
How many names of parameters does this policy file have?
std::shared_ptr< const Policy > ConstPtr
IntArray getIntArray(const std::string &name) const
return an array of values associated with the given name
Policy()
Create an empty policy.
std::vector< ConstPtr > ConstPolicyPtrArray
ValueType
an enumeration for the supported policy types
virtual ~Policy()
destroy this policy