LSSTApplications  19.0.0-14-gb0260a2+68b5710e34,20.0.0+34a42eae2c,20.0.0+5e413b1bb7,20.0.0+8220981c08,20.0.0+8558dd3f48,20.0.0+9105c11c27,20.0.0+9c492b2baa,20.0.0+b290a576ab,20.0.0+b2ea66fa67,20.0.0+bdb47f006b,20.0.0+c80b78a72c,20.0.0+ca71b4c878,20.0.0+dcf29472a8,20.0.0+f45b7d88f4,20.0.0+ff38a75775,20.0.0-1-g10df615+0301c91ccb,20.0.0-1-g253301a+dcf29472a8,20.0.0-1-g498fb60+ff88705a28,20.0.0-1-g4d801e7+0fef26433e,20.0.0-1-g8a53f90+2817c06967,20.0.0-1-gc96f8cb+9c492b2baa,20.0.0-1-gd1c87d7+2817c06967,20.0.0-1-gdb27ee5+60996fbbb1,20.0.0-11-gda4966f+51d1f94bfc,20.0.0-17-g98646ba4+6d72394450,20.0.0-2-g25c5319+53d663580f,20.0.0-2-gec03fae+3bc057fb2a,20.0.0-27-g22bab1b+63c2eb6a9e,20.0.0-3-gd2e950e+f45b7d88f4,20.0.0-4-g4a2362f+f45b7d88f4,20.0.0-4-ge48a6ca+6f08222a1e,20.0.0-5-gac0d578b1+6c871ee35c,20.0.0-6-g01203fff+c632a9a46a,20.0.0-7-g3c4151b+49dfb5b924,20.0.0-8-g9573cbd+60996fbbb1,20.0.0-8-gc2abeef+9c492b2baa,w.2020.32
LSSTDataManagementBasePackage
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | List of all members
lsst::pex::policy::Policy Class Reference

a container for holding hierarchical configuration data in memory. More...

#include <Policy.h>

Inheritance diagram for lsst::pex::policy::Policy:
lsst::daf::base::Persistable

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< PolicyPtr
 
typedef std::shared_ptr< const PolicyConstPtr
 
typedef std::shared_ptr< Dictionary > DictPtr
 
typedef std::shared_ptr< const Dictionary > ConstDictPtr
 
typedef std::shared_ptr< PolicyFileFilePtr
 
typedef std::vector< bool > BoolArray
 
typedef std::vector< int > IntArray
 
typedef std::vector< double > DoubleArray
 
typedef std::vector< std::stringStringArray
 
typedef std::vector< PtrPolicyPtrArray
 
typedef std::vector< FilePtrFilePtrArray
 
typedef std::vector< ConstPtrConstPolicyPtrArray
 

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_infogetTypeInfo (const std::string &name) const
 return the type information for the underlying type associated with a given name. More...
 
