You could use an implicit constructor, e.g.

template<typename T>
class Value {
  Value(T);
  Value(const Value<T>&);
};

class Value<int>;

template<T>
void addMeta(const std::string&, const Value<T>& v) {
  Value<T>* localcopy = new Value<T>(v);
}

so the function call:

addMeta("myMeta", 5);

is implicitly converted to:

addMeta(std::string("myMeta"), Value<int>(5));


Two considerations:
 - There is some copying involved, which might be undesirable for large
arrays.  C++ 2011 move constructors are intended to solve this problem
in general, but it's unlikely that OSG compatibility requirements will
allow the use of C++ 2011 features for a while.

 - The way it is described here, any customization for Value<T> must
occur through template specialization, rather than subclassing.  To
support subclassing, use a clone() method instead of new Value<T>(v).

On a related note, my preference would be for the Value<T> class to be
immutable so that you are required to set metadata values through the
API rather than poking  Value<T> objects directly.  This is necessary if
you want to support alternate backing stores which don't use Value<T>
objects in the backend at all.

- Peter

On 4/15/2011 11:10 AM, Sukender wrote:
> Hi Peter,
>
> Thanks... but what for the addMeta<T>()?
> I mean it's okay having a addMeta(string, ValueBase *), but this will force 
> you to write
>     o->addMeta( "myMeta", new Value<int>(5) );
> instead of simply
>     o->addMeta( "myMeta", 5 );
> which could be nice. Any idea?
>
> Sukender
> PVLE - Lightweight cross-platform game engine - http://pvle.sourceforge.net/
-- 
Peter Amstutz
Senior Software Engineer
Technology Solutions Experts
Natick, MA
02131

_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to