Home Help Center

How to load empty properties?

n2503vn2503v Member Alex MakarenkoOrganization: ACFR, University of SydneyProject: Orca ✭✭✭
Ice v.3.1.0, C++.

I use Ice Properties facility to configure my own application. I was trying to use the feature of setting a property to an empty string in order to unset any previously loaded value. Internally Ice does it for files specified with --Ice.Config (Sec. 28.3)

It seems that either Properties::load() or Properties::getCommandLineOptions() strips the empty properties. For example, i have this config file:
# Example config file for Ice
Ice.MessageSizeMax = 2048 # Largest message size is 2MB
Ice.Trace.Network=3 # Highest level of tracing for network
Ice.Trace.Protocol= # Disable protocol tracing

I load it like this:
Ice::PropertiesPtr p = Ice::createProperties();
p->load( filename );
Ice::StringSeq propSeq = p->getCommandLineOptions();
 
cout<<"loaded "<<propSeq.size()<<" properties"<<endl;
for ( unsigned int i=0; i<propSeq.size(); ++i ) {
  cout<<propSeq[i]<<endl;
}

and get this output:
loaded 2 properties
--Ice.MessageSizeMax=2048
--Ice.Trace.Network=3

So now I cannot tell if Ice.Trace.Protocol was specified in the file. Of course, the result is the same if I use getProperty() on THIS properties set, but if I want to override some "global" config setting then I cannot do it.

Is this the expected behaviour? Would it make sense to preserve all specified properties?

Thanks, Alex

Comments

  • bernardbernard Jupiter, FLAdministrators, ZeroC Staff Bernard NormierOrganization: ZeroC, Inc.Project: Ice ZeroC Staff
    Hi Alex,

    That's the expected behavior. "Setting" a property to the empty string means unsetting this property if it is already set.

    Usually, this means resetting the property to its default behavior. From the Ice manual:

    "If not stated otherwise in the description of the individual properties, the default value for all properties is the empty string. If the property takes a numeric value, the empty string is interpreted as zero."

    Cheers,
    Bernard
Sign In or Register to comment.