const std::type_infotypeOf (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 >
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 PolicycreatePolicy (PolicySource &input, bool doIncludes=true, bool validate=true)
 create a Policy from a file. More...
 
static PolicycreatePolicy (const std::string &input, bool doIncludes=true, bool validate=true)
 
static PolicycreatePolicyFromUrn (const std::string &urn, bool validate=true)
 Create a Policy from a file specified by a URN. More...
 
static PolicycreatePolicy (PolicySource &input, const boost::filesystem::path &repos, bool validate=true)
 create a Policy from a file. More...
 
static PolicycreatePolicy (PolicySource &input, const std::string &repos, bool validate=true)
 
static PolicycreatePolicy (PolicySource &input, const char *repos, bool validate=true)
 
static PolicycreatePolicy (const std::string &input, const boost::filesystem::path &repos, bool validate=true)
 
static PolicycreatePolicy (const std::string &input, const std::string &repos, bool validate=true)
 
static PolicycreatePolicy (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...
 

Detailed Description

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".

Loading a Policy File

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.

Default Policy Data

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.

Version Notes

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()

Definition at line 167 of file Policy.h.

Member Typedef Documentation

◆ BoolArray

Definition at line 175 of file Policy.h.

◆ ConstDictPtr

Definition at line 172 of file Policy.h.

◆ ConstPolicyPtrArray

Definition at line 181 of file Policy.h.

◆ ConstPtr

Definition at line 170 of file Policy.h.

◆ DictPtr

Definition at line 171 of file Policy.h.

◆ DoubleArray

Definition at line 177 of file Policy.h.

◆ FilePtr

Definition at line 173 of file Policy.h.

◆ FilePtrArray

Definition at line 180 of file Policy.h.

◆ IntArray

Definition at line 176 of file Policy.h.

◆ PolicyPtrArray

Definition at line 179 of file Policy.h.

◆ Ptr

Definition at line 169 of file Policy.h.

◆ StringArray

Definition at line 178 of file Policy.h.

Member Enumeration Documentation

◆ ValueType

an enumeration for the supported policy types

Enumerator
UNDETERMINED 
UNDEF 
BOOL 
INT 
DOUBLE 
STRING 
POLICY 
FILE 

Definition at line 186 of file Policy.h.

Constructor & Destructor Documentation

◆ Policy() [1/8]

lsst::pex::policy::Policy::Policy ( )

Create an empty policy.

◆ Policy() [2/8]

lsst::pex::policy::Policy::Policy ( const std::string pathOrUrn)
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.

Parameters
pathOrUrncan be a local file name, file path, or URN.

◆ Policy() [3/8]

lsst::pex::policy::Policy::Policy ( const char *  pathOrUrn)
explicit

◆ Policy() [4/8]

lsst::pex::policy::Policy::Policy ( const PolicySource source)
explicit

Create a Policy from a PolicySource (usually, a PolicyFile)

Parameters
source

◆ Policy() [5/8]

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).

Parameters
validateif true, a shallow copy of the Dictionary will be held onto by this Policy and used to validate future updates.
dictthe Dictionary to load defaults from
repositorythe directory to look for dictionary files referenced in dict. The default is the current directory.

◆ Policy() [6/8]

lsst::pex::policy::Policy::Policy ( Policy pol,
bool  deep = false 
)

copy a Policy.

Parameters
polthe policy to copy
deepif true, do a deep copy. Otherwise, Policy data will be shared.

◆ Policy() [7/8]

lsst::pex::policy::Policy::Policy ( const Policy pol)

deep-copy a Policy.

◆ ~Policy()

virtual lsst::pex::policy::Policy::~Policy ( )
virtual

destroy this policy

◆ Policy() [8/8]

lsst::pex::policy::Policy::Policy ( const lsst::daf::base::PropertySet::Ptr  ps)
inlineprotected

use a PropertySet as the data for a new Policy object

Definition at line 817 of file Policy.h.

817 : lsst::daf::base::Persistable(), _data(ps) {}

Member Function Documentation

◆ add() [1/7]

void lsst::pex::policy::Policy::add ( const std::string name,
bool  value 
)
inline

Definition at line 1011 of file Policy.h.

1011  {
1012  _validate(name, value, valueCount(name));
1013  POL_ADD(name, value);
1014 }

◆ add() [2/7]

void lsst::pex::policy::Policy::add ( const std::string name,
const char *  value 
)
inline

Definition at line 1027 of file Policy.h.

1027  {
1028  std::string v(value);
1029  _validate(name, v, valueCount(name));
1030  POL_ADD(name, v);
1031 }

◆ add() [3/7]

void lsst::pex::policy::Policy::add ( const std::string name,
const FilePtr value 
)

◆ add() [4/7]

void lsst::pex::policy::Policy::add ( const std::string name,
const Ptr value 
)
inline

Definition at line 1007 of file Policy.h.

1007  {
1008  _validate(name, value, valueCount(name));
1009  POL_ADD(name, value->asPropertySet())
1010 }

◆ add() [5/7]

void lsst::pex::policy::Policy::add ( const std::string name,
const std::string value 
)
inline

Definition at line 1023 of file Policy.h.

1023  {
1024  _validate(name, value, valueCount(name));
1025  POL_ADD(name, value);
1026 }

◆ add() [6/7]

void lsst::pex::policy::Policy::add ( const std::string name,
double  value 
)
inline

Definition at line 1019 of file Policy.h.

1019  {
1020  _validate(name, value, valueCount(name));
1021  POL_ADD(name, value);
1022 }

◆ add() [7/7]

void lsst::pex::policy::Policy::add ( const std::string name,
int  value 
)
inline

Definition at line 1015 of file Policy.h.

1015  {
1016  _validate(name, value, valueCount(name));
1017  POL_ADD(name, value);
1018 }

◆ addValue() [1/4]

template<>
void lsst::pex::policy::Policy::addValue ( const std::string name,
const bool &  value 
)

◆ addValue() [2/4]

template<>
void lsst::pex::policy::Policy::addValue ( const std::string name,
const double &  value 
)

◆ addValue() [3/4]

template<>
void lsst::pex::policy::Policy::addValue ( const std::string name,
const int &  value 
)

◆ addValue() [4/4]

template<typename T >
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

Dictionary

(see

), this operation will be checked before it is performed, and if it would create an invalid state, it will not succeed, and a

ValidationError

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

add(const string&, const string&)

and

add(const string&, const char *)

are equivalent.

Parameters
namethe name of the parameter. This can be a hierarchical name with fields delimited with "."
valuethe value–int, double, string or Policy–to associate with the name.
Exceptions
TypeErrorif 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 1152 of file Policy.h.

1152  {
1153  throw LSST_EXCEPT(TypeError, name, "not implemented for this type");
1154 }

◆ asPropertySet()

lsst::daf::base::PropertySet::Ptr lsst::pex::policy::Policy::asPropertySet ( )
inline

return the internal policy data as a PropertySet pointer.

All sub-policy data will appear as PropertySets.

Definition at line 1070 of file Policy.h.

1070 { return _data; }

◆ canValidate()

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.

◆ createPolicy() [1/8]

Policy * lsst::pex::policy::Policy::createPolicy ( const std::string input,
bool  doIncludes = true,
bool  validate = true 
)
inlinestatic

Definition at line 1040 of file Policy.h.

1040  {
1041  return _createPolicy(input, doIncludes, boost::filesystem::path(), validate);
1042 }

◆ createPolicy() [2/8]

Policy * lsst::pex::policy::Policy::createPolicy ( const std::string input,
const boost::filesystem::path &  repos,
bool  validate = true 
)
inlinestatic

Definition at line 1057 of file Policy.h.

1058  {
1059  return _createPolicy(input, true, repository, validate);
1060 }

◆ createPolicy() [3/8]

Policy * lsst::pex::policy::Policy::createPolicy ( const std::string input,
const char *  repos,
bool  validate = true 
)
inlinestatic

Definition at line 1066 of file Policy.h.

1066  {
1067  return _createPolicy(input, true, boost::filesystem::path(repository), validate);
1068 }

◆ createPolicy() [4/8]

Policy * lsst::pex::policy::Policy::createPolicy ( const std::string input,
const std::string repos,
bool  validate = true 
)
inlinestatic

Definition at line 1062 of file Policy.h.

1062  {
1063  return _createPolicy(input, true, boost::filesystem::path(repository), validate);
1064 }

◆ createPolicy() [5/8]

Policy * lsst::pex::policy::Policy::createPolicy ( PolicySource input,
bool  doIncludes = true,
bool  validate = true 
)
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.

Parameters
inputthe input file or stream to load data from.
doIncludesif 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.
validateif 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 1036 of file Policy.h.

1036  {
1037  return _createPolicy(input, doIncludes, boost::filesystem::path(), validate);
1038 }

◆ createPolicy() [6/8]

Policy * lsst::pex::policy::Policy::createPolicy ( PolicySource input,
const boost::filesystem::path &  repos,
bool  validate = true 
)
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.

Parameters
inputthe input file or stream to load data from.
reposa directory to look in for the referenced files. Only when the name of the file to be included is an absolute path will this.
validateif 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 1044 of file Policy.h.

1045  {
1046  return _createPolicy(input, true, repository, validate);
1047 }

◆ createPolicy() [7/8]

Policy * lsst::pex::policy::Policy::createPolicy ( PolicySource input,
const char *  repos,
bool  validate = true 
)
inlinestatic

Definition at line 1053 of file Policy.h.

1053  {
1054  return _createPolicy(input, true, boost::filesystem::path(repository), validate);
1055 }

◆ createPolicy() [8/8]

Policy * lsst::pex::policy::Policy::createPolicy ( PolicySource input,
const std::string repos,
bool  validate = true 
)
inlinestatic

Definition at line 1049 of file Policy.h.

1049  {
1050  return _createPolicy(input, true, boost::filesystem::path(repository), validate);
1051 }

◆ createPolicyFile()

static FilePtr lsst::pex::policy::Policy::createPolicyFile ( const std::string pathOrUrn,
bool  strict = false 
)
static

Create a PolicyFile or UrnPolicyFile from pathOrUrn.

Parameters
pathOrUrnif this looks like a Policy URN, create a UrnPolicyFile; otherwise, create a plain PolicyFile.
strictif false, "@" will be accepted as a substitute for "urn:eupspkg:"; if true, urn:eupspkg must be present in a URN.

◆ createPolicyFromUrn()

static Policy* lsst::pex::policy::Policy::createPolicyFromUrn ( const std::string urn,
bool  validate = true 
)
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.

Parameters
urnA URN of the form "urn:eupspkg:<package>[:<repository>]:<path> to load data from, as described in UrnPolicyFile.
validateif 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.

◆ exists()

bool lsst::pex::policy::Policy::exists ( const std::string name) const
inline

return true if a value exists in this policy for the given name.

This is semantically equivalent to (valuecount(name) > 0) (though its implementation is slightly more efficient).

Parameters
namethe (possibly) hierarchical name of the property of interest.

Definition at line 893 of file Policy.h.

893 { return _data->exists(name); }

◆ fileNames() [1/2]

Policy::StringArray lsst::pex::policy::Policy::fileNames ( bool  topLevelOnly = false) const
inline

Definition at line 883 of file Policy.h.

883  {
884  StringArray out;
885  _names(out, topLevelOnly, true, 2);
886  return out;
887 }

◆ fileNames() [2/2]

int lsst::pex::policy::Policy::fileNames ( std::list< std::string > &  names,
bool  topLevelOnly = false,
bool  append = false 
) const
inline

Definition at line 864 of file Policy.h.

864  {
865  return _names(names, topLevelOnly, append, 2);
866 }

◆ getBool()

bool lsst::pex::policy::Policy::getBool ( const std::string name) const
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.

Parameters
namethe name of the parameter. This can be a hierarchical name with fields delimited with "."
Exceptions
NameNotFoundif no value is associated with the given name.
TypeErrorif the value associated the given name is not a boolean type.

Definition at line 567 of file Policy.h.

567 { POL_GETSCALAR(name, bool, BOOL) }

◆ getBoolArray()

Policy::BoolArray lsst::pex::policy::Policy::getBoolArray ( const std::string name) const
inline

return an array of values associated with the given name

Parameters
namethe name of the parameter. This can be a hierarchical name with fields delimited with "."
Exceptions
NameNotFoundif no value is associated with the given name.
TypeErrorif the value associated the given name is not the expected type.

Definition at line 964 of file Policy.h.

964 { POL_GETLIST(name, bool, BOOL) }

◆ getConstPolicyArray()

ConstPolicyPtrArray lsst::pex::policy::Policy::getConstPolicyArray ( const std::string name) const

◆ getDictionary()

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.

◆ getDouble()

double lsst::pex::policy::Policy::getDouble ( const std::string name) 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.

Parameters
namethe name of the parameter. This can be a hierarchical name with fields delimited with "."
Exceptions
NameNotFoundif no value is associated with the given name.
TypeErrorif the value associated the given name is not a double type.

Definition at line 591 of file Policy.h.

591 { POL_GETSCALAR(name, double, DOUBLE) }

◆ getDoubleArray()

Policy::DoubleArray lsst::pex::policy::Policy::getDoubleArray ( const std::string name) const
inline

Definition at line 968 of file Policy.h.

968  {
969  POL_GETLIST(name, double, DOUBLE)
970 }

◆ getFile()

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.

Parameters
namethe name of the parameter. This can be a hierarchical name with fields delimited with "."
Exceptions
NameNotFoundif no value is associated with the given name.
TypeErrorif the value associated the given name is not a Policy type.

◆ getFileArray()

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&).

