[xsd-users] Accessors for sequences

Boris Kolpackov boris at codesynthesis.com
Fri May 30 10:44:47 EDT 2008


Hi Manav,

Manav Rathi <manav.rathi at incainformatics.com> writes:

> Presently the unbounded occurring elements like
>   "<element name="member" type="string" minOccurs="unbounded"/>"
> are translated to 
>   "member_sequence& member();"
> Thus, to use this sequence in, say, a BOOST_FOREACH, I have to write
>   "foreach(member_type & member, e.member())"
> 
> I would suggest the following variation. Accessors for sequences are named
> by appending a 's' at the end. So our example becomes
>   "foreach(member_type & member, e.members())"
> This seems more 'natural'.

Hm, I think I agree this might be a more natural naming convention.
However:

(1) Using a name other than the element name may result in conflicts
    (e.g., you could have both 'member' and 'members' elements in the
    same type). This, however, would probably happen seldom enough for
    us to ignore it.

(2) Changing the default naming convention would break thing for hundreds
    of people.

Probably the only practical way to support this is to add an option for
custom regex transformations (see below).


> Also, is there any way to do this currently (by using some sort of regex)?

Kind of. There are --accessor-regex and --modifier-regex options but
they don't distinguish between one/optional/sequence. So if you have
two elements 'member' in two different types one is sequence and the
other is not, then you are out of luck. You will also have to add a
regex for each sequence element which can be quite a pain if you have
a lot of them.

I guess we could add a bunch more options (we already have almost a
hundred options for the C++/Tree mapping so a few more, a few less,
I am sure nobody will notice ;-)). Something along these lines:

--one-accessor-regex
--one-modifier-regex

--opt-accessor-regex
--opt-modifier-regex

--seq-accessor-regex
--seq-modifier-regex

I've added this to my TODO list. If you would like to start using
these new options I can probably implement them on Monday and build
you a pre-release binary. Let me know if you would like that.

And thanks for the suggestion.

Boris




More information about the xsd-users mailing list