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
|
a container for holding hierarchical configuration data in memory. More...
#include <Policy.h>
Public Types | |
enum | ValueType { UNDETERMINED = -1, UNDEF, BOOL, INT, DOUBLE, STRING, POLICY, FILE } |
an enumeration for the supported policy types More... | |
typedef std::shared_ptr< Policy > | Ptr |
typedef std::shared_ptr< const Policy > | ConstPtr |
typedef std::shared_ptr< Dictionary > | DictPtr |
typedef std::shared_ptr< const Dictionary > | ConstDictPtr |
typedef std::shared_ptr< PolicyFile > | FilePtr |
typedef std::vector< bool > | BoolArray |
typedef std::vector< int > | IntArray |
typedef std::vector< double > | DoubleArray |
typedef std::vector< std::string > | StringArray |
typedef std::vector< Ptr > | PolicyPtrArray |
typedef std::vector< FilePtr > | FilePtrArray |
typedef std::vector< ConstPtr > | ConstPolicyPtrArray |
Public Member Functions | |
Policy () | |
Create an empty policy. More... | |
Policy (const std::string &pathOrUrn) | |
Create a Policy from a named file or URN of the form "urn:eupspkg:<package>[:<repos>]:<path>". More... | |
Policy (const char *pathOrUrn) | |
Policy (const PolicySource &source) | |
Create a Policy from a PolicySource (usually, a PolicyFile) More... | |
Policy (bool validate, const Dictionary &dict, const boost::filesystem::path &repository="") | |
Create a default Policy from a Dictionary. More... | |
Policy (Policy &pol, bool deep=false) | |
copy a Policy. More... | |
Policy (const Policy &pol) | |
deep-copy a Policy. More... | |
virtual | ~Policy () |
destroy this policy More... | |
int | nameCount () const |
How many names of parameters does this policy file have? More... | |
int | names (std::list< std::string > &names, bool topLevelOnly=false, bool append=false) const |
load the names of parameters into a given list. More... | |
int | paramNames (std::list< std::string > &names, bool topLevelOnly=false, bool append=false) const |
int | policyNames (std::list< std::string > &names, bool topLevelOnly=false, bool append=false) const |
int | fileNames (std::list< std::string > &names, bool topLevelOnly=false, bool append=false) const |
StringArray | names (bool topLevelOnly=false) const |
return the names of parameters. More... | |
StringArray | paramNames (bool topLevelOnly=false) const |
StringArray | policyNames (bool topLevelOnly=false) const |
StringArray | fileNames (bool topLevelOnly=false) const |
bool | isDictionary () const |
return true if it appears that this Policy actually contains dictionary definition data. More... | |
bool | canValidate () const |
Can this policy validate itself – that is, does it have a dictionary that it can use to validate itself? If true, then set() and add() operations will be checked against it. More... | |
const ConstDictPtr | getDictionary () const |
The dictionary (if any) that this policy uses to validate itself, including checking set() and add() operations for validity. More... | |
void | setDictionary (const Dictionary &dict) |
Update this policy's dictionary that it uses to validate itself. More... | |
void | validate (ValidationError *errs=0) const |
Validate this policy, using its stored dictionary. More... | |
size_t | valueCount (const std::string &name) const |
return the number of values currently associated with a given name More... | |
bool | isArray (const std::string &name) const |
return true if multiple values can be retrieved via the given name. More... | |
bool | exists (const std::string &name) const |
return true if a value exists in this policy for the given name. More... | |
bool | isBool (const std::string &name) const |
return true if the value pointed to by the given name is a boolean More... | |
bool | isInt (const std::string &name) const |
return true if the value pointed to by the given name is an integer More... | |
bool | isDouble (const std::string &name) const |
return true if the value pointed to by the given name is a double More... | |
bool | isString (const std::string &name) const |
return true if the value pointed to by the given name is a string More... | |
bool | isPolicy (const std::string &name) const |
return true if the value pointed to by the given name is a Policy More... | |
bool | isFile (const std::string &name) const |
return true if the value pointed to by the given name is a PolicyFile More... | |
const std::type_info & | getTypeInfo (const std::string &name) const |
return the type information for the underlying type associated with a given name. More... | |
const std::type_info & | typeOf (const std::string &name) const |
return the type information for the underlying type associated with a given name. More... | |
ValueType | getValueType (const std::string &name) const |
return the ValueType enum identifier for the underlying type associated with a given name. More... | |
const char * | getTypeName (const std::string &name) const |
return a string name for the type associated with the parameter of a given name. More... | |
template<typename T > | |
T | getValue (const std::string &name) const |
Template-ized version of getInt, getPolicy, etc. More... | |
template<typename T > | |
std::vector< T > | getValueArray (const std::string &name) const |
Template-ized version of getIntArray, getPolicyPtrArray, etc. More... | |
ConstPtr | getPolicy (const std::string &name) const |
return a "sub-Policy" identified by a given name. More... | |
Ptr | getPolicy (const std::string &name) |
FilePtr | getFile (const std::string &name) const |
return a PolicyFile (a reference to a file with "sub-Policy" data) identified by a given name. More... | |
bool | getBool (const std::string &name) const |
return a boolean value associated with the given name. More... | |
int | getInt (const std::string &name) const |
return an integer value associated with the given name. More... | |
double | getDouble (const std::string &name) const |
return a double value associated with the given name. More... | |
const std::string | getString (const std::string &name) const |
return a string value associated with the given name . More... | |
PolicyPtrArray | getPolicyArray (const std::string &name) const |
return an array of Policy pointers associated with the given name. More... | |
ConstPolicyPtrArray | getConstPolicyArray (const std::string &name) const |
FilePtrArray | getFileArray (const std::string &name) const |
return an array of PolicyFile pointers associated with the given name. More... | |
BoolArray | getBoolArray (const std::string &name) const |
return an array of values associated with the given name More... | |
IntArray | getIntArray (const std::string &name) const |
DoubleArray | getDoubleArray (const std::string &name) const |
StringArray | getStringArray (const std::string &name) const |
template<typename T > | |
void | setValue (const std::string &name, const T &value) |
Set a value with the given name. More... | |
void | set (const std::string &name, const Ptr &value) |
void | set (const std::string &name, const FilePtr &value) |
void | set (const std::string &name, bool value) |
void | set (const std::string &name, int value) |
void | set (const std::string &name, double value) |
void | set (const std::string &name, const std::string &value) |
void | set (const std::string &name, const char *value) |
template<typename T > | |
void | addValue (const std::string &name, const T &value) |
Add a value to an array of values with a given name. More... | |
void | add (const std::string &name, const Ptr &value) |
void | add (const std::string &name, const FilePtr &value) |
void | add (const std::string &name, bool value) |
void | add (const std::string &name, int value) |
void | add (const std::string &name, double value) |
void | add (const std::string &name, const std::string &value) |
void | add (const std::string &name, const char *value) |
void | remove (const std::string &name) |
Remove all values with a given name. More... | |
int | loadPolicyFiles (bool strict=true) |
Recursively replace all PolicyFile values with the contents of the files they refer to. More... | |
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. More... | |
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 policy. More... | |
virtual std::string | str (const std::string &name, const std::string &indent="") const |
return a string representation of the value given by a name. More... | |
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. More... | |
std::string | toString () const |
convert the entire contents of this policy to a string. More... | |
lsst::daf::base::PropertySet::Ptr | asPropertySet () |
return the internal policy data as a PropertySet pointer. More... | |
template<> | |
bool | getValue (const std::string &name) const |
template<> | |
int | getValue (const std::string &name) const |
template<> | |
double | getValue (const std::string &name) const |
template<> | |
std::vector< bool > | getValueArray (const std::string &name) const |
template<> | |
std::vector< int > | getValueArray (const std::string &name) const |
template<> | |
std::vector< double > | getValueArray (const std::string &name) const |
template<> | |
void | setValue (const std::string &name, const bool &value) |
template<> | |
void | setValue (const std::string &name, const int &value) |
template<> | |
void | setValue (const std::string &name, const double &value) |
template<> | |
void | addValue (const std::string &name, const bool &value) |
template<> | |
void | addValue (const std::string &name, const int &value) |
template<> | |
void | addValue (const std::string &name, const double &value) |
template<class Archive > | |
void | serialize (Archive &, unsigned int const) |
Template boost::serialization function for the base class. More... | |
Static Public Member Functions | |
static Policy * | createPolicy (PolicySource &input, bool doIncludes=true, bool validate=true) |
create a Policy from a file. More... | |
static Policy * | createPolicy (const std::string &input, bool doIncludes=true, bool validate=true) |
static Policy * | createPolicyFromUrn (const std::string &urn, bool validate=true) |
Create a Policy from a file specified by a URN. More... | |
static Policy * | createPolicy (PolicySource &input, const boost::filesystem::path &repos, bool validate=true) |
create a Policy from a file. More... | |
static Policy * | createPolicy (PolicySource &input, const std::string &repos, bool validate=true) |
static Policy * | createPolicy (PolicySource &input, const char *repos, bool validate=true) |
static Policy * | createPolicy (const std::string &input, const boost::filesystem::path &repos, bool validate=true) |
static Policy * | createPolicy (const std::string &input, const std::string &repos, bool validate=true) |
static Policy * | createPolicy (const std::string &input, const char *repos, bool validate=true) |
static FilePtr | createPolicyFile (const std::string &pathOrUrn, bool strict=false) |
Create a PolicyFile or UrnPolicyFile from pathOrUrn . More... | |
template<typename T > | |
static ValueType | getValueType () |
A template-ized way to get the ValueType. More... | |
static ValueType | getTypeByName (const std::string &name) |
Given the human-readable name of a type ("bool", "int", "policy", etc), what is its ValueType (BOOL, STRING, etc.)? Throws BadNameError if unknown. More... | |
template<> | |
Policy::ValueType | getValueType () |
template<> | |
Policy::ValueType | getValueType () |
template<> | |
Policy::ValueType | getValueType () |
template<> | |
Policy::ValueType | getValueType () |
Static Public Attributes | |
static const char *const | typeName [] |
c-string forms for the supported value types. More... | |
Protected Member Functions | |
Policy (const lsst::daf::base::PropertySet::Ptr ps) | |
use a PropertySet as the data for a new Policy object More... | |
a container for holding hierarchical configuration data in memory.
A policy is a set of named parameters that can be used to configure the internal data and behavior of an object within an application. An important feature Policy objects is that the parameters can be loaded in from a file. Thus, it allows applications fine-grained control of objects even if much of the configuration parameters they provide are normally set to defaults and otherwise do not change.
The Policy interface allows an application to pull out parameter values by name. Typically, the application "knows" the names it needs from a Policy to configure itself–that is, these names and the use of their values are hard-coded into the application. The application simply calls one of the get methods to retrieve a typed value for the parameter. (Nevertheless, if necessary, the parameter names contained in a policy can be retrieved via the names()
member function.)
Policy parameters values are restricted to a limited set of types to ensure simple, well-defined ASCII text serialization format. These types are In particular, a Policy parameter can be one of:
As implied by the inclusion of Policy as a value type, a Policy can be hierarchical (like a PropertySet). Values deep within the hierarchy can be retrieved via a hiearchical name. Such a name is made up of name fields delimited by dots (.) where each name field represents a level of the hierarchy. The first field represents the top level of the hierarchy. If a given name does not resolve to value, a NameNotFound exception is thrown. If one expects a different value type for a name than what is actually stored, (e.g. one calls getInt(name)
for a parameter that is actually a string), a TypeError exception is thrown.
A hierarchical Policy allows an application to configure a whole hierarchy of objects, even if the object classes (and their associated policy parameters) were developed by different people. In particular, if an application that is configuring one of the objects it uses, it can either pull out the relevent values directly by their hierarchical names, or if that object supports configuration from a Policy, it can pull all of the values for the object by retrieving a Policy (via getPolicy(name)
) and passing it to the object.
It is important to note that parameter names relative the Policy that contains them. For example, suppose you have a parameter accessible via the name "foo.bar.zub". This implies that the name "foo.bar" will resolve to a Policy object. You can retrieve the "zub" parameter from that "sub-Policy" object by asking for "zub".
One can read Policy data via the constructors that take a file name in some form as an input argument; however the prefered manner is via one of the createPolicy() functions. The latter is able to intelligently differentiate between simple Policy file and a Dictionary file. In either case, the formats supported would be restricted by default to those currently built into this package. Support for other formats can be plugged in using the PolicyFile and SupportFormats classes.
For more information about about Policy files, file formats, and dictionaries, see the package overview as well as the PolicyFile and Dictionary class descriptions.
When an object using a Policy fails to find a parameter it was expecting, it is a little inelegant to provide a default hard-coded in the object's implementation, by design. Instead it is recommended that defaults be loaded from another Policy. The intended way to do this is to load defaults via a DefaultPolicyFile (which can locate a policy file from any EUPS-setup installation directory) and to merge them into to the primary Policy instance via the mergeDefaults() function.
With version 3.1, support for the JSON format was dropped.
After version 3.2, Policy's internal implementation was changed to be a wrapper around PropertySet. Prior to this, it used its own internal data map. The API (which had been optimized for the old implementation), remained largely unchanged for the purposes of backward compatibility. The changes include (1) dropping support for providing default values to the get*() functions, (2) returning array values by value rather than reference, and (3) added functions for greater consistancy with PropertySet.
After 3.3.3, loading default data (including from Dictionarys) was improved. This included adding mergeDefaults()
typedef std::vector<bool> lsst.pex::policy::Policy::BoolArray |
typedef std::shared_ptr<const Dictionary> lsst.pex::policy::Policy::ConstDictPtr |
typedef std::shared_ptr<const Policy> lsst.pex::policy::Policy::ConstPtr |
typedef std::shared_ptr<Dictionary> lsst.pex::policy::Policy::DictPtr |
typedef std::vector<double> lsst.pex::policy::Policy::DoubleArray |
typedef std::vector<int> lsst.pex::policy::Policy::IntArray |
lsst.pex::policy::Policy::Policy | ( | ) |
Create an empty policy.
|
explicit |
Create a Policy from a named file or URN of the form "urn:eupspkg:<package>[:<repos>]:<path>".
For more details on the format of the URN, see UrnPolicyFile.
pathOrUrn | can be a local file name, file path, or URN. |
|
explicit |
|
explicit |
Create a Policy from a PolicySource (usually, a PolicyFile)
source |
lsst.pex::policy::Policy::Policy | ( | bool | validate, |
const Dictionary & | dict, | ||
const boost::filesystem::path & | repository = "" |
||
) |
Create a default Policy from a Dictionary.
If the Dictionary references files containing dictionaries for sub-Policies, an attempt is made to open them and extract the default data, and if that attempt fails, an exception is thrown (probably an IoError or ParseError).
validate | if true, a shallow copy of the Dictionary will be held onto by this Policy and used to validate future updates. |
dict | the Dictionary to load defaults from |
repository | the directory to look for dictionary files referenced in dict . The default is the current directory. |
lsst.pex::policy::Policy::Policy | ( | Policy & | pol, |
bool | deep = false |
||
) |
|
virtual |
destroy this policy
|
inlineprotected |
|
inline |
|
inline |
void lsst.pex::policy::Policy::add | ( | const std::string & | name, |
const FilePtr & | value | ||
) |
|
inline |
|
inline |
|
inline |
|
inline |
void lsst.pex::policy::Policy::addValue | ( | const std::string & | name, |
const bool & | value | ||
) |
void lsst.pex::policy::Policy::addValue | ( | const std::string & | name, |
const double & | value | ||
) |
void lsst.pex::policy::Policy::addValue | ( | const std::string & | name, |
const int & | value | ||
) |
void lsst.pex::policy::Policy::addValue | ( | const std::string & | name, |
const T & | value | ||
) |
Add a value to an array of values with a given name.
If a value was previously set using the set() function, that previous value will be retained as the first value of the array.
If this policy has a
(see
), this operation will be checked before it is performed, and if it would create an invalid state, it will not succeed, and a
will be thrown. With the exception that the minimum number of values (in the case of an array) will not be checked, in case this is part of a sequence of
operations.
Note that
and
are equivalent.
name | the name of the parameter. This can be a hierarchical name with fields delimited with "." |
value | the value–int, double, string or Policy–to associate with the name. |
|
inline |
bool lsst.pex::policy::Policy::canValidate | ( | ) | const |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
create a Policy from a file.
The caller is responsible for deleting the returned value. This is the preferred way to obtain a Policy file if you don't care to know if the input file is an actual policy file or a policy dictionary. If it turns out to be a dictionary file, the defined defaults will be loaded into the return policy.
input | the input file or stream to load data from. |
doIncludes | if true, any references found to external Policy files will be resolved into sub-policy values. The files will be looked for in a directory relative the current directory. |
validate | if true and the input file is a policy dictionary, it will be given to the returned policy and used to validate future updates to the Policy. |
|
inlinestatic |
create a Policy from a file.
The caller is responsible for deleting the returned value. This is the preferred way to obtain a Policy file if you don't care to know if the input file is an actual policy file or a policy dictionary. If it turns out to be a dictionary file, the defined defaults will be loaded into the return policy.
input | the input file or stream to load data from. |
repos | a directory to look in for the referenced files. Only when the name of the file to be included is an absolute path will this. |
validate | if true and the input file is a policy dictionary, it will be given to the returned policy and used to validate future updates to the Policy. |
|
inlinestatic |
|
inlinestatic |
|
static |
Create a PolicyFile or UrnPolicyFile from pathOrUrn
.
pathOrUrn | if this looks like a Policy URN, create a UrnPolicyFile; otherwise, create a plain PolicyFile. |
strict | if false, "@" will be accepted as a substitute for "urn:eupspkg:"; if true, urn:eupspkg must be present in a URN. |
|
static |
Create a Policy from a file specified by a URN.
The caller is responsible for deleting the returned value. This is the preferred way to obtain a Policy file if you don't care to know if the input file is an actual policy file or a policy dictionary. If it turns out to be a dictionary file, the defined defaults will be loaded into the return policy.
urn | A URN of the form "urn:eupspkg:<package>[:<repository>]:<path> to load data from, as described in UrnPolicyFile. |
validate | if true and the input file is a policy dictionary, it will be given to the returned policy and used to validate future updates to the Policy. |
|
inline |
|
inline |
|
inline |
|
inline |
return a boolean value associated with the given name.
If the underlying value is an array, only the last value added will be returned.
name | the name of the parameter. This can be a hierarchical name with fields delimited with "." |
NameNotFound | if no value is associated with the given name. |
TypeError | if the value associated the given name is not a boolean type. |
Definition at line 567 of file Policy.h.
|
inline |
return an array of values associated with the given name
name | the name of the parameter. This can be a hierarchical name with fields delimited with "." |
NameNotFound | if no value is associated with the given name. |
TypeError | if the value associated the given name is not the expected type. |
Definition at line 964 of file Policy.h.
ConstPolicyPtrArray lsst.pex::policy::Policy::getConstPolicyArray | ( | const std::string & | name | ) | const |
const ConstDictPtr lsst.pex::policy::Policy::getDictionary | ( | ) | const |
|
inline |
return a double value associated with the given name.
If the underlying value is an array, only the last value added will be returned.
name | the name of the parameter. This can be a hierarchical name with fields delimited with "." |
NameNotFound | if no value is associated with the given name. |
TypeError | if the value associated the given name is not a double type. |
Definition at line 591 of file Policy.h.
|
inline |
FilePtr lsst.pex::policy::Policy::getFile | ( | const std::string & | name | ) | const |
return a PolicyFile (a reference to a file with "sub-Policy" data) identified by a given name.
name | the name of the parameter. This can be a hierarchical name with fields delimited with "." |
NameNotFound | if no value is associated with the given name. |
TypeError | if the value associated the given name is not a Policy type. |
FilePtrArray lsst.pex::policy::Policy::getFileArray | ( | const std::string & | name | ) | const |
return an array of PolicyFile pointers associated with the given name.
Adding an element to the returned array (using push_back()) is equivalent adding a value with add(const string&, const Policy::FilePtr&).
name | the name of the parameter. This can be a hierarchical name with fields delimited with "." |
NameNotFound | if no value is associated with the given name. |
TypeError | if the value associated the given name is not a Policy type. |
|
inline |
return an integer value associated with the given name.
If the underlying value is an array, only the last value added will be returned.
name | the name of the parameter. This can be a hierarchical name with fields delimited with "." |
NameNotFound | if no value is associated with the given name. |
TypeError | if the value associated the given name is not an integer type. |
Definition at line 579 of file Policy.h.
|
inline |
|
inline |
|
inline |
return a "sub-Policy" identified by a given name.
name | the name of the parameter. This can be a hierarchical name with fields delimited with "." |
NameNotFound | if no value is associated with the given name. |
TypeError | if the value associated the given name is not a Policy type. |
PolicyPtrArray lsst.pex::policy::Policy::getPolicyArray | ( | const std::string & | name | ) | const |
return an array of Policy pointers associated with the given name.
Adding an element to the returned array (using push_back()) is equivalent adding a value with add(const string&, const Policy::Ptr&).
name | the name of the parameter. This can be a hierarchical name with fields delimited with "." |
NameNotFound | if no value is associated with the given name. |
TypeError | if the value associated the given name is not a Policy type. |
|
inline |
return a string value associated with the given name .
If the underlying value is an array, only the last value added will be returned.
name | the name of the parameter. This can be a hierarchical name with fields delimited with "." |
NameNotFound | if no value is associated with the given name. |
TypeError | if the value associated the given name is not an integer type. |
Definition at line 603 of file Policy.h.
|
inline |
|
static |
Given the human-readable name of a type ("bool", "int", "policy", etc), what is its ValueType (BOOL, STRING, etc.)? Throws BadNameError if unknown.
|
inline |
|
inline |
T lsst.pex::policy::Policy::getValue | ( | const std::string & | name | ) | const |
Template-ized version of getInt, getPolicy, etc.
General case is disallowed, but specific types are implemented: bool, int, double, string, FilePtr (aka shared_ptr<PolicyFile>), ConstPtr (aka shared_ptr<const Policy>).
bool lsst.pex::policy::Policy::getValue | ( | const std::string & | name | ) | const |
int lsst.pex::policy::Policy::getValue | ( | const std::string & | name | ) | const |
double lsst.pex::policy::Policy::getValue | ( | const std::string & | name | ) | const |
std::vector< T > lsst.pex::policy::Policy::getValueArray | ( | const std::string & | name | ) | const |
Template-ized version of getIntArray, getPolicyPtrArray, etc.
General case is disallowed, but specific types are implemented: bool, int, double, string, FilePtr (aka shared_ptr<PolicyFile>, returns FilePtrArray), Ptr (aka shared_ptr<Policy>, returns PolicyPtrArray).
std::vector<double> lsst.pex::policy::Policy::getValueArray | ( | const std::string & | name | ) | const |
std::vector<int> lsst.pex::policy::Policy::getValueArray | ( | const std::string & | name | ) | const |
std::vector<bool> lsst.pex::policy::Policy::getValueArray | ( | const std::string & | name | ) | const |
|
static |
A template-ized way to get the ValueType.
General case is disallowed, but specific types are implemented: bool, int, double, string, Policy, FilePtr (aka shared_ptr<PolicyFile>), Ptr (aka shared_ptr<Policy>), ConstPtr (aka shared_ptr<const Policy>).
|
static |
|
static |
|
static |
|
static |
ValueType lsst.pex::policy::Policy::getValueType | ( | const std::string & | name | ) | const |
return the ValueType enum identifier for the underlying type associated with a given name.
If a parameter with that name has not been set, Policy::UNDEF is returned.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
return true if the value pointed to by the given name is a PolicyFile
Definition at line 935 of file Policy.h.
|
inline |
|
inline |
|
inline |
|
inline |
Recursively replace all PolicyFile values with the contents of the files they refer to.
The type of a parameter containing a PolicyFile will consequently change to a Policy upon successful completion. If the value is an array, all PolicyFiles in the array must load without error before the PolicyFile values themselves are erased.
strict | If true, throw an exception if an error occurs while reading and/or parsing the file (probably an IoError or ParseError). Otherwise, replace the file reference with a partial or empty sub-policy (that is, "{}"). |
Definition at line 747 of file Policy.h.
|
virtual |
Recursively replace all PolicyFile values with the contents of the files they refer to.
The type of a parameter containing a PolicyFile will consequently change to a Policy upon successful completion. If the value is an array, all PolicyFiles in the array must load without error before the PolicyFile values themselves are erased.
strict | If true, throw an exception if an error occurs while reading and/or parsing the file (probably an IoError or ParseError). Otherwise, replace the file reference with a partial or empty sub-policy (that is, "{}"). |
repository | a directory to look in for the referenced files. Only when the name of the file to be included is an absolute path will this. If empty or not provided, the directorywill be assumed to be the current one. |
int lsst.pex::policy::Policy::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 policy.
This function will iterate through the parameter names in the given policy, and if the name is not found in this policy, the value from the given one will be copied into this one. No attempt is made to match the number of values available per name.
defaultPol | the policy to pull default values from. This may be a Dictionary; if so, the default values will drawn from the appropriate default keyword. |
keepForValidation | if true, and if defaultPol is a Dictionary, keep a reference to it for validation future updates to this Policy. |
errs | an exception to load errors into – only relevant if defaultPol is a Dictionary or if this Policy already has a dictionary to validate against; if a validation error is encountered, it will be added to errs if errs is non-null, and an exception will not be raised; however, if errs is null, an exception will be thrown if a validation error is encountered. |
|
inline |
|
inline |
return the names of parameters.
names()
returns all names, paramNames()
only returns the names that resolve to non-Policy and non-PolicyFile type parameters, policyNames()
only returns the Policy names, and fileNames() only returns PolicyFile names.
topLevelOnly | if true, only parameter names at the top of the hierarchy will be returned; no hierarchical names will be included. |
|
inline |
load the names of parameters into a given list.
names()
returns all names, paramNames()
only returns the names that resolve to non-Policy and non-PolicyFile type parameters, policyNames()
only returns the Policy names, and fileNames() only returns PolicyFile names. These versions are provided for backward compatibility but are deprecated; use the versions that return vector values.
names | the list object to be loaded |
topLevelOnly | if true, only parameter names at the top of the hierarchy will be returned; no hierarchical names will be included. |
append | if false, the contents of the given list will be erased before loading the names. |
|
inline |
|
inline |
|
inline |
|
inline |
|
virtual |
print the contents of this policy to an output stream.
This is mainly intended for debugging purposes.
out | the output stream to write contents to |
label | a labeling string to lead the listing with. |
indent | a string to prepend each line with. |
|
inline |
|
inlineinherited |
Template boost::serialization function for the base class.
Doesn't actually do anything, since there is no data associated with the base. Inline to allow expansion wherever needed.
Definition at line 87 of file Persistable.h.
|
inline |
|
inline |
void lsst.pex::policy::Policy::set | ( | const std::string & | name, |
const FilePtr & | value | ||
) |
|
inline |
|
inline |
|
inline |
|
inline |
void lsst.pex::policy::Policy::setDictionary | ( | const Dictionary & | dict | ) |
Update this policy's dictionary that it uses to validate itself.
Note that this will not trigger validation – you will need to call
afterwards.
void lsst.pex::policy::Policy::setValue | ( | const std::string & | name, |
const bool & | value | ||
) |
void lsst.pex::policy::Policy::setValue | ( | const std::string & | name, |
const double & | value | ||
) |
void lsst.pex::policy::Policy::setValue | ( | const std::string & | name, |
const int & | value | ||
) |
void lsst.pex::policy::Policy::setValue | ( | const std::string & | name, |
const T & | value | ||
) |
Set a value with the given name.
Any previous value set with the same name will be overwritten. In particular, if the property previously pointed to an array of values, all those values will be forgotten.
If this policy has a
(see
), this operation will be checked before it is performed, and if it would create an invalid state, it will not succeed, and a
will be thrown. With the exception that the minimum number of values (in the case of an array) will not be checked, in case this will be followed by
operations.
Note that
and
are equivalent.
name | the name of the parameter. This can be a hierarchical name with fields delimited with "." |
value | the value–int, double, string or Policy–to associate with the name. |
|
virtual |
return a string representation of the value given by a name.
The string "<null>" is printed if the name does not exist.
name | the name of the parameter to string-ify |
indent | a string to prepend each line with. If the string includes embedded newline characters, each line should be preceded by this indent string. |
std::string lsst.pex::policy::Policy::toString | ( | ) | const |
convert the entire contents of this policy to a string.
This is mainly intended for debugging purposes.
|
inline |
return the type information for the underlying type associated with a given name.
This is equivalent to getTypeInfo() and is provided for consistency with PropertySet.
Definition at line 951 of file Policy.h.
void lsst.pex::policy::Policy::validate | ( | ValidationError * | errs = 0 | ) | const |
Validate this policy, using its stored dictionary.
If
is false, this will throw a LogicError.
If validation errors are found and
is null, a ValidationError will be thrown.
errs | if non-null, any validation errors will be stored here instead of being thrown. |
|
inline |
|
static |