#region CPL License /* Nuclex Framework Copyright (C) 2002-2009 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #endregion using System; using Microsoft.Xna.Framework; namespace Nuclex.Geometry.Volumes { /// Base class for volume visitors /// /// See the visitor pattern. /// /// If you need to perform work on a volume whose type you do not know, you could /// of course just create a set of if(volume is ...) queries. However, you would /// have to manually track down all these queries should a future version of this /// library provide a new type of volume. /// /// /// Your other option is to create a special class that does your work which derives /// from this VolumeVisitor class. It will elegantly resolve the volume type by /// calling into the volume (resolving the type via the vtable) which then calls /// the visitor's distinctive method for the exact kind of volume. If a new volume /// is introduced to the library, it will be added to the VolumeVisitor class and /// your compiler will point out to you where you need to extend your code for the /// new kind of volume because the abstract method will not yet be implemented there. /// /// public abstract class VolumeVisitor { /// Visit a volume and do the action the visitor is intended for /// Volume to visit public void Visit(IVolume3 volume) { volume.Accept(this); } /// Visit an axis aligned box /// Box to visit public abstract void Visit(AxisAlignedBox3 box); /// Visit an oriented box /// Box to visit public abstract void Visit(Box3 box); /// Visit a sphere /// Sphere to visit public abstract void Visit(Sphere3 sphere); /// Visit a cylinder /// Cylinder to visit public abstract void Visit(Cylinder3 cylinder); /// Visit a triangle mesh /// Mesh to visit public abstract void Visit(TriangleMesh3 mesh); } } // namespace Nuclex.Geometry.Volumes