1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #ifndef MAPLE_UTIL_INCLUDE_BASE_GRAPH_NODE_H
16 #define MAPLE_UTIL_INCLUDE_BASE_GRAPH_NODE_H
17 #include "types_def.h"
18 #include "mempool_allocator.h"
19 namespace maple {
20
21 template <typename T>
22 struct Comparator {
operatorComparator23 bool operator()(const T *lhs, const T *rhs) const
24 {
25 return lhs->GetID() < rhs->GetID();
26 }
27 };
28
29 class BaseGraphNode {
30 public:
31 virtual void GetOutNodes(std::vector<BaseGraphNode *> &outNodes) = 0;
32 virtual void GetOutNodes(std::vector<BaseGraphNode *> &outNodes) const = 0;
33 virtual void GetInNodes(std::vector<BaseGraphNode *> &outNodes) = 0;
34 virtual void GetInNodes(std::vector<BaseGraphNode *> &outNodes) const = 0;
35 virtual const std::string GetIdentity() = 0;
36 virtual uint32 GetID() const = 0;
37 };
38
39 // BaseGraphNode needs to be the base class of T
40 template <typename T, std::enable_if_t<std::is_base_of<BaseGraphNode, T>::value, bool> = true>
ConvertToVectorOfBasePtr(const MapleVector<T * > & originVec,MapleVector<BaseGraphNode * > & targetVec)41 void ConvertToVectorOfBasePtr(const MapleVector<T *> &originVec, MapleVector<BaseGraphNode *> &targetVec)
42 {
43 for (auto &item : originVec) {
44 targetVec.emplace_back(item);
45 }
46 }
47 } // namespace maple
48 #endif /* MAPLE_UTIL_INCLUDE_BASE_GRAPH_NODE_H */
49