Boost logo

Boost :

From: Dylan Cuthbert (dylan_at_[hidden])
Date: 2002-08-12 00:58:58


Hi there,

We have a similar system implemented here, using map<string,any> as the
container for the variables and supporting nested structures in the same way
you are. We also supply an "Access", which returns the local container for
a particular "structure name".

ie. (names are just made up)

int val = script_vars.get<int>( "a.b.c.d" );
or

VariableContainer& con = script_vars.access( "a.b.c" );

int val = con.get<int>( "d" ); // accesses a.b.c.d

We also supply a "get&set" function so if the variable doesn't exist, it
will set a default value for future accesses. (useful for initialising
structures in C++ code that are later "played with" via a scripting
language)

con.get( "d", a_class.val );

"val" is passed by non-const reference, if the variable exists it writes the
value in, if it doesn't exist (or is of a different type) the named variable
is overwritten by the value in class.val.

set() and exists() are also defined of course plus a few others for
debugging/display.

I think it would be nice to have such a system polished up and put in the
boost library alongside "any", although support for "variant" would be
rather cool too. So maybe the containment method could be specified via a
traits template of some kind.

As for naming, your guess is as good as mine :-) I suppose, it is a "Named
Structured and Typed Variable Container" but that seems a bit long.

Regards
---------------------------------
Q-Games, Dylan Cuthbert.
http://www.q-games.com
P2P internet radio - http://www.peercast.org

"Geoff Leyland" <geoff.leyland_at_[hidden]> wrote in message
news:65E8E052-9FC6-11D6-B49F-003065F9F514_at_epfl.ch...
> Hi,
>
> I'm new to Boost, so please excuse me if I bring up any stuff that's
> been dealt with ages ago: I've been reading the list for a while, but
> not forever, and it's a *lot* of volume. There's a few questions I'd
> like to ask, and things to propose. I've only got the released Boost
> 1.28, so if things have changed a lot since then, please excuse me again.
>
> 1) I've got some very crude classes for something I call "run-time
> structures" (naming things isn't my strong point). These are for
> handling, well, structures that get created at run time - like one has
> in MATLAB or Python or so on. If x is one I can go:
>
> x("a.b") = 2.0;
> x("a.c.d") = "hello";
>
> if (x("a.c.d").isa<string>())
> std::cout << x("a.c.d").be<string>();
>
> and so on. It throws semi-informative exceptions for wrong types and
> has a nasty little type-promotion mechanism so that, for example, char
> *'s are stored as strings. It's *very* rudimentary, and it only does
> what I need it to do. However, what I need it to do is slowly getting
> more complex. In the long run I can dream of it reading these in from
> text files, which shouldn't be too hard, or changing the underlying
> representation to match MATLAB's or Python's (if that's what you're
> trying to talk to).
>
> I looked quite hard on the web for some existing code to do this before
> I started, but didn't find any. Surely it must have been done a million
> times before (for all those scripting languages.). Did I not look hard
> enough?
>
> Anyway, it uses a class (called "object" - told you I sucked at names)
> for storing its members in. On seeing "any" in Boost, I thought I would
> be much better off using that (using nice libraries is better than my
> cruft any day), but looking at any.hpp, I can see that the approaches
> are a bit different. My object is the equivalent of the holder in any,
> I think. I also see on the list that any and variant (though I've not
> got variant in boost 1.28) are being redefined.
>
> So, two questions :
> Would anyone working on any and variant be interested in what I've got
> (it's really not much) or even just my opinion on what would be nice for
> their any/variant to do? I'd certainly be interested in getting recent
> copies of any and variant.
> Would anyone else be interested in "run-time structures" as described
> above? If so, what's a better name? An even better question is: does
> this exist anywhere else?
>
> 2) I noticed at the end of random library documentation that Jens Maurer
> asks for Quasi-random sequence generators. I've got a Sobol sequence
> generator (not a big deal, they're very short), but I also found (from a
> source far more reputable than me) starting data for up to 1111
> dimensions. Would anyone be interested in this being added to the
> random library?
>
> If you reply, please reply to me as well as the list : I'm only getting
> the digest.
>
> Cheers,
> goof
>
> _______________________________________________
> Unsubscribe & other changes:
http://lists.boost.org/mailman/listinfo.cgi/boost
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk