| LSSTApplications
    20.0.0
    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 
  
const std::type_info & typeOf(const std::string &name) const
return the type information for the underlying type associated with a given name.
bool getBool(const std::string &name) const
return a boolean value associated with the given name.
std::vector< double > DoubleArray
const std::string getString(const std::string &name) const
return a string value associated with the given name .
lsst::daf::base::PropertySet::Ptr asPropertySet()
return the internal policy data as a PropertySet pointer.
BoolArray getBoolArray(const std::string &name) const
return an array of values associated with the given name
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 isInt(const std::string &name) const
return true if the value pointed to by the given name is an integer
static ValueType getTypeByName(const std::string &name)
Given the human-readable name of a type ("bool", "int", "policy", etc), what is its ValueType (BOOL,...
static Policy * createPolicy(PolicySource &input, bool doIncludes=true, bool validate=true)
create a Policy from a file.
#define POL_ADD(name, value)
ValueType
an enumeration for the supported policy types
std::shared_ptr< const Policy > ConstPtr
DoubleArray getDoubleArray(const std::string &name) const
static const char *const typeName[]
c-string forms for the supported value types.
int loadPolicyFiles(bool strict=true)
Recursively replace all PolicyFile values with the contents of the files they refer to.
Reports attempts to access elements using an invalid key.
bool isArray(const std::string &name) const
return true if multiple values can be retrieved via the given name.
std::vector< std::string > StringArray
int names(std::list< std::string > &names, bool topLevelOnly=false, bool append=false) const
load the names of parameters into a given list.
const ConstDictPtr getDictionary() const
The dictionary (if any) that this policy uses to validate itself, including checking set() and add() ...
std::shared_ptr< FrameSet > append(FrameSet const &first, FrameSet const &second)
Construct a FrameSet that performs two transformations in series.
void setDictionary(const Dictionary &dict)
Update this policy's dictionary that it uses to validate itself.
Policy(const lsst::daf::base::PropertySet::Ptr ps)
use a PropertySet as the data for a new Policy object
an exception indicating that a policy parameter with a given name has a type different from the one t...
Policy(bool validate, const Dictionary &dict, const boost::filesystem::path &repository="")
Create a default Policy from a Dictionary.
std::shared_ptr< const Dictionary > ConstDictPtr
std::vector< Ptr > PolicyPtrArray
int fileNames(std::list< std::string > &names, bool topLevelOnly=false, bool append=false) const
FilePtrArray getFileArray(const std::string &name) const
return an array of PolicyFile pointers associated with the given name.
Policy(const std::string &pathOrUrn)
Create a Policy from a named file or URN of the form "urn:eupspkg:<package>[:<repos>]:<path>".
a container for holding hierarchical configuration data in memory.
Policy(const PolicySource &source)
Create a Policy from a PolicySource (usually, a PolicyFile)
void validate(ValidationError *errs=0) const
Validate this policy, using its stored dictionary.
void add(const std::string &name, const FilePtr &value)
std::vector< bool > BoolArray
bool exists(const std::string &name) const
return true if a value exists in this policy for the given name.
std::vector< FilePtr > FilePtrArray
Interface for Persistable base class.
FilePtr getFile(const std::string &name) const
return a PolicyFile (a reference to a file with "sub-Policy" data) identified by a given name.
bool isFile(const std::string &name) const
return true if the value pointed to by the given name is a PolicyFile
int paramNames(std::list< std::string > &names, bool topLevelOnly=false, bool append=false) const
std::vector< ConstPtr > ConstPolicyPtrArray
bool isDouble(const std::string &name) const
return true if the value pointed to by the given name is a double
double getDouble(const std::string &name) const
return a double value associated with the given name.
const char * source()
Source function that allows astChannel to source from a Stream.
Policy(const Policy &pol)
deep-copy a Policy.
StringArray getStringArray(const std::string &name) const
std::shared_ptr< Policy > Ptr
std::shared_ptr< PolicyFile > FilePtr
Policy(const char *pathOrUrn)
std::vector< T > getValueArray(const std::string &name) const
Template-ized version of getIntArray, getPolicyPtrArray, etc.
Policy(Policy &pol, bool deep=false)
copy a Policy.
static ValueType getValueType()
A template-ized way to get the ValueType.
an abstract class representing a source of serialized Policy parameter data.
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...
std::vector< int > IntArray
PolicyPtrArray getPolicyArray(const std::string &name) const
return an array of Policy pointers associated with the given name.
ConstPtr getPolicy(const std::string &name) const
return a "sub-Policy" identified by a given name.
bool isBool(const std::string &name) const
return true if the value pointed to by the given name is a boolean
bool isString(const std::string &name) const
return true if the value pointed to by the given name is a string
#define POL_GETSCALAR(name, type, vtype)
std::ostream & operator<<(std::ostream &os, const Policy &p)
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
const char * getTypeName(const std::string &name) const
return a string name for the type associated with the parameter of a given name.
void setValue(const std::string &name, const T &value)
Set a value with the given name.
IntArray getIntArray(const std::string &name) const
bool isDictionary() const
return true if it appears that this Policy actually contains dictionary definition data.
A base class for image defects.
#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
void remove(const std::string &name)
Remove all values 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 itse...
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 FilePtr createPolicyFile(const std::string &pathOrUrn, bool strict=false)
Create a PolicyFile or UrnPolicyFile from pathOrUrn.
Reports invalid arguments.
Base class for all persistable classes.
definition of Policy-specific exceptions classes
void addValue(const std::string &name, const T &value)
Add a value to an array of values with a given name.
Persistable(void)
Default constructor.
static Policy * createPolicyFromUrn(const std::string &urn, bool validate=true)
Create a Policy from a file specified by a URN.
#define POL_GETLIST(name, type, vtype)
ConstPolicyPtrArray getConstPolicyArray(const std::string &name) const
void add(const std::string &name, const Ptr &value)
std::string toString() const
convert the entire contents of this policy to a string.
virtual ~Policy()
destroy this policy
int getInt(const std::string &name) const
return an integer value associated with the given name.
an exception indicating that a policy parameter of a given name can not be found in a Policy object.
size_t valueCount(const std::string &name) const
return the number of values currently associated with a given name
void set(const std::string &name, const FilePtr &value)
void set(const std::string &name, const Ptr &value)
bool isPolicy(const std::string &name) const
return true if the value pointed to by the given name is a Policy
const std::type_info & getTypeInfo(const std::string &name) const
return the type information for the underlying type associated with a given name.
ValueType getValueType(const std::string &name) const
return the ValueType enum identifier for the underlying type associated with a given name.
T getValue(const std::string &name) const
Template-ized version of getInt, getPolicy, etc.
Policy()
Create an empty policy.
int nameCount() const
How many names of parameters does this policy file have?