Home Help Center

return value of getPropertyAsInt

n2503vn2503v Member Alex MakarenkoOrganization: ACFR, University of SydneyProject: Orca ✭✭✭
The Ice reference manual says:

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

Comments

  • matthewmatthew NL, CanadaMember Matthew NewhookOrganization: ZeroC, Inc.Project: Internet Communications Engine ✭✭✭
    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.
  • n2503vn2503v Member Alex MakarenkoOrganization: ACFR, University of SydneyProject: Orca ✭✭✭
    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.

    alex
  • michimichi Member Michi HenningOrganization: Triodia TechnologiesProject: I have a passing interest in Ice :-) ✭✭✭
    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.

    Cheers,

    Michi.
Sign In or Register to comment.