Parameters
namethe name of the parameter. This can be a hierarchical name with fields delimited with "."
Exceptions
NameNotFoundif no value is associated with the given name.
TypeErrorif the value associated the given name is not a Policy type.

◆ getInt()

int lsst::pex::policy::Policy::getInt ( const std::string name) const
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.

Parameters
namethe name of the parameter. This can be a hierarchical name with fields delimited with "."
Exceptions
NameNotFoundif no value is associated with the given name.
TypeErrorif the value associated the given name is not an integer type.

Definition at line 579 of file Policy.h.

579 { POL_GETSCALAR(name, int, INT) }

◆ getIntArray()

Policy::IntArray lsst::pex::policy::Policy::getIntArray ( const std::string name) const
inline

Definition at line 966 of file Policy.h.

966 { POL_GETLIST(name, int, INT) }

◆ getPolicy() [1/2]

Policy::Ptr lsst::pex::policy::Policy::getPolicy ( const std::string name)
inline

Definition at line 956 of file Policy.h.

956  {
957  return Ptr(new Policy(_data->get<lsst::daf::base::PropertySet::Ptr>(name)));
958 }

◆ getPolicy() [2/2]

Policy::ConstPtr lsst::pex::policy::Policy::getPolicy ( const std::string name) const
inline

return a "sub-Policy" identified by a given name.

