From 50d066d7566dacc2d8597e69fef4412520eacd24 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 2 Apr 2004 15:45:34 +0000 Subject: [PATCH] From Bob Kuehne, reworked code to use a marco instead of duplicated code, done as measure for reducing the risk of copy and paste errors. --- src/osg/CopyOp.cpp | 90 +++++++++++----------------------------------- 1 file changed, 20 insertions(+), 70 deletions(-) diff --git a/src/osg/CopyOp.cpp b/src/osg/CopyOp.cpp index e7ac333da..14bb77218 100644 --- a/src/osg/CopyOp.cpp +++ b/src/osg/CopyOp.cpp @@ -1,4 +1,4 @@ -/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2004 Robert Osfield * * This library is open source and may be redistributed and/or modified under * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or @@ -21,42 +21,30 @@ using namespace osg; +#define COPY_OP( TYPE, FLAG ) \ +TYPE* CopyOp::operator() (const TYPE* obj) const \ +{ \ + if (obj && _flags&FLAG) \ + return dynamic_cast( obj->clone(*this) ); \ + else \ + return const_cast(obj); \ +} + +COPY_OP( Object, DEEP_COPY_OBJECTS ); +COPY_OP( Node, DEEP_COPY_NODES ); +COPY_OP( Drawable, DEEP_COPY_DRAWABLES ); +COPY_OP( StateSet, DEEP_COPY_STATESETS ); +COPY_OP( Texture, DEEP_COPY_TEXTURES ); +COPY_OP( Image, DEEP_COPY_IMAGES ); +COPY_OP( Array, DEEP_COPY_DRAWABLES ); +COPY_OP( PrimitiveSet, DEEP_COPY_PRIMITIVES ); +COPY_OP( Shape, DEEP_COPY_SHAPES ); + Referenced* CopyOp::operator() (const Referenced* ref) const { return const_cast(ref); } -Object* CopyOp::operator() (const Object* obj) const -{ - if (obj && _flags&DEEP_COPY_OBJECTS) - return obj->clone(*this); - else return const_cast(obj); -} - -Node* CopyOp::operator() (const Node* node) const -{ - if (node && _flags&DEEP_COPY_NODES) - return dynamic_cast(node->clone(*this)); - else - return const_cast(node); -} - -Drawable* CopyOp::operator() (const Drawable* drawable) const -{ - if (drawable && _flags&DEEP_COPY_DRAWABLES) - return dynamic_cast(drawable->clone(*this)); - else - return const_cast(drawable); -} - -StateSet* CopyOp::operator() (const StateSet* stateset) const -{ - if (stateset && _flags&DEEP_COPY_STATESETS) - return dynamic_cast(stateset->clone(*this)); - else - return const_cast(stateset); -} - StateAttribute* CopyOp::operator() (const StateAttribute* attr) const { if (attr && _flags&DEEP_COPY_STATEATTRIBUTES) @@ -75,42 +63,4 @@ StateAttribute* CopyOp::operator() (const StateAttribute* attr) const return const_cast(attr); } -Texture* CopyOp::operator() (const Texture* text) const -{ - if (text && _flags&DEEP_COPY_TEXTURES) - return dynamic_cast(text->clone(*this)); - else - return const_cast(text); -} - -Image* CopyOp::operator() (const Image* image) const -{ - if (image && _flags&DEEP_COPY_IMAGES) - return dynamic_cast(image->clone(*this)); - else return const_cast(image); -} - -Array* CopyOp::operator() (const Array* array) const -{ - if (array && _flags&DEEP_COPY_ARRAYS) - return dynamic_cast(array->clone(*this)); - else - return const_cast(array); -} - -PrimitiveSet* CopyOp::operator() (const PrimitiveSet* primitive) const -{ - if (primitive && _flags&DEEP_COPY_PRIMITIVES) - return dynamic_cast(primitive->clone(*this)); - else - return const_cast(primitive); -} - -Shape* CopyOp::operator() (const Shape* shape) const -{ - if (shape && _flags&DEEP_COPY_SHAPES) - return dynamic_cast(shape->clone(*this)); - else - return const_cast(shape); -}