/*
Copyright 2007-2013 The NGenerics Team
(https://github.com/ngenerics/ngenerics/wiki/Team)
This program is licensed under the GNU Lesser General Public License (LGPL). You should
have received a copy of the license along with the source code. If not, an online copy
of the license can be found at http://www.gnu.org/copyleft/lesser.html.
*/
using System;
using System.Diagnostics.CodeAnalysis;
using NGenerics.Util;
namespace NGenerics.Patterns.Visitor
{
///
/// A visitor that visits objects in order (PreOrder, PostOrder, or InOrder).
/// Used primarily as a base class for Visitors specializing in a specific order type.
///
/// The type of objects to be visited.
public class OrderedVisitor : IVisitor
{
#region Globals
private readonly IVisitor visitorToUse;
#endregion
#region Construction
/// The visitor to use when visiting the object.
/// is a null reference (Nothing in Visual Basic).
public OrderedVisitor(IVisitor visitorToUse)
{
Guard.ArgumentNotNull(visitorToUse, "visitorToUse");
this.visitorToUse = visitorToUse;
}
#endregion
#region IOrderedVisitor Members
///
/// Determines whether this visitor is done.
///
///
///
/// true if this visitor is done; otherwise, false.
///
public bool HasCompleted
{
get
{
return visitorToUse.HasCompleted;
}
}
///
/// Visits the object in pre order.
///
/// The obj.
[SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "PreOrder")]
public virtual void VisitPreOrder(T obj)
{
visitorToUse.Visit(obj);
}
///
/// Visits the object in post order.
///
/// The obj.
public virtual void VisitPostOrder(T obj)
{
visitorToUse.Visit(obj);
}
///
/// Visits the object in order.
///
/// The obj.
public virtual void VisitInOrder(T obj)
{
visitorToUse.Visit(obj);
}
///
public void Visit(T obj)
{
visitorToUse.Visit(obj);
}
#endregion
#region Public Members
///
/// Gets the visitor to use.
///
/// The visitor to use.
public IVisitor VisitorToUse
{
get
{
return visitorToUse;
}
}
#endregion
}
}