Parameters
namethe name of the parameter. This can be a hierarchical name with fields delimited with "."
Exceptions
NameNotFoundif no value is associated with the given name.
TypeErrorif the value associated the given name is not a Policy type.

Definition at line 953 of file Policy.h.

953  {
955 }

◆ getPolicyArray()

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&).

Parameters
namethe name of the parameter. This can be a hierarchical name with fields delimited with "."
Exceptions
NameNotFoundif no value is associated with the given name.
TypeErrorif the value associated the given name is not a Policy type.

◆ getString()

const std::string lsst::pex::policy::Policy::getString ( const std::string name) const
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.

Parameters
namethe name of the parameter. This can be a hierarchical name with fields delimited with "."
Exceptions
NameNotFoundif no value is associated with the given name.
TypeErrorif the value associated the given name is not an integer type.

Definition at line 603 of file Policy.h.

◆ getStringArray()

Policy::StringArray lsst::pex::policy::Policy::getStringArray ( const std::string name) const
inline

Definition at line 960 of file Policy.h.

960  {
961  return _data->getArray<std::string>(name);
962 }

◆ getTypeByName()

static ValueType lsst::pex::policy::Policy::getTypeByName ( const std::string name)
static

Given the human-readable name of a type ("bool", "int", "policy", etc), what is its ValueType (BOOL, STRING, etc.)? Throws BadNameError if unknown.

