Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 ARM Limited. |
| 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to |
| 8 | * deal in the Software without restriction, including without limitation the |
| 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 | * sell copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in all |
| 14 | * copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | */ |
| 24 | #ifndef __ARM_COMPUTE_GRAPH2_INODEVISITOR_H__ |
| 25 | #define __ARM_COMPUTE_GRAPH2_INODEVISITOR_H__ |
| 26 | |
| 27 | #include "arm_compute/graph2/nodes/NodesFwd.h" |
| 28 | |
| 29 | namespace arm_compute |
| 30 | { |
| 31 | namespace graph2 |
| 32 | { |
| 33 | /** Node visitor interface */ |
| 34 | class INodeVisitor |
| 35 | { |
| 36 | public: |
| 37 | virtual ~INodeVisitor() = default; |
| 38 | virtual void visit(INode &n) = 0; |
| 39 | virtual void visit(ActivationLayerNode &n) = 0; |
| 40 | virtual void visit(BatchNormalizationLayerNode &n) = 0; |
| 41 | virtual void visit(ConstNode &n) = 0; |
| 42 | virtual void visit(ConvolutionLayerNode &n) = 0; |
| 43 | virtual void visit(DepthConcatenateLayerNode &n) = 0; |
| 44 | virtual void visit(DepthwiseConvolutionLayerNode &n) = 0; |
| 45 | virtual void visit(EltwiseLayerNode &n) = 0; |
| 46 | virtual void visit(FlattenLayerNode &n) = 0; |
| 47 | virtual void visit(FullyConnectedLayerNode &n) = 0; |
| 48 | virtual void visit(InputNode &n) = 0; |
| 49 | virtual void visit(NormalizationLayerNode &n) = 0; |
| 50 | virtual void visit(OutputNode &n) = 0; |
| 51 | virtual void visit(PoolingLayerNode &n) = 0; |
| 52 | virtual void visit(ReshapeLayerNode &n) = 0; |
| 53 | virtual void visit(SoftmaxLayerNode &n) = 0; |
| 54 | }; |
| 55 | |
| 56 | /** Default visitor implementation |
| 57 | * |
| 58 | * Implements visit methods by calling a default function. |
| 59 | * Inherit from DefaultNodeVisitor if you don't want to provide specific implementation for all nodes. |
| 60 | */ |
| 61 | class DefaultNodeVisitor : public INodeVisitor |
| 62 | { |
| 63 | public: |
| 64 | virtual ~DefaultNodeVisitor() = default; |
| 65 | |
| 66 | // Inherited methods overridden |
| 67 | virtual void visit(INode &n) override |
| 68 | { |
| 69 | default_visit(); |
| 70 | } |
| 71 | virtual void visit(ActivationLayerNode &n) override |
| 72 | { |
| 73 | default_visit(); |
| 74 | } |
| 75 | virtual void visit(BatchNormalizationLayerNode &n) override |
| 76 | { |
| 77 | default_visit(); |
| 78 | } |
| 79 | virtual void visit(ConstNode &n) override |
| 80 | { |
| 81 | default_visit(); |
| 82 | } |
| 83 | virtual void visit(ConvolutionLayerNode &n) override |
| 84 | { |
| 85 | default_visit(); |
| 86 | } |
| 87 | virtual void visit(DepthConcatenateLayerNode &n) override |
| 88 | { |
| 89 | default_visit(); |
| 90 | } |
| 91 | virtual void visit(DepthwiseConvolutionLayerNode &n) override |
| 92 | { |
| 93 | default_visit(); |
| 94 | } |
| 95 | virtual void visit(EltwiseLayerNode &n) override |
| 96 | { |
| 97 | default_visit(); |
| 98 | } |
| 99 | virtual void visit(FlattenLayerNode &n) override |
| 100 | { |
| 101 | default_visit(); |
| 102 | } |
| 103 | virtual void visit(FullyConnectedLayerNode &n) override |
| 104 | { |
| 105 | default_visit(); |
| 106 | } |
| 107 | virtual void visit(InputNode &n) override |
| 108 | { |
| 109 | default_visit(); |
| 110 | } |
| 111 | virtual void visit(NormalizationLayerNode &n) override |
| 112 | { |
| 113 | default_visit(); |
| 114 | } |
| 115 | virtual void visit(OutputNode &n) override |
| 116 | { |
| 117 | default_visit(); |
| 118 | } |
| 119 | virtual void visit(PoolingLayerNode &n) override |
| 120 | { |
| 121 | default_visit(); |
| 122 | } |
| 123 | virtual void visit(ReshapeLayerNode &n) override |
| 124 | { |
| 125 | default_visit(); |
| 126 | } |
| 127 | virtual void visit(SoftmaxLayerNode &n) override |
| 128 | { |
| 129 | default_visit(); |
| 130 | } |
| 131 | |
| 132 | /** Function to be overloaded by the client and implement default behavior for the |
| 133 | * non-overloaded visitors |
| 134 | */ |
| 135 | virtual void default_visit() = 0; |
| 136 | }; |
| 137 | } // namespace graph2 |
| 138 | } // namespace arm_compute |
| 139 | #endif /* __ARM_COMPUTE_GRAPH2_INODEVISITOR_H__ */ |