Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Ticket #713 (closed enhancement: fixed)

Opened 10 months ago

Last modified 10 months ago

Change tango.text.Properties interface to be more consistent

Reported by: schveiguy Assigned to: kris
Priority: normal Milestone: 0.99.3
Component: Core Functionality Version: trunk
Keywords: Cc:

Description

The current interface for the Properties object is inconsistent. Loading properties consists of passing a delegate to handle the properties as they are read. Saving properties involves passing an AA to the Properties object. This means that if you don't want to create a temporary AA to do the save, you should always have a delegate that loads the properties into an AA.

I propose that the interface be changed to use an interface to an object to read and write the properties from the file. This allows a coder to specify their own method of storage and allow using the Properties object to save/load. Attached is an updated version of Properties.d. I also attached a SimplePropertyMap? object which wraps an AA with the appropriate interface. It would be trivial to create a PropertyMap? derivative that uses a tango.util.collection.model.Map object as its storage.

Attachments

SimplePropertyMap.d (1.8 kB) - added by schveiguy on 10/29/07 18:09:28.
Simple implementation of PropertyMap? interface
Properties.d (8.3 kB) - added by schveiguy on 10/31/07 16:33:12.
updated version of Properties.d

Change History

10/29/07 17:17:58 changed by schveiguy

  • owner changed from sean to kris.

10/29/07 18:09:28 changed by schveiguy

  • attachment SimplePropertyMap.d added.

Simple implementation of PropertyMap? interface

10/31/07 10:31:27 changed by schveiguy

Don't use this yet, there is an issue because the add function is not using the dup property of the strings as they are read, so the properties could become corrupted. I will fix the Properties.d file and upload it later.

10/31/07 16:33:12 changed by schveiguy

  • attachment Properties.d added.

updated version of Properties.d

10/31/07 16:33:49 changed by schveiguy

OK, safe to use now.

(follow-up: ↓ 5 ) 11/02/07 23:12:58 changed by kris

  • status changed from new to assigned.
  • milestone set to 0.99.4.

I'm a bit unsure about the change here, since wrapping the native AA type seems to be somewhat redundant? I suspect we can do better than this, and it may help to consider a Stream oriented approach. Experimenting ...

(in reply to: ↑ 4 ) 11/03/07 00:44:53 changed by schveiguy

Replying to kris:

I think you might be right. If the PropertyMap? interface is used more as a conversion class instead of both the conversion class AND the final container of the properties, no reimplementation of the AA methods is necessary. To do this, we just get rid of all methods in the PropertyMap? interface except for:

// use this when reading properties from a file
void add(T[] name, T[] value);

// use this when reading properties from memory to write to a file.
int opApply(int delegate(ref T[] name, ref T[] value) dg);

Then SimplePropertyMap? takes an AA reference as an argument to use as a property storage container. Once you are done loading the properties, you use the AA directly, then save them using SimplePropertyMap? again.

Maybe even the Properties class itself could be changed into a filter you attach to a stream. I haven't used the streams interfaces yet, so I'm not sure how that works.

11/03/07 17:19:25 changed by kris

  • status changed from assigned to closed.
  • resolution set to fixed.

already done and checked-in :)

Thanks, schveiguy

11/03/07 17:19:47 changed by kris

  • milestone changed from 0.99.4 to 0.99.3.

11/05/07 21:29:03 changed by schveiguy

  • status changed from closed to reopened.
  • resolution deleted.

The current version does not address the inconsistency I was thinking of. The inconsistency is in the difference between the second argument of the load/save functions.

static void load (InputStream stream, void delegate (T[] name, T[] value) dg)
...
static void save (OutputStream stream, T[][T[]] properties)
...

Note that the load function allows any method of loading the properties as long as you provide a function to handle them as they arrive, whereas the save method REQUIRES you to store your properties in an associative array before saving.

11/05/07 23:15:14 changed by kris

you're not looking at MapStream? though ... ?

(follow-up: ↓ 11 ) 11/05/07 23:32:35 changed by kris

it's perhaps not ideal, but it's pretty close to what you were thinking of? The opApply() is quite useful in this context: http://dsource.org/projects/tango/browser/trunk/tango/io/stream/MapStream.d

(in reply to: ↑ 10 ) 11/06/07 11:35:40 changed by schveiguy

Replying to kris:

Yes, this is exactly what I was thinking of. I suppose I expected it to appear in place of Properties.d instead of in a new class:)

Does this not deprecate Properties.d? At least Properties.d should be implemented in terms of MapStream? to make how property files are parsed more maintainable.

11/06/07 12:35:13 changed by kris

  • status changed from reopened to closed.
  • resolution set to fixed.

Properties.d will be deprecated, probably in the release after this one :)