LSSTApplications
19.0.0-14-gb0260a2+d60062ef16,20.0.0+1540ce6389,20.0.0+7c6b12c2f9,20.0.0+ae956f52c5,20.0.0+be870186d9,20.0.0+e2e26847c2,20.0.0-1-g10df615+7683e4f082,20.0.0-1-g253301a+7c6b12c2f9,20.0.0-1-g2b7511a+46a6078777,20.0.0-1-g3dda6ea+606b36f8c0,20.0.0-1-g4d801e7+901ee84527,20.0.0-1-g5b95a8c+a5fa15ec54,20.0.0-1-gb058bd0+46a6078777,20.0.0-1-gb88604f+acecce4127,20.0.0-1-gc96f8cb+61a4a056b1,20.0.0-1-gedffbd8+4f0e391d5e,20.0.0-10-g0891cd99+aadc987f3e,20.0.0-10-g9a20bd332+576ca7b471,20.0.0-17-gcdbda88+ed0d4927ab,20.0.0-2-g4dae9ad+61a4a056b1,20.0.0-2-g61b8584+85c46248f3,20.0.0-2-gb780d76+f45b7d88f4,20.0.0-2-gf072044+7c6b12c2f9,20.0.0-21-g9bbb7f7+61a4a056b1,20.0.0-22-gc512666+9eba1c4719,20.0.0-23-g8900aa8+68630f7098,20.0.0-3-g1653f94+85c46248f3,20.0.0-3-g4cc78c6+63636aeed8,20.0.0-3-g750bffe+e05f822de9,20.0.0-3-gbd60e8c+ff10c6d78d,20.0.0-32-g15a0e07c+ff1c9f120b,20.0.0-4-g97dc21a+68630f7098,20.0.0-4-gfea843c+f45b7d88f4,20.0.0-5-g357b56b+f45b7d88f4,20.0.0-6-g9a5b7a1+2c4171520d,20.0.0-61-g4de25fb+e4dd172200,20.0.0-7-gcda7bf1+85e953d7e4,w.2020.43
LSSTDataManagementBasePackage
|
Go to the documentation of this file.
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])); \
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;
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);
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);
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));
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);
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)); \
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>
1151 template <
typename T>
1172 #endif // LSST_PEX_POLICY_POLICY_H
Policy(const std::string &pathOrUrn)
Create a Policy from a named file or URN of the form "urn:eupspkg:<package>[:<repos>]:<path>".
Policy(const lsst::daf::base::PropertySet::Ptr ps)
use a PropertySet as the data for a new Policy object
virtual ~Policy()
destroy this policy
PolicyPtrArray getPolicyArray(const std::string &name) const
return an array of Policy pointers associated with the given name.
void add(const std::string &name, const FilePtr &value)
lsst::daf::base::PropertySet::Ptr asPropertySet()
return the internal policy data as a PropertySet pointer.
virtual std::string str(const std::string &name, const std::string &indent="") const
return a string representation of the value given by a name.
std::vector< FilePtr > FilePtrArray
std::vector< ConstPtr > ConstPolicyPtrArray
Policy(const PolicySource &source)
Create a Policy from a PolicySource (usually, a PolicyFile)
#define POL_ADD(name, value)
ValueType
an enumeration for the supported policy types
void set(const std::string &name, const Ptr &value)
T getValue(const std::string &name) const
Template-ized version of getInt, getPolicy, etc.
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< std::string > StringArray
const std::type_info & typeOf(const std::string &name) const
return the type information for the underlying type associated with a given name.
std::shared_ptr< const Policy > ConstPtr
Reports attempts to access elements using an invalid key.
std::vector< bool > BoolArray
std::shared_ptr< FrameSet > append(FrameSet const &first, FrameSet const &second)
Construct a FrameSet that performs two transformations in series.
an exception indicating that a policy parameter with a given name has a type different from the one t...
static ValueType getValueType()
A template-ized way to get the ValueType.
a container for holding hierarchical configuration data in memory.
void validate(ValidationError *errs=0) const
Validate this policy, using its stored dictionary.
const std::string getString(const std::string &name) const
return a string value associated with the 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.
int getInt(const std::string &name) const
return an integer value associated 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...
static ValueType getTypeByName(const std::string &name)
Given the human-readable name of a type ("bool", "int", "policy", etc), what is its ValueType (BOOL,...
Policy(Policy &pol, bool deep=false)
copy a Policy.
int loadPolicyFiles(bool strict=true)
Recursively replace all PolicyFile values with the contents of the files they refer to.
int policyNames(std::list< std::string > &names, bool topLevelOnly=false, bool append=false) const
ConstPolicyPtrArray getConstPolicyArray(const std::string &name) const
void remove(const std::string &name)
Remove all values with a given name.
static Policy * createPolicyFromUrn(const std::string &urn, bool validate=true)
Create a Policy from a file specified by a URN.
int paramNames(std::list< std::string > &names, bool topLevelOnly=false, bool append=false) const
DoubleArray getDoubleArray(const std::string &name) const
const char * source()
Source function that allows astChannel to source from a Stream.
bool exists(const std::string &name) const
return true if a value exists in this policy for the given name.
double getDouble(const std::string &name) const
return a double value associated with the given name.
void addValue(const std::string &name, const T &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::vector< int > IntArray
void setValue(const std::string &name, const T &value)
Set a value with the given name.
Interface for Persistable base class.
std::vector< Ptr > PolicyPtrArray
BoolArray getBoolArray(const std::string &name) const
return an array of values associated with the given name
static Policy * createPolicy(PolicySource &input, bool doIncludes=true, bool validate=true)
create a Policy from a file.
Policy(const char *pathOrUrn)
an abstract class representing a source of serialized Policy parameter data.
#define POL_GETSCALAR(name, type, vtype)
bool isInt(const std::string &name) const
return true if the value pointed to by the given name is an integer
std::ostream & operator<<(std::ostream &os, const Policy &p)
const ConstDictPtr getDictionary() const
The dictionary (if any) that this policy uses to validate itself, including checking set() and add() ...
IntArray getIntArray(const std::string &name) const
FilePtrArray getFileArray(const std::string &name) const
return an array of PolicyFile pointers associated with the given name.
bool isBool(const std::string &name) const
return true if the value pointed to by the given name is a boolean
ConstPtr getPolicy(const std::string &name) const
return a "sub-Policy" identified by a given name.
ValueType getValueType(const std::string &name) const
return the ValueType enum identifier for the underlying type associated with a given name.
Policy()
Create an empty policy.
definition of Policy-specific exceptions classes
A base class for image defects.
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
std::shared_ptr< Policy > Ptr
virtual int loadPolicyFiles(const boost::filesystem::path &repository, bool strict=true)
Recursively replace all PolicyFile values with the contents of the files they refer to.
std::shared_ptr< Dictionary > DictPtr
Policy(const Policy &pol)
deep-copy a Policy.
static FilePtr createPolicyFile(const std::string &pathOrUrn, bool strict=false)
Create a PolicyFile or UrnPolicyFile from pathOrUrn.
std::string toString() const
convert the entire contents of this policy to a string.
Reports invalid arguments.
bool getBool(const std::string &name) const
return a boolean value associated with the given name.
Base class for all persistable classes.
std::shared_ptr< PolicyFile > FilePtr
std::shared_ptr< const Dictionary > ConstDictPtr
Persistable(void)
Default constructor.
bool isArray(const std::string &name) const
return true if multiple values can be retrieved via the given name.
#define POL_GETLIST(name, type, vtype)
bool canValidate() const
Can this policy validate itself – that is, does it have a dictionary that it can use to validate itse...
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.
static const char *const typeName[]
c-string forms for the supported value types.
void add(const std::string &name, const Ptr &value)
bool isDictionary() const
return true if it appears that this Policy actually contains dictionary definition data.
size_t valueCount(const std::string &name) const
return the number of values currently associated with a given name
std::vector< T > getValueArray(const std::string &name) const
Template-ized version of getIntArray, getPolicyPtrArray, etc.
Policy(bool validate, const Dictionary &dict, const boost::filesystem::path &repository="")
Create a default Policy from a Dictionary.
int fileNames(std::list< std::string > &names, bool topLevelOnly=false, bool append=false) const
an exception indicating that a policy parameter of a given name can not be found in a Policy object.
StringArray getStringArray(const std::string &name) const
void set(const std::string &name, const FilePtr &value)
std::vector< double > DoubleArray
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
bool isDouble(const std::string &name) const
return true if the value pointed to by the given name is a double
const char * getTypeName(const std::string &name) const
return a string name for the type associated with the parameter of a given name.
bool isString(const std::string &name) const
return true if the value pointed to by the given name is a string
int names(std::list< std::string > &names, bool topLevelOnly=false, bool append=false) const
load the names of parameters into a given list.
bool isFile(const std::string &name) const
return true if the value pointed to by the given name is a PolicyFile