Hi Jeremy,

Most OSG objects implement the clone operator with CopyOp parameter so
you can just pass this along.  For objects like std::vector etc you
would typically just implement a deep copy, i.e. copy all the
contents, unless of course its a vector of ref_ptr<>'s in which case
copying the contents of the vector shares the pointers so you have to
do a element by element deep copy op on the objects if that's what is
required.

To see examples of various ways of implementing the copy operator have
a look at the implementations - they are all over the OSG.

Robert.

On Feb 18, 2008 5:10 PM, Jeremy Moles <[EMAIL PROTECTED]> wrote:
> I have a quick question that I may be over-thinking, of which I have yet
> to find a simple answer.
>
> Imagine that I have a class Derived from osg::MatrixTransform--let's
> call this osgWidget::Window. In my derived Window class, I have a number
> of osg::ref_ptr<> objects referencing various things that get added to
> the Window object itself, and which I keep around for ease of use
> elsewhere in the API.
>
> I want to provide suitable copy constructors (and am required to do so
> by using the META_Object macro, thankfully), but I'm beginning to see a
> definite problem when setting the pointers in the "new" copies ref_ptr
> object. Usually I can come up with clever tricks to do so, but generally
> it's not very straightforward--which leads me to my main question: is it
> generally bad design to keep ref_ptr's around like this when designing
> classes that will directly derive from OSG objects? Using
> osg::CopyOp::DEEP_COPY_ALL ensures that I will get a full copy of the
> subgraph, which is certainly the desired behavior, but I'm not entirely
> sure I know the best way to easily set any internal ref_ptr's to the new
> subgraph after copy other than--like I mentioned earlier--clever
> tricks. :) Below is an example of one such abomination:
>
>
>
> // Here we're in the copy ctor()
> Window::Window(const Window& w, const CopyOp& co):
> MatrixTransform(w, co) {
>         ColorArray* c = dynamic_cast<ColorArray*>(getColorArray());
>
>         if(c) _c = c;
> }
>
>
>
> ...where _c is my osg::ref_ptr<ColorArray> object, and where
> getColorArray() works because we're using DEEP_COPY_ALL and we assume
> all of the geometry was deeply copied into the new object.
>
> I really feel like I'm missing an easier way to do this...
>
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to