Hi guys,

On 1/12/09 7:20 PM, Chris 'Xenon' Hanson wrote:
> Thrall, Bryan wrote:
>> This seems overly complicated to me; couldn't we just rely on users
>> knowing the type they want for a given key, like we rely on them knowing
>> what subclass of UserData they want now? That way, UserPropertyContainer
>> is simply an std::map<string,ref_ptr<Referenced> >. The UserData API
>> would store its Referenced pointer, and the Description API could store
>> a vector of strings:

I agree with Bryan that we should rely on users knowing what they stored and 
what they want.

>   This works pretty well for objects that are Referenced, but I was looking 
> for a good way
> to store basic integer and floating-point values in the properties. There 
> would need to be
> a little more fleshing out to accomplish that, but I imagine one could make a 
> class
> derived from Referenced that contained a float or an int.

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?
Cheers,
/ulrich

PS: boost has a variant class but I'm not sure if that's overkill.
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to