[haiku-3rdparty-dev] Re: Saving preferences

On Sat, Jun 2, 2012 at 2:56 PM, David Rawson Couzelis
<drcouzelis@xxxxxxxxx> wrote:
> But I'm confused as to how to store data that can change size. Namely, I
> have a BList of RSS feeds ("Feed" class) and each feed has a BList of
> news items ("Item" class).

Two things to be aware of here: first of all, BMessage supports
multiple indices per name, i.e. calling AddInt32 multiple times with
the same field name will result in multiple values for that name,
which can then be retrieved with the variants of FindInt32 that take
an index parameter [1].

In conjunction with that, you can also store one BMessage within
another. For instance, you could create a message representing one of
your feeds, which stores the news items (or even take it one step
further and also create a message for each news item containing all
the parameters needed to reconstruct it, i.e. what classes
implementing BFlattenable[2] do). You can then add each feed message
to the main settings message using the aforementioned multiple index
functionality.

Hope this helps,

Rene

[1] http://www.haiku-os.org/legacy-docs/bebook/BMessage.html#BMessage_FindData
[2] http://www.haiku-os.org/legacy-docs/bebook/BFlattenable.html

Other related posts: