From c0cdb2ad99a1e2a6ade5ce76c91177a79258e669 Mon Sep 17 00:00:00 2001 From: Daniel Wilhelm Date: Fri, 18 Apr 2014 17:10:11 +0200 Subject: 3.14 --- shared/loki/Visitor.h | 314 +++++++++++++++++++++++++------------------------- 1 file changed, 157 insertions(+), 157 deletions(-) (limited to 'shared/loki/Visitor.h') diff --git a/shared/loki/Visitor.h b/shared/loki/Visitor.h index 4425a9fa..f6b0ad81 100644 --- a/shared/loki/Visitor.h +++ b/shared/loki/Visitor.h @@ -2,14 +2,14 @@ // The Loki Library // Copyright (c) 2001 by Andrei Alexandrescu // This code accompanies the book: -// Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design +// Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design // Patterns Applied". Copyright (c) 2001. Addison-Wesley. -// Permission to use, copy, modify, distribute and sell this software for any -// purpose is hereby granted without fee, provided that the above copyright -// notice appear in all copies and that both that copyright notice and this +// Permission to use, copy, modify, distribute and sell this software for any +// purpose is hereby granted without fee, provided that the above copyright +// notice appear in all copies and that both that copyright notice and this // permission notice appear in supporting documentation. -// The author or Addison-Wesley Longman make no representations about the -// suitability of this software for any purpose. It is provided "as is" +// The author or Addison-Wesley Longman make no representations about the +// suitability of this software for any purpose. It is provided "as is" // without express or implied warranty. //////////////////////////////////////////////////////////////////////////////// #ifndef LOKI_VISITOR_INC_ @@ -28,17 +28,17 @@ namespace Loki //////////////////////////////////////////////////////////////////////////////// /// \class BaseVisitor -/// +/// /// \ingroup VisitorGroup /// The base class of any Acyclic Visitor //////////////////////////////////////////////////////////////////////////////// - class BaseVisitor - { - public: - virtual ~BaseVisitor() {} - }; - +class BaseVisitor +{ +public: + virtual ~BaseVisitor() {} +}; + //////////////////////////////////////////////////////////////////////////////// /// \class Visitor /// @@ -48,7 +48,7 @@ namespace Loki /// \par Usage /// /// Defining the visitable class: -/// +/// /// \code /// class RasterBitmap : public BaseVisitable<> /// { @@ -59,7 +59,7 @@ namespace Loki /// /// Way 1 to define a visitor: /// \code -/// class SomeVisitor : +/// class SomeVisitor : /// public BaseVisitor // required /// public Visitor, /// public Visitor @@ -72,7 +72,7 @@ namespace Loki /// /// Way 2 to define the visitor: /// \code -/// class SomeVisitor : +/// class SomeVisitor : /// public BaseVisitor // required /// public Visitor /// { @@ -84,7 +84,7 @@ namespace Loki /// /// Way 3 to define the visitor: /// \code -/// class SomeVisitor : +/// class SomeVisitor : /// public BaseVisitor // required /// public Visitor::Type> /// { @@ -97,7 +97,7 @@ namespace Loki /// \par Using const visit functions: /// /// Defining the visitable class (true for const): -/// +/// /// \code /// class RasterBitmap : public BaseVisitable /// { @@ -108,7 +108,7 @@ namespace Loki /// /// Defining the visitor which only calls const member functions: /// \code -/// class SomeVisitor : +/// class SomeVisitor : /// public BaseVisitor // required /// public Visitor, /// { @@ -119,38 +119,38 @@ namespace Loki /// /// \par Example: /// -/// test/Visitor/main.cpp +/// test/Visitor/main.cpp //////////////////////////////////////////////////////////////////////////////// - template - class Visitor; +template +class Visitor; - template - class Visitor - { - public: - typedef R ReturnType; - typedef T ParamType; - virtual ~Visitor() {} - virtual ReturnType Visit(ParamType&) = 0; - }; - - template - class Visitor - { - public: - typedef R ReturnType; - typedef const T ParamType; - virtual ~Visitor() {} - virtual ReturnType Visit(ParamType&) = 0; - }; +template +class Visitor +{ +public: + typedef R ReturnType; + typedef T ParamType; + virtual ~Visitor() {} + virtual ReturnType Visit(ParamType&) = 0; +}; + +template +class Visitor +{ +public: + typedef R ReturnType; + typedef const T ParamType; + virtual ~Visitor() {} + virtual ReturnType Visit(ParamType&) = 0; +}; //////////////////////////////////////////////////////////////////////////////// // class template Visitor (specialization) // This specialization is not present in the book. It makes it easier to define // Visitors for multiple types in a shot by using a typelist. Example: // -// class SomeVisitor : +// class SomeVisitor : // public BaseVisitor // required // public Visitor // { @@ -160,41 +160,41 @@ namespace Loki // }; //////////////////////////////////////////////////////////////////////////////// - template - class Visitor, R, false> - : public Visitor, public Visitor - { - public: - typedef R ReturnType; - // using Visitor::Visit; - // using Visitor::Visit; - }; - - template - class Visitor, R, false> : public Visitor - { - public: - typedef R ReturnType; - using Visitor::Visit; - }; - - template - class Visitor, R, true> - : public Visitor, public Visitor - { - public: - typedef R ReturnType; - // using Visitor::Visit; - // using Visitor::Visit; - }; - - template - class Visitor, R, true> : public Visitor - { - public: - typedef R ReturnType; - using Visitor::Visit; - }; +template +class Visitor, R, false> + : public Visitor, public Visitor +{ +public: + typedef R ReturnType; + // using Visitor::Visit; + // using Visitor::Visit; +}; + +template +class Visitor, R, false> : public Visitor +{ +public: + typedef R ReturnType; + using Visitor::Visit; +}; + +template +class Visitor, R, true> + : public Visitor, public Visitor +{ +public: + typedef R ReturnType; + // using Visitor::Visit; + // using Visitor::Visit; +}; + +template +class Visitor, R, true> : public Visitor +{ +public: + typedef R ReturnType; + using Visitor::Visit; +}; //////////////////////////////////////////////////////////////////////////////// @@ -203,29 +203,29 @@ namespace Loki // functions) //////////////////////////////////////////////////////////////////////////////// - template class BaseVisitorImpl; +template class BaseVisitorImpl; + +template +class BaseVisitorImpl, R> + : public Visitor + , public BaseVisitorImpl +{ +public: + // using BaseVisitorImpl::Visit; + + virtual R Visit(Head&) + { return R(); } +}; + +template +class BaseVisitorImpl, R> + : public Visitor +{ +public: + virtual R Visit(Head&) + { return R(); } +}; - template - class BaseVisitorImpl, R> - : public Visitor - , public BaseVisitorImpl - { - public: - // using BaseVisitorImpl::Visit; - - virtual R Visit(Head&) - { return R(); } - }; - - template - class BaseVisitorImpl, R> - : public Visitor - { - public: - virtual R Visit(Head&) - { return R(); } - }; - //////////////////////////////////////////////////////////////////////////////// // class template BaseVisitable //////////////////////////////////////////////////////////////////////////////// @@ -241,61 +241,61 @@ struct DefaultCatchAll // class template BaseVisitable //////////////////////////////////////////////////////////////////////////////// - template - < - typename R = void, - template class CatchAll = DefaultCatchAll, - bool ConstVisitable = false - > - class BaseVisitable; +template +< +typename R = void, + template class CatchAll = DefaultCatchAll, + bool ConstVisitable = false + > +class BaseVisitable; - template class CatchAll> - class BaseVisitable +template class CatchAll> +class BaseVisitable +{ +public: + typedef R ReturnType; + virtual ~BaseVisitable() {} + virtual ReturnType Accept(BaseVisitor&) = 0; + +protected: // give access only to the hierarchy + template + static ReturnType AcceptImpl(T& visited, BaseVisitor& guest) { - public: - typedef R ReturnType; - virtual ~BaseVisitable() {} - virtual ReturnType Accept(BaseVisitor&) = 0; - - protected: // give access only to the hierarchy - template - static ReturnType AcceptImpl(T& visited, BaseVisitor& guest) + // Apply the Acyclic Visitor + if (Visitor* p = dynamic_cast*>(&guest)) { - // Apply the Acyclic Visitor - if (Visitor* p = dynamic_cast*>(&guest)) - { - return p->Visit(visited); - } - return CatchAll::OnUnknownVisitor(visited, guest); + return p->Visit(visited); } - }; + return CatchAll::OnUnknownVisitor(visited, guest); + } +}; - template class CatchAll> - class BaseVisitable +template class CatchAll> +class BaseVisitable +{ +public: + typedef R ReturnType; + virtual ~BaseVisitable() {} + virtual ReturnType Accept(BaseVisitor&) const = 0; + +protected: // give access only to the hierarchy + template + static ReturnType AcceptImpl(const T& visited, BaseVisitor& guest) { - public: - typedef R ReturnType; - virtual ~BaseVisitable() {} - virtual ReturnType Accept(BaseVisitor&) const = 0; - - protected: // give access only to the hierarchy - template - static ReturnType AcceptImpl(const T& visited, BaseVisitor& guest) + // Apply the Acyclic Visitor + if (Visitor* p = dynamic_cast*>(&guest)) { - // Apply the Acyclic Visitor - if (Visitor* p = dynamic_cast*>(&guest)) - { - return p->Visit(visited); - } - return CatchAll::OnUnknownVisitor(const_cast(visited), guest); + return p->Visit(visited); } - }; + return CatchAll::OnUnknownVisitor(const_cast(visited), guest); + } +}; //////////////////////////////////////////////////////////////////////////////// /// \def LOKI_DEFINE_VISITABLE() /// \ingroup VisitorGroup -/// Put it in every class that you want to make visitable +/// Put it in every class that you want to make visitable /// (in addition to deriving it from BaseVisitable) //////////////////////////////////////////////////////////////////////////////// @@ -306,7 +306,7 @@ struct DefaultCatchAll //////////////////////////////////////////////////////////////////////////////// /// \def LOKI_DEFINE_CONST_VISITABLE() /// \ingroup VisitorGroup -/// Put it in every class that you want to make visitable by const member +/// Put it in every class that you want to make visitable by const member /// functions (in addition to deriving it from BaseVisitable) //////////////////////////////////////////////////////////////////////////////// @@ -318,25 +318,25 @@ struct DefaultCatchAll /// \class CyclicVisitor /// /// \ingroup VisitorGroup -/// Put it in every class that you want to make visitable (in addition to +/// Put it in every class that you want to make visitable (in addition to /// deriving it from BaseVisitable //////////////////////////////////////////////////////////////////////////////// - template - class CyclicVisitor : public Visitor +template +class CyclicVisitor : public Visitor +{ +public: + typedef R ReturnType; + // using Visitor::Visit; + + template + ReturnType GenericVisit(Visited& host) { - public: - typedef R ReturnType; - // using Visitor::Visit; - - template - ReturnType GenericVisit(Visited& host) - { - Visitor& subObj = *this; - return subObj.Visit(host); - } - }; - + Visitor& subObj = *this; + return subObj.Visit(host); + } +}; + //////////////////////////////////////////////////////////////////////////////// /// \def LOKI_DEFINE_CYCLIC_VISITABLE(SomeVisitor) /// \ingroup VisitorGroup -- cgit