◆ getTypeInfo()

const std::type_info & lsst::pex::policy::Policy::getTypeInfo ( const std::string name) const
inline

return the type information for the underlying type associated with a given name.

This is equivalent to typeOf() and is provided for backward compatibility.

Definition at line 943 of file Policy.h.

943  {
944  try {
945  return _data->typeOf(name);
947  throw LSST_EXCEPT(NameNotFound, name);
948  }
949 }

◆ getTypeName()

const char* lsst::pex::policy::Policy::getTypeName ( const std::string name) const
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 507 of file Policy.h.

507  {
508  try {
509  return typeName[getValueType(name)];
510  } catch (NameNotFound&) {
511  return typeName[UNDEF];
512  }
513  }

◆ getValue() [1/4]

template<typename T >
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>).

Definition at line 1074 of file Policy.h.

1074  {
1075  throw LSST_EXCEPT(TypeError, name, "not implemented for this type");
1076 }

◆ getValue() [2/4]

template<>
bool lsst::pex::policy::Policy::getValue ( const std::string name) const

◆ getValue() [3/4]

template<>
int lsst::pex::policy::Policy::getValue ( const std::string name) const

◆ getValue() [4/4]

template<>
double lsst::pex::policy::Policy::getValue ( const std::string name) const

◆ getValueArray() [1/4]

template<typename T >
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 1092 of file Policy.h.

1092  {
1093  throw LSST_EXCEPT(TypeError, name, "not implemented for this type");
1094 }

◆ getValueArray() [2/4]

template<>
std::vector<double> lsst::pex::policy::Policy::getValueArray ( const std::string name) const

◆ getValueArray() [3/4]

template<>
std::vector<int> lsst::pex::policy::Policy::getValueArray ( const std::string name) const

◆ getValueArray() [4/4]

template<>
std::vector<bool> lsst::pex::policy::Policy::getValueArray ( const std::string name) const

◆ getValueType() [1/6]

template<typename T >
Policy::ValueType lsst::pex::policy::Policy::getValueType
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>).

Definition at line 1112 of file Policy.h.

1112  {
1113  throw LSST_EXCEPT(TypeError, "unknown", "not implemented for this type");
1114 }

◆ getValueType() [2/6]

template<>
Policy::ValueType lsst::pex::policy::Policy::getValueType ( )
static

◆ getValueType() [3/6]

template<>
Policy::ValueType lsst::pex::policy::Policy::getValueType ( )
static

◆ getValueType() [4/6]

template<>
Policy::ValueType lsst::pex::policy::Policy::getValueType ( )
static

◆ getValueType() [5/6]

template<>
Policy::ValueType lsst::pex::policy::Policy::getValueType ( )
static

◆ getValueType() [6/6]

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.

◆ isArray()

bool lsst::pex::policy::Policy::isArray ( const std::string name) const
inline

return true if multiple values can be retrieved via the given name.

False is returned if the name does not exist. This is equivalent to (valueCount(name) > 1).

Parameters
namethe (possibly) hierarchical name of the property of interest.

Definition at line 891 of file Policy.h.

891 { return _data->isArray(name); }

◆ isBool()

bool lsst::pex::policy::Policy::isBool ( const std::string name) const
inline

return true if the value pointed to by the given name is a boolean

Definition at line 895 of file Policy.h.

895  {
896  try {
897  return (_data->typeOf(name) == typeid(bool));
898  } catch (...) {
899  return false;
900  }
901 }

◆ isDictionary()

bool lsst::pex::policy::Policy::isDictionary ( ) const
inline

return true if it appears that this Policy actually contains dictionary definition data.

Definition at line 392 of file Policy.h.

392 { return exists("definitions"); }

