Hi Ulrich et. al,

Comments at bottom of mail... but first some context for my comments :-)

On Wed, Dec 2, 2009 at 9:36 AM, Ulrich Hertlein <[email protected]> wrote:
> Agreed, maybe for basic data types we could use a simple Variant class:
>
> class Variant : Referenced
> {
> public:
>    Variant() : Referenced() {
>        ::memset(&_variant, 0, sizeof(_variant));
>    }
>
>    inline void set(int i) { _variant.i = i; }
>    inline void set(long long ll) { _variant.ll = ll; }
>    inline void set(float f) { _variant.f = f; }
>    inline void set(double d) { _variant.d = d; }
>    inline void set(void* vp) { _variant.vp = vp; }
>
>    inline int geti() const { return _variant.i; }
>    inline long long getll() const { return _variant.ll; }
>    inline float getf() const { return _variant.f; }
>    inline double getd() const { return _variant.d; }
>    inline void* getv() const { return _variant.vp; }
>
> private:
>    union VariantData {
>        int i;
>        long long ll;
>        float f;
>        double d;
>        void* vp;
>    };
>    VariantData _variant;
> };
>
> Usage would be something like this:
>
> UserProps& props = node->getUserProps();
> props.get("earth.g")->set(-9.81f);
> float g = props.get("earth.g")->getf();
>
> If we wanted this could be shortened to something like:
>
> props.set("earth.g", -9.81f);
> float g = props.getf("earth.g");
>
> Thoughts?

I've done something similar to this in the OSG in the
osg::ArgumnetParser::Parameter class - this one uses a union
internally like the Variant class above, with the twist that it's for
passing in data to be set so it uses a pointer to each datatype rather
than the actual data.  The Parameter class is used to avoid the need
for many different read(..) methods for each type.  I've also adopted
this technique in the osgDB::Input class to enable the same type of
functionality with providing read(Parameter,...) that are really
convenient to use.

One could use that osg::ArgumnetParser::Parameter approach in the new
scheme being discussed for getting data out of the container object in
convenient and type-safe way.

Robert.
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to