The Properties
interface provides the following operations for reading property values:
string getProperty(string key)
string getPropertyWithDefault(string key, string value)
int getPropertyAsInt(string key)
int getPropertyAsIntWithDefault(string key, int value)
StringSeq getPropertyAsList(string key)
StringSeq getPropertyAsListWithDefault(string key, StringSeq value)
getPropertyAsList
above). If the property is not set or set to an empty value, the operation returns the supplied default value.PropertyDict getPropertiesForPrefix(string prefix)
PropertyDict
. This operation is useful if you want to extract the properties for a specific subsystem. For example,getPropertiesForPrefix("Filesystem")
returns all properties that start with the prefix Filesystem
, such as Filesystem.MaxFileSize
. You can then use the usual dictionary lookup operations to extract the properties of interest from the returned dictionary.With these operations, using application-specific properties now becomes the simple matter of initializing a communicator as usual, getting access to the communicator's properties, and examining the desired property value. For example:
{zcode:cpp} // ... Ice::CommunicatorPtr ic; // ... ic = Ice::initialize(argc, argv); // Get the maximum file size. // Ice::PropertiesPtr props = ic->getProperties(); Ice::Int maxSize = props->getPropertyAsIntWithDefault("Filesystem.MaxFileSize", 1024); // ... {zcode} |
Assuming that you have created a configuration file that sets the Filesystem.MaxFileSize
property (and that you have set the ICE_CONFIG
variable or the --Ice.Config
option accordingly), your application will pick up the configured value of the property.
The technique shown above allows you to obtain application-specific properties from a configuration file. If you also want the ability to set application-specific properties on the command line, you will need to parse command-line options for your prefix. (Calling |