1 /* 2 * Copyright (c) 2015, Intel Corporation 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are met: 6 * 7 * * Redistributions of source code must retain the above copyright notice, 8 * this list of conditions and the following disclaimer. 9 * * Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * * Neither the name of Intel Corporation nor the names of its contributors 13 * may be used to endorse or promote products derived from this software 14 * without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 /** \file 30 * \brief Visitor base class for working with the component tree. 31 */ 32 33 #ifndef CONSTCOMPONENTVISITOR_H 34 #define CONSTCOMPONENTVISITOR_H 35 36 namespace ue2 { 37 38 class AsciiComponentClass; 39 class Component; 40 class ComponentAlternation; 41 class ComponentAssertion; 42 class ComponentAtomicGroup; 43 class ComponentBackReference; 44 class ComponentBoundary; 45 class ComponentByte; 46 class ComponentCondReference; 47 class ComponentClass; 48 class ComponentEmpty; 49 class ComponentEUS; 50 class ComponentRepeat; 51 class ComponentSequence; 52 class ComponentWordBoundary; 53 class UTF8ComponentClass; 54 55 /** 56 * \brief Visitor base class for traversing an immutable component tree. 57 * 58 * Our approach to implementing the visitor pattern for traversing the 59 * Component tree for a pattern. This version operates on an immutable tree; 60 * use \ref ComponentVisitor if you need to make changes to components during 61 * traversal. 62 */ 63 class ConstComponentVisitor { 64 public: 65 virtual ~ConstComponentVisitor(); 66 67 virtual void pre(const AsciiComponentClass &c) = 0; 68 virtual void pre(const ComponentAlternation &c) = 0; 69 virtual void pre(const ComponentAssertion &c) = 0; 70 virtual void pre(const ComponentAtomicGroup &c) = 0; 71 virtual void pre(const ComponentBackReference &c) = 0; 72 virtual void pre(const ComponentBoundary &c) = 0; 73 virtual void pre(const ComponentByte &c) = 0; 74 virtual void pre(const ComponentCondReference &c) = 0; 75 virtual void pre(const ComponentEmpty &c) = 0; 76 virtual void pre(const ComponentEUS &c) = 0; 77 virtual void pre(const ComponentRepeat &c) = 0; 78 virtual void pre(const ComponentSequence &c) = 0; 79 virtual void pre(const ComponentWordBoundary &c) = 0; 80 virtual void pre(const UTF8ComponentClass &c) = 0; 81 82 virtual void during(const AsciiComponentClass &c) = 0; 83 virtual void during(const ComponentAlternation &c) = 0; 84 virtual void during(const ComponentAssertion &c) = 0; 85 virtual void during(const ComponentAtomicGroup &c) = 0; 86 virtual void during(const ComponentBackReference &c) = 0; 87 virtual void during(const ComponentBoundary &c) = 0; 88 virtual void during(const ComponentByte &c) = 0; 89 virtual void during(const ComponentCondReference &c) = 0; 90 virtual void during(const ComponentEmpty &c) = 0; 91 virtual void during(const ComponentEUS &c) = 0; 92 virtual void during(const ComponentRepeat &c) = 0; 93 virtual void during(const ComponentSequence &c) = 0; 94 virtual void during(const ComponentWordBoundary &c) = 0; 95 virtual void during(const UTF8ComponentClass &c) = 0; 96 97 virtual void post(const AsciiComponentClass &c) = 0; 98 virtual void post(const ComponentAlternation &c) = 0; 99 virtual void post(const ComponentAssertion &c) = 0; 100 virtual void post(const ComponentAtomicGroup &c) = 0; 101 virtual void post(const ComponentBackReference &c) = 0; 102 virtual void post(const ComponentBoundary &c) = 0; 103 virtual void post(const ComponentByte &c) = 0; 104 virtual void post(const ComponentCondReference &c) = 0; 105 virtual void post(const ComponentEmpty &c) = 0; 106 virtual void post(const ComponentEUS &c) = 0; 107 virtual void post(const ComponentRepeat &c) = 0; 108 virtual void post(const ComponentSequence &c) = 0; 109 virtual void post(const ComponentWordBoundary &c) = 0; 110 virtual void post(const UTF8ComponentClass &c) = 0; 111 }; 112 113 /** 114 * \brief Concrete subclass of ConstComponentVisitor with default behaviour, 115 * allowing you to just implement the member functions you need. 116 */ 117 class DefaultConstComponentVisitor : public ConstComponentVisitor { 118 public: 119 DefaultConstComponentVisitor(); 120 ~DefaultConstComponentVisitor() override; 121 122 void pre(const AsciiComponentClass &c) override; 123 void pre(const ComponentAlternation &c) override; 124 void pre(const ComponentAssertion &c) override; 125 void pre(const ComponentAtomicGroup &c) override; 126 void pre(const ComponentBackReference &c) override; 127 void pre(const ComponentBoundary &c) override; 128 void pre(const ComponentByte &c) override; 129 void pre(const ComponentCondReference &c) override; 130 void pre(const ComponentEmpty &c) override; 131 void pre(const ComponentEUS &c) override; 132 void pre(const ComponentRepeat &c) override; 133 void pre(const ComponentSequence &c) override; 134 void pre(const ComponentWordBoundary &c) override; 135 void pre(const UTF8ComponentClass &c) override; 136 137 void during(const AsciiComponentClass &c) override; 138 void during(const ComponentAlternation &c) override; 139 void during(const ComponentAssertion &c) override; 140 void during(const ComponentAtomicGroup &c) override; 141 void during(const ComponentBackReference &c) override; 142 void during(const ComponentBoundary &c) override; 143 void during(const ComponentByte &c) override; 144 void during(const ComponentCondReference &c) override; 145 void during(const ComponentEmpty &c) override; 146 void during(const ComponentEUS &c) override; 147 void during(const ComponentRepeat &c) override; 148 void during(const ComponentSequence &c) override; 149 void during(const ComponentWordBoundary &c) override; 150 void during(const UTF8ComponentClass &c) override; 151 152 void post(const AsciiComponentClass &c) override; 153 void post(const ComponentAlternation &c) override; 154 void post(const ComponentAssertion &c) override; 155 void post(const ComponentAtomicGroup &c) override; 156 void post(const ComponentBackReference &c) override; 157 void post(const ComponentBoundary &c) override; 158 void post(const ComponentByte &c) override; 159 void post(const ComponentCondReference &c) override; 160 void post(const ComponentEmpty &c) override; 161 void post(const ComponentEUS &c) override; 162 void post(const ComponentRepeat &c) override; 163 void post(const ComponentSequence &c) override; 164 void post(const ComponentWordBoundary &c) override; 165 void post(const UTF8ComponentClass &c) override; 166 }; 167 168 } // namespace ue2 169 170 #endif // CONSTCOMPONENTVISITOR_H 171