◆ isDouble()

bool lsst::pex::policy::Policy::isDouble ( const std::string name) const
inline

return true if the value pointed to by the given name is a double

Definition at line 911 of file Policy.h.

911  {
912  try {
913  return (_data->typeOf(name) == typeid(double));
914  } catch (...) {
915  return false;
916  }
917 }

◆ isFile()

bool lsst::pex::policy::Policy::isFile ( const std::string name) const
inline

return true if the value pointed to by the given name is a PolicyFile

Definition at line 935 of file Policy.h.

935  {
936  try {
937  return (getValueType(name) == FILE);
938  } catch (...) {
939  return false;
940  }
941 }

◆ isInt()

bool lsst::pex::policy::Policy::isInt ( const std::string name) const
inline

return true if the value pointed to by the given name is an integer

Definition at line 903 of file Policy.h.

903  {
904  try {
905  return (_data->typeOf(name) == typeid(int));
906  } catch (...) {
907  return false;
908  }
909 }

◆ isPolicy()

bool lsst::pex::policy::Policy::isPolicy ( const std::string name) const
inline

return true if the value pointed to by the given name is a Policy

Definition at line 927 of file Policy.h.

927  {
928  try {
929  return _data->isPropertySetPtr(name);
930  } catch (...) {
931  return false;
932  }
933 }

◆ isString()

bool lsst::pex::policy::Policy::isString ( const std::string name) const
inline

return true if the value pointed to by the given name is a string

Definition at line 919 of file Policy.h.

919  {
920  try {
921  return (_data->typeOf(name) == typeid(std::string));
922  } catch (...) {
923  return false;
924  }
925 }

◆ loadPolicyFiles() [1/2]

int lsst::pex::policy::Policy::loadPolicyFiles ( bool  strict = true)
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.

Parameters
strictIf 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, "{}").
Returns
the number of files loaded

Definition at line 747 of file Policy.h.

747 { return loadPolicyFiles(boost::filesystem::path(), strict); }

◆ loadPolicyFiles() [2/2]

virtual int lsst::pex::policy::Policy::loadPolicyFiles ( const boost::filesystem::path &  repository,
bool  strict = true 
)
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.

Parameters
strictIf 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, "{}").
Returns
the number of files loaded
Parameters
repositorya 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.

◆ mergeDefaults()

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.

Parameters
defaultPolthe policy to pull default values from. This may be a Dictionary; if so, the default values will drawn from the appropriate default keyword.
keepForValidationif true, and if defaultPol is a Dictionary, keep a reference to it for validation future updates to this Policy.
errsan 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.
Returns
int the number of parameter names copied over

◆ nameCount()

int lsst::pex::policy::Policy::nameCount ( ) const
inline

How many names of parameters does this policy file have?

Definition at line 341 of file Policy.h.

341 { return _data->nameCount(); }

◆ names() [1/2]

Policy::StringArray lsst::pex::policy::Policy::names ( bool  topLevelOnly = false) const
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.

Parameters
topLevelOnlyif true, only parameter names at the top of the hierarchy will be returned; no hierarchical names will be included.

Definition at line 868 of file Policy.h.

868  {
869  StringArray out;
870  _names(out, topLevelOnly, true, 7);
871  return out;
872 }

◆ names() [2/2]

int lsst::pex::policy::Policy::names ( std::list< std::string > &  names,
bool  topLevelOnly = false,
bool  append = false 
) const
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.

Parameters
namesthe list object to be loaded
topLevelOnlyif true, only parameter names at the top of the hierarchy will be returned; no hierarchical names will be included.
appendif false, the contents of the given list will be erased before loading the names.
Returns
int the number of names added

Definition at line 855 of file Policy.h.

855  {
856  return _names(names, topLevelOnly, append, 7);
857 }

◆ paramNames() [1/2]

Policy::StringArray lsst::pex::policy::Policy::paramNames ( bool  topLevelOnly = false) const
inline

Definition at line 873 of file Policy.h.

873  {
874  StringArray out;
875  _names(out, topLevelOnly, true, 4);
876  return out;
877 }

◆ paramNames() [2/2]

int lsst::pex::policy::Policy::paramNames ( std::list< std::string > &  names,
bool  topLevelOnly = false,
bool  append = false 
) const
inline

Definition at line 858 of file Policy.h.

858  {
859  return _names(names, topLevelOnly, append, 4);
860 }

◆ policyNames() [1/2]

Policy::StringArray lsst::pex::policy::Policy::policyNames ( bool  topLevelOnly = false) const
inline

Definition at line 878 of file Policy.h.

