This forum has been archived. Please start a new discussion on GitHub.

return value of getPropertyAsInt

The Ice reference manual says:

int getPropertyAsInt(string key);
Get a property as an integer. If the property does not exist, 0 is returned."

Is there a way then to differentiate between the following two cases:
1) The property was specified with value 0
2) The property was not specified

thanks, alex


  • matthew
    matthew NL, Canada
    Not with that method, no. If you want to find out whether the property exists if you can call getPropertiesForPrefix with the property name. If the result set contains the property it exists. Beware though that this method isn't very efficient.
  • Thanks, it makes sense. I was thinking of testing with getProperty() to see if it returns an empty string, but it suffers from the same problem.

  • In general, I would recommend to avoid designs that need to distinguish between a property not being set, and a property being set to the default value that is returned by getProperty() and getPropertyAsInt() for a property that doesn't exist.

    The situation is analogous to shell environment variables. You can't tell the difference between a variable that isn't set and a variable that is set to the empty string.

    You will probably find that your code becomes cleaner and easier to maintain if you define semantics for properties such that the default value (empty string or zero) is what takes effect when a property is not set. That way, there is no need to distinguish between an unset property and one that's set to the default.