LSSTApplications
10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
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 } |
typedef boost::shared_ptr< Policy > | Ptr |
typedef boost::shared_ptr < const Policy > | ConstPtr |
typedef boost::shared_ptr < Dictionary > | DictPtr |
typedef boost::shared_ptr < const Dictionary > | ConstDictPtr |
typedef boost::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 Types inherited from lsst::daf::base::Citizen | |
enum | { magicSentinel = 0xdeadbeef } |
typedef unsigned long | memId |
Type of the block's ID. More... | |
typedef memId(* | memNewCallback )(const memId cid) |
A function used to register a callback. More... | |
typedef memId(* | memCallback )(const Citizen *ptr) |
Public Types inherited from lsst::daf::base::Persistable | |
typedef boost::shared_ptr < Persistable > | Ptr |
Public Member Functions | |
Policy () | |
Policy (const PolicySource &source) | |
Policy (bool validate, const Dictionary &dict, const boost::filesystem::path &repository="") | |
Policy (Policy &pol, bool deep=false) | |
Policy (const Policy &pol) | |
virtual | ~Policy () |
int | nameCount () const |
bool | isDictionary () const |
bool | canValidate () const |
const ConstDictPtr | getDictionary () const |
void | setDictionary (const Dictionary &dict) |
void | validate (ValidationError *errs=0) const |
size_t | valueCount (const std::string &name) const |
bool | isArray (const std::string &name) const |
bool | exists (const std::string &name) const |
bool | isBool (const std::string &name) const |
bool | isInt (const std::string &name) const |
bool | isDouble (const std::string &name) const |
bool | isString (const std::string &name) const |
bool | isPolicy (const std::string &name) const |
bool | isFile (const std::string &name) const |
const std::type_info & | getTypeInfo (const std::string &name) const |
const std::type_info & | typeOf (const std::string &name) const |
ValueType | getValueType (const std::string &name) const |
const char * | getTypeName (const std::string &name) const |
template<typename T > | |
T | getValue (const std::string &name) const |
template<typename T > | |
std::vector< T > | getValueArray (const std::string &name) const |
FilePtr | getFile (const std::string &name) const |
bool | getBool (const std::string &name) const |
int | getInt (const std::string &name) const |
double | getDouble (const std::string &name) const |
const std::string | getString (const std::string &name) const |
FilePtrArray | getFileArray (const std::string &name) const |
void | remove (const std::string &name) |
int | loadPolicyFiles (bool strict=true) |
virtual int | loadPolicyFiles (const boost::filesystem::path &repository, bool strict=true) |
int | mergeDefaults (const Policy &defaultPol, bool keepForValidation=true, ValidationError *errs=0) |
virtual std::string | str (const std::string &name, const std::string &indent="") const |
virtual void | print (std::ostream &out, const std::string &label="Policy", const std::string &indent="") const |
std::string | toString () const |
lsst::daf::base::PropertySet::Ptr | asPropertySet () |
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<> | |
Policy::ValueType | getValueType () |
template<> | |
Policy::ValueType | getValueType () |
template<> | |
Policy::ValueType | getValueType () |
template<> | |
Policy::ValueType | getValueType () |
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) |
Policy (const std::string &pathOrUrn) | |
Policy (const char *pathOrUrn) | |
int | names (std::list< std::string > &names, bool topLevelOnly=false, bool append=false) const |
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 |
StringArray | paramNames (bool topLevelOnly=false) const |
StringArray | policyNames (bool topLevelOnly=false) const |
StringArray | fileNames (bool topLevelOnly=false) const |
ConstPtr | getPolicy (const std::string &name) const |
Ptr | getPolicy (const std::string &name) |
PolicyPtrArray | getPolicyArray (const std::string &name) const |
ConstPolicyPtrArray | getConstPolicyArray (const std::string &name) const |
BoolArray | getBoolArray (const std::string &name) const |
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) |
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) |
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) |
Public Member Functions inherited from lsst::daf::base::Citizen | |
Citizen (const std::type_info &) | |
Citizen (Citizen const &) | |
~Citizen () | |
Citizen & | operator= (Citizen const &) |
std::string | repr () const |
Return a string representation of a Citizen. More... | |
void | markPersistent (void) |
Mark a Citizen as persistent and not destroyed until process end. More... | |
memId | getId () const |
Return the Citizen's ID. More... | |
Public Member Functions inherited from lsst::daf::base::Persistable | |
Persistable (void) | |
virtual | ~Persistable (void) |
template<class Archive > | |
void | serialize (Archive &, unsigned int const) |
Static Public Member Functions | |
static Policy * | createPolicyFromUrn (const std::string &urn, bool validate=true) |
static FilePtr | createPolicyFile (const std::string &pathOrUrn, bool strict=false) |
template<typename T > | |
static ValueType | getValueType () |
static ValueType | getTypeByName (const std::string &name) |
static Policy * | createPolicy (PolicySource &input, bool doIncludes=true, bool validate=true) |
static Policy * | createPolicy (const std::string &input, bool doIncludes=true, bool validate=true) |
static Policy * | createPolicy (PolicySource &input, const boost::filesystem::path &repos, bool validate=true) |
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 Public Member Functions inherited from lsst::daf::base::Citizen | |
static bool | hasBeenCorrupted () |
Check all allocated blocks for corruption. More... | |
static memId | getNextMemId () |
Return the memId of the next object to be allocated. More... | |
static int | init () |
Called once when the memory system is being initialised. More... | |
static int | census (int, memId startingMemId=0) |
How many active Citizens are there? More... | |
static void | census (std::ostream &stream, memId startingMemId=0) |
Print a list of all active Citizens to stream, sorted by ID. More... | |
static const std::vector < const Citizen * > * | census () |
Return a (newly allocated) std::vector of active Citizens sorted by ID. More... | |
static memId | setNewCallbackId (memId id) |
Call the NewCallback when block is allocated. More... | |
static memId | setDeleteCallbackId (memId id) |
Call the current DeleteCallback when block is deleted. More... | |
static memNewCallback | setNewCallback (memNewCallback func) |
Set the NewCallback function. More... | |
static memCallback | setDeleteCallback (memCallback func) |
Set the DeleteCallback function. More... | |
static memCallback | setCorruptionCallback (memCallback func) |
Set the CorruptionCallback function. More... | |
Static Public Attributes | |
static const char *const | typeName [] |
Protected Member Functions | |
Policy (const lsst::daf::base::PropertySet::Ptr ps) | |
Private Member Functions | |
int | _names (std::list< std::string > &names, bool topLevelOnly=false, bool append=false, int want=3) const |
int | _names (std::vector< std::string > &names, bool topLevelOnly=false, bool append=false, int want=3) const |
template<typename T > | |
void | _validate (const std::string &name, const T &value, int curCount=0) |
std::vector < lsst::daf::base::Persistable::Ptr > | _getPersistList (const std::string &name) const |
std::vector < lsst::daf::base::PropertySet::Ptr > | _getPropSetList (const std::string &name) const |
Static Private Member Functions | |
static Policy * | _createPolicy (PolicySource &input, bool doIncludes, const boost::filesystem::path &repos, bool validate) |
static Policy * | _createPolicy (const std::string &input, bool doIncludes, const boost::filesystem::path &repos, bool validate) |
Private Attributes | |
lsst::daf::base::PropertySet::Ptr | _data |
DictPtr | _dictionary |
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 boost::shared_ptr<const Dictionary> lsst::pex.policy::Policy::ConstDictPtr |
typedef std::vector<ConstPtr> lsst::pex.policy::Policy::ConstPolicyPtrArray |
typedef boost::shared_ptr<const Policy> lsst::pex.policy::Policy::ConstPtr |
typedef boost::shared_ptr<Dictionary> lsst::pex.policy::Policy::DictPtr |
typedef std::vector<double> lsst::pex.policy::Policy::DoubleArray |
typedef boost::shared_ptr<PolicyFile> lsst::pex.policy::Policy::FilePtr |
typedef std::vector<FilePtr> lsst::pex.policy::Policy::FilePtrArray |
typedef std::vector<int> lsst::pex.policy::Policy::IntArray |
typedef std::vector<Ptr> lsst::pex.policy::Policy::PolicyPtrArray |
typedef boost::shared_ptr<Policy> lsst::pex.policy::Policy::Ptr |
typedef std::vector<std::string> lsst::pex.policy::Policy::StringArray |
an enumeration for the supported policy types
Enumerator | |
---|---|
UNDETERMINED | |
UNDEF | |
BOOL | |
INT | |
DOUBLE | |
STRING | |
POLICY | |
FILE |
Definition at line 189 of file Policy.h.
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 |
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 |
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 |
||
) |
copy a Policy.
pol | the policy to copy |
deep | if true, do a deep copy. Otherwise, Policy data will be shared. |
lsst::pex.policy::Policy::Policy | ( | const Policy & | pol | ) |
deep-copy a Policy.
|
virtual |
destroy this policy
|
inlineprotected |
|
staticprivate |
|
staticprivate |
|
inlineprivate |
Definition at line 872 of file Policy.h.
|
inlineprivate |
Definition at line 877 of file Policy.h.
|
private |
|
private |
|
private |
If _dictionary is non-null, validate value against it, assuming curCount current values for name.
|
inline |
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. |
TypeError | if the existing array of values is not of the requested type, or if this Policy is controlled by a Dictionary but the value type does not match the definition associated with the name. |
Definition at line 1075 of file Policy.h.
void lsst::pex.policy::Policy::add | ( | const std::string & | name, |
const FilePtr & | 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. |
TypeError | if the existing array of values is not of the requested type, or if this Policy is controlled by a Dictionary but the value type does not match the definition associated with the name. |
|
inline |
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. |
TypeError | if the existing array of values is not of the requested type, or if this Policy is controlled by a Dictionary but the value type does not match the definition associated with the name. |
Definition at line 1079 of file Policy.h.
|
inline |
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. |
TypeError | if the existing array of values is not of the requested type, or if this Policy is controlled by a Dictionary but the value type does not match the definition associated with the name. |
Definition at line 1083 of file Policy.h.
|
inline |
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. |
TypeError | if the existing array of values is not of the requested type, or if this Policy is controlled by a Dictionary but the value type does not match the definition associated with the name. |
Definition at line 1087 of file Policy.h.
|
inline |
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. |
TypeError | if the existing array of values is not of the requested type, or if this Policy is controlled by a Dictionary but the value type does not match the definition associated with the name. |
Definition at line 1091 of file Policy.h.
|
inline |
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. |
TypeError | if the existing array of values is not of the requested type, or if this Policy is controlled by a Dictionary but the value type does not match the definition associated with the name. |
Definition at line 1095 of file Policy.h.
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. |
TypeError | if the existing array of values is not of the requested type, or if this Policy is controlled by a Dictionary but the value type does not match the definition associated with the name. |
Definition at line 1210 of file Policy.h.
void lsst::pex.policy::Policy::addValue | ( | const std::string & | name, |
const bool & | 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 double & | value | ||
) |
|
inline |
bool lsst::pex.policy::Policy::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.
|
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. |
Definition at line 1106 of file Policy.h.
|
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. |
Definition at line 1112 of file Policy.h.
|
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. |
Definition at line 1118 of file Policy.h.
|
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. |
Definition at line 1125 of file Policy.h.
|
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. |
Definition at line 1132 of file Policy.h.
|
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. |
Definition at line 1139 of file Policy.h.
|
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. |
Definition at line 1146 of file Policy.h.
|
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. |
Definition at line 1153 of file Policy.h.
|
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 |
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. |
Definition at line 913 of file Policy.h.
|
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. |
Definition at line 930 of file Policy.h.
|
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 589 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 1027 of file Policy.h.
ConstPolicyPtrArray lsst::pex.policy::Policy::getConstPolicyArray | ( | 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. |
const ConstDictPtr lsst::pex.policy::Policy::getDictionary | ( | ) | const |
The dictionary (if any) that this policy uses to validate itself, including checking set() and add() operations for validity.
|
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 617 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 1036 of file Policy.h.
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 603 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 1031 of file Policy.h.
|
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. |
Definition at line 1015 of file Policy.h.
|
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. |
Definition at line 1018 of file Policy.h.
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 631 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 1023 of file Policy.h.
|
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 |
return a string name for the type associated with the parameter of a given name. If a parameter with that name has not been set, the returned string will be "undefined".
Definition at line 534 of file Policy.h.
T lsst::pex.policy::Policy::getValue | ( | const std::string & | name | ) | const |
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).
Definition at line 1174 of file Policy.h.
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 |
std::vector<double> lsst::pex.policy::Policy::getValueArray | ( | const std::string & | name | ) | const |
|
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.
Policy::ValueType lsst::pex.policy::Policy::getValueType | ( | ) |
Policy::ValueType lsst::pex.policy::Policy::getValueType | ( | ) |
Policy::ValueType lsst::pex.policy::Policy::getValueType | ( | ) |
Policy::ValueType lsst::pex.policy::Policy::getValueType | ( | ) |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
return true if the value pointed to by the given name is a PolicyFile
Definition at line 993 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 775 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 |
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. |
Definition at line 897 of file Policy.h.
|
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. |
Definition at line 919 of file Policy.h.
|
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. |
Definition at line 902 of file Policy.h.
|
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. |
Definition at line 922 of file Policy.h.
|
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. |
Definition at line 907 of file Policy.h.
|
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. |
Definition at line 927 of file Policy.h.
|
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 |
|
inline |
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. |
TypeError | if this Policy is controlled by a Dictionary but the value type does not match the definition associated with the name. |
Definition at line 1040 of file Policy.h.
void lsst::pex.policy::Policy::set | ( | const std::string & | name, |
const FilePtr & | 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. |
TypeError | if this Policy is controlled by a Dictionary but the value type does not match the definition associated with the name. |
|
inline |
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. |
TypeError | if this Policy is controlled by a Dictionary but the value type does not match the definition associated with the name. |
Definition at line 1044 of file Policy.h.
|
inline |
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. |
TypeError | if this Policy is controlled by a Dictionary but the value type does not match the definition associated with the name. |
Definition at line 1048 of file Policy.h.
|
inline |
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. |
TypeError | if this Policy is controlled by a Dictionary but the value type does not match the definition associated with the name. |
Definition at line 1052 of file Policy.h.
|
inline |
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. |
TypeError | if this Policy is controlled by a Dictionary but the value type does not match the definition associated with the name. |
Definition at line 1056 of file Policy.h.
|
inline |
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. |
TypeError | if this Policy is controlled by a Dictionary but the value type does not match the definition associated with the name. |
Definition at line 1060 of file Policy.h.
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 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. |
TypeError | if this Policy is controlled by a Dictionary but the value type does not match the definition associated with the name. |
Definition at line 1199 of file Policy.h.
void lsst::pex.policy::Policy::setValue | ( | const std::string & | name, |
const bool & | 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 double & | value | ||
) |
|
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 1011 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 |
|
private |
|
static |