878  {
879  StringArray out;
880  _names(out, topLevelOnly, true, 1);
881  return out;
882 }

◆ policyNames() [2/2]

int lsst::pex::policy::Policy::policyNames ( std::list< std::string > &  names,
bool  topLevelOnly = false,
bool  append = false 
) const
inline

Definition at line 861 of file Policy.h.

861  {
862  return _names(names, topLevelOnly, append, 1);
863 }

◆ print()

virtual void lsst::pex::policy::Policy::print ( std::ostream out,
const std::string label = "Policy",
const std::string indent = "" 
) const
virtual

print the contents of this policy to an output stream.

This is mainly intended for debugging purposes.

Parameters
outthe output stream to write contents to
labela labeling string to lead the listing with.
indenta string to prepend each line with.

◆ remove()

void lsst::pex::policy::Policy::remove ( const std::string name)
inline

Remove all values with a given name.

Parameters
nameThe name of the parameter to remove. Can be hierarchical name with fields delimited with ".".

Definition at line 1034 of file Policy.h.

1034 { _data->remove(name); }

◆ serialize()

template<class Archive >
void lsst::daf::base::Persistable::serialize ( Archive &  ,
unsigned int const   
)
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.

87 {}

◆ set() [1/7]

void lsst::pex::policy::Policy::set ( const std::string name,
bool  value 
)
inline

Definition at line 976 of file Policy.h.

976  {
977  _validate(name, value);
978  _data->set(name, value);
979 }

◆ set() [2/7]

void lsst::pex::policy::Policy::set ( const std::string name,
const char *  value 
)
inline

Definition at line 992 of file Policy.h.

992  {
993  if (value == NULL)
995  std::string("Attempted to assign NULL value to ") + name + ".");
996  _validate(name, std::string(value));
997  _data->set(name, std::string(value));
998 }

◆ set() [3/7]

void lsst::pex::policy::Policy::set ( const std::string name,
const FilePtr value 
)

◆ set() [4/7]

void lsst::pex::policy::Policy::set ( const std::string name,
const Ptr value 
)
inline

Definition at line 972 of file Policy.h.

972  {
973  _validate(name, value);
974  _data->set(name, value->asPropertySet());
975 }

◆ set() [5/7]

void lsst::pex::policy::Policy::set ( const std::string name,
const std::string value 
)
inline

Definition at line 988 of file Policy.h.

988  {
989  _validate(name, value);
990  _data->set(name, value);
991 }

◆ set() [6/7]

void lsst::pex::policy::Policy::set ( const std::string name,
double  value 
)
inline

Definition at line 984 of file Policy.h.

984  {
985  _validate(name, value);
986  _data->set(name, value);
987 }

◆ set() [7/7]

void lsst::pex::policy::Policy::set ( const std::string name,
int  value 
)
inline

Definition at line 980 of file Policy.h.

980  {
981  _validate(name, value);
982  _data->set(name, value);
983 }

◆ setDictionary()

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.

◆ setValue() [1/4]

template<>
void lsst::pex::policy::Policy::setValue ( const std::string name,
const bool &  value 
)

◆ setValue() [2/4]

template<>
void lsst::pex::policy::Policy::setValue ( const std::string name,
const double &  value 
)

◆ setValue() [3/4]

template<>
void lsst::pex::policy::Policy::setValue ( const std::string name,
const int &  value 
)

◆ setValue() [4/4]

template<typename T >
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

Dictionary

(see

), this operation will be checked before it is performed, and if it would create an invalid state, it will not succeed, and a

ValidationError

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

set(const string&, const string&)

and

set(const string&, const char *)

are equivalent.

Parameters
namethe name of the parameter. This can be a hierarchical name with fields delimited with "."
valuethe value–int, double, string or Policy–to associate with the name.
Exceptions
TypeErrorif this Policy is controlled by a Dictionary but the value type does not match the definition associated with the name.

Definition at line 1134 of file Policy.h.

1134  {
1135  throw LSST_EXCEPT(TypeError, name, "not implemented for this type");
1136 }

◆ str()

virtual std::string lsst::pex::policy::Policy::str ( const std::string name,
const std::string indent = "" 
) const
virtual

return a string representation of the value given by a name.

The string "<null>" is printed if the name does not exist.

Parameters
namethe name of the parameter to string-ify
indenta string to prepend each line with. If the string includes embedded newline characters, each line should be preceded by this indent string.

◆ toString()

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.

◆ typeOf()

const std::type_info & lsst::pex::policy::Policy::typeOf ( const std::string name) const
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.

951 { return getTypeInfo(name); }

◆ validate()

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

err

is null, a ValidationError will be thrown.

