neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
visitor.hpp
Go to the documentation of this file.
1// visitor.hpp
2/*
3 * Copyright (c) 2007 Leigh Johnston.
4 *
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
9 * met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * * Neither the name of Leigh Johnston nor the names of any
19 * other contributors to this software may be used to endorse or
20 * promote products derived from this software without specific prior
21 * written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
24 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
25 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
27 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34*/
35
36#pragma once
37
38#include <neolib/neolib.hpp>
39
40namespace neolib
41{
42 template <unsigned int N>
43 struct unused_visitee {};
44
45 template<typename T1, typename T2 = unused_visitee<2>, typename T3 = unused_visitee<3>, typename T4 = unused_visitee<4>,
46 typename T5 = unused_visitee<5>, typename T6 = unused_visitee<6>, typename T7 = unused_visitee<7>,
47 typename T8 = unused_visitee<8>, typename T9 = unused_visitee<9>, typename T10 = unused_visitee<10> >
48 class visitor
49 {
50 public:
51 virtual ~visitor() = default;
52 public:
53 virtual void visit(const T1& aVisitee) const {}
54 virtual void visit(T1& aVisitee) { visit(const_cast<const T1&>(aVisitee)); }
55 virtual void visit(const T2& aVisitee) const {}
56 virtual void visit(T2& aVisitee) { visit(const_cast<const T2&>(aVisitee)); }
57 virtual void visit(const T3& aVisitee) const {}
58 virtual void visit(T3& aVisitee) { visit(const_cast<const T3&>(aVisitee)); }
59 virtual void visit(const T4& aVisitee) const {}
60 virtual void visit(T4& aVisitee) { visit(const_cast<const T4&>(aVisitee)); }
61 virtual void visit(const T5& aVisitee) const {}
62 virtual void visit(T5& aVisitee) { visit(const_cast<const T5&>(aVisitee)); }
63 virtual void visit(const T6& aVisitee) const {}
64 virtual void visit(T6& aVisitee) { visit(const_cast<const T6&>(aVisitee)); }
65 virtual void visit(const T7& aVisitee) const {}
66 virtual void visit(T7& aVisitee) { visit(const_cast<const T7&>(aVisitee)); }
67 virtual void visit(const T8& aVisitee) const {}
68 virtual void visit(T8& aVisitee) { visit(const_cast<const T8&>(aVisitee)); }
69 virtual void visit(const T9& aVisitee) const {}
70 virtual void visit(T9& aVisitee) { visit(const_cast<const T9&>(aVisitee)); }
71 virtual void visit(const T10& aVisitee) const {}
72 virtual void visit(T10& aVisitee) { visit(const_cast<const T10&>(aVisitee)); }
73 };
74
75 template<typename T1, typename T2 = unused_visitee<2>, typename T3 = unused_visitee<3>, typename T4 = unused_visitee<4>,
76 typename T5 = unused_visitee<5>, typename T6 = unused_visitee<6>, typename T7 = unused_visitee<7>,
77 typename T8 = unused_visitee<8>, typename T9 = unused_visitee<9>, typename T10 = unused_visitee<10> >
78 class visitee
79 {
80 public:
82 public:
83 virtual void accept(const visitor_type& aVisitor) const = 0;
84 virtual void accept(visitor_type& aVisitor) { accept(const_cast<const visitor_type&>(aVisitor)); }
85 };
86}
virtual void accept(const visitor_type &aVisitor) const =0
virtual void accept(visitor_type &aVisitor)
Definition visitor.hpp:84
visitor< T1, T2, T3, T4, T5, T6, T7, T8, T9, T10 > visitor_type
Definition visitor.hpp:81
virtual void visit(const T5 &aVisitee) const
Definition visitor.hpp:61
virtual void visit(T5 &aVisitee)
Definition visitor.hpp:62
virtual void visit(const T7 &aVisitee) const
Definition visitor.hpp:65
virtual void visit(T8 &aVisitee)
Definition visitor.hpp:68
virtual void visit(T10 &aVisitee)
Definition visitor.hpp:72
virtual void visit(T1 &aVisitee)
Definition visitor.hpp:54
virtual void visit(T2 &aVisitee)
Definition visitor.hpp:56
virtual void visit(T6 &aVisitee)
Definition visitor.hpp:64
virtual void visit(const T3 &aVisitee) const
Definition visitor.hpp:57
virtual void visit(T9 &aVisitee)
Definition visitor.hpp:70
virtual void visit(T7 &aVisitee)
Definition visitor.hpp:66
virtual void visit(T4 &aVisitee)
Definition visitor.hpp:60
virtual void visit(const T9 &aVisitee) const
Definition visitor.hpp:69
virtual void visit(const T2 &aVisitee) const
Definition visitor.hpp:55
virtual void visit(T3 &aVisitee)
Definition visitor.hpp:58
virtual void visit(const T10 &aVisitee) const
Definition visitor.hpp:71
virtual ~visitor()=default
virtual void visit(const T6 &aVisitee) const
Definition visitor.hpp:63
virtual void visit(const T1 &aVisitee) const
Definition visitor.hpp:53
virtual void visit(const T8 &aVisitee) const
Definition visitor.hpp:67
virtual void visit(const T4 &aVisitee) const
Definition visitor.hpp:59