2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef __ONERT_IR_MODEL_H__
18 #define __ONERT_IR_MODEL_H__
21 #include <unordered_map>
24 #include "util/ObjectManager.h"
37 Model(const Model &obj) = default;
38 Model(Model &&) = default;
39 Model &operator=(const Model &) = default;
40 Model &operator=(Model &&) = default;
44 * @brief Put subgraph in the container with a new Index for that
46 * @param[in] subg Subgraph to be pushed
47 * @param[in] index Index of subgraph to be pushed
50 void push(SubgraphIndex index, const std::shared_ptr<Graph> &subg) { _subgraphs[index] = subg; }
53 * @brief Remove the subgraph that is associated with the given index
55 * @param[in] index Index of the subgraph to be removed
58 void remove(const SubgraphIndex &index) { _subgraphs.erase(index); }
61 * @brief Get the subgraph that is associated with the given index
63 * @param[in] index Index of the subgraph to be returned
66 const std::shared_ptr<Graph> &at(const SubgraphIndex &index) const
68 return _subgraphs.at(index);
71 * @brief Get the subgraph that is associated with the given index
73 * @param[in] index Index of the subgraph to be returned
76 std::shared_ptr<Graph> &at(const SubgraphIndex &index) { return _subgraphs.at(index); }
79 * @brief Get the subgraph that is associated with the given index
81 * @param[in] index Index of the subgraph to be returned
82 * @return true if such entry exists otherwise false
84 bool exist(const SubgraphIndex &index) const
86 auto it = _subgraphs.find(index);
87 return it != _subgraphs.end();
91 * @brief Iterate over the container with given function
93 * @param[in] fn Function to be run for every container entry
96 void iterate(const std::function<void(const SubgraphIndex &, const Graph &)> &fn) const
98 for (const auto &e : _subgraphs)
100 fn(e.first, *e.second);
105 * @brief Iterate over the container with given function
107 * @param[in] fn Function to be run for every container entry
110 void iterate(const std::function<void(const SubgraphIndex &, Graph &)> &fn)
112 for (const auto &e : _subgraphs)
114 fn(e.first, *e.second);
119 * @brief Get count of Subgraphs
121 * @return count of Subgraphs
123 size_t subgraphs_count() const { return _subgraphs.size(); }
126 * @brief Return the primary subgraph
128 * @return std::shared_ptr<Graph> Primary subgraph
130 std::shared_ptr<Graph> primary_subgraph() const { return _subgraphs.at(SubgraphIndex{0}); }
133 std::unordered_map<SubgraphIndex, std::shared_ptr<Graph>> _subgraphs;
139 #endif // __ONERT_IR_MODEL_H__