Parameters
errsif non-null, any validation errors will be stored here instead of being thrown.

◆ valueCount()

size_t lsst::pex::policy::Policy::valueCount ( const std::string name) const
inline

return the number of values currently associated with a given name

Parameters
namethe (possibly) hierarchical name of the property of interest.

Definition at line 889 of file Policy.h.

889 { return _data->valueCount(name); }

Member Data Documentation

◆ typeName

const char* const lsst::pex::policy::Policy::typeName[]
static

c-string forms for the supported value types.

The ValueType enum values can be used a indexes into the array to return the name of the corresping type.

Definition at line 193 of file Policy.h.


The documentation for this class was generated from the following file:
std::string
STL class.
std::shared_ptr< PropertySet >
POL_ADD
#define POL_ADD(name, value)
Definition: Policy.h:1000
lsst::pex::policy::Policy::ConstPtr
std::shared_ptr< const Policy > ConstPtr
Definition: Policy.h:170
lsst::pex::policy::Policy::typeName
static const char *const typeName[]
c-string forms for the supported value types.
Definition: Policy.h:193
lsst::pex::policy::Policy::loadPolicyFiles
int loadPolicyFiles(bool strict=true)
Recursively replace all PolicyFile values with the contents of the files they refer to.
Definition: Policy.h:747
lsst::pex::exceptions::NotFoundError
Reports attempts to access elements using an invalid key.
Definition: Runtime.h:151
lsst::pex::policy::Policy::StringArray
std::vector< std::string > StringArray
Definition: Policy.h:178
lsst::pex::policy::Policy::names
int names(std::list< std::string > &names, bool topLevelOnly=false, bool append=false) const
load the names of parameters into a given list.
Definition: Policy.h:855
ast::append
std::shared_ptr< FrameSet > append(FrameSet const &first, FrameSet const &second)
Construct a FrameSet that performs two transformations in series.
Definition: functional.cc:33
std::shared_ptr::get
T get(T... args)
lsst::pex::policy::Policy::BOOL
@ BOOL
Definition: Policy.h:186
lsst::afw::geom.transform.transformContinued.name
string name
Definition: transformContinued.py:32
lsst::pex::policy::Policy::validate
void validate(ValidationError *errs=0) const
Validate this policy, using its stored dictionary.
lsst::pex::policy::Policy::exists
bool exists(const std::string &name) const
return true if a value exists in this policy for the given name.
Definition: Policy.h:893
lsst::pex::policy::Policy::UNDETERMINED
@ UNDETERMINED
Definition: Policy.h:186
lsst::pex::policy::Policy::STRING
@ STRING
Definition: Policy.h:186
lsst::pex::policy::Policy::Ptr
std::shared_ptr< Policy > Ptr
Definition: Policy.h:169
lsst::pex::policy::Policy::getValueType
static ValueType getValueType()
A template-ized way to get the ValueType.
Definition: Policy.h:1112
POL_GETSCALAR
#define POL_GETSCALAR(name, type, vtype)
Definition: Policy.h:51
LSST_EXCEPT
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
lsst::pex::policy::Policy::canValidate
bool canValidate() const
Can this policy validate itself – that is, does it have a dictionary that it can use to validate itse...
lsst::pex::exceptions::InvalidParameterError
Reports invalid arguments.
Definition: Runtime.h:66
lsst::daf::base::Persistable
Base class for all persistable classes.
Definition: Persistable.h:75
POL_GETLIST
#define POL_GETLIST(name, type, vtype)
Definition: Policy.h:62
lsst::pex::policy::Policy::UNDEF
@ UNDEF
Definition: Policy.h:186
lsst::pex::policy::Policy::add
void add(const std::string &name, const Ptr &value)
Definition: Policy.h:1007
lsst::pex::policy::Policy::POLICY
@ POLICY
Definition: Policy.h:186
lsst::pex::policy::Policy::valueCount
size_t valueCount(const std::string &name) const
return the number of values currently associated with a given name
Definition: Policy.h:889
lsst::pex::policy::Policy::set
void set(const std::string &name, const Ptr &value)
Definition: Policy.h:972
lsst::pex::policy::Policy::getTypeInfo
const std::type_info & getTypeInfo(const std::string &name) const
return the type information for the underlying type associated with a given name.
Definition: Policy.h:943
lsst::pex::policy::Policy::FILE
@ FILE
Definition: Policy.h:186
lsst::pex::policy::Policy::INT
@ INT
Definition: Policy.h:186
lsst::pex::policy::Policy::Policy
Policy()
Create an empty policy.
lsst::pex::policy::Policy::DOUBLE
@ DOUBLE
Definition: Policy.h:186