• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2020 Huawei Technologies Co., Ltd
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 
17 #ifndef MINDSPORE_CCSRC_IR_CELL_H_
18 #define MINDSPORE_CCSRC_IR_CELL_H_
19 
20 #include <unordered_map>
21 #include <vector>
22 #include <memory>
23 #include <string>
24 #include <tuple>
25 
26 #include "abstract/abstract_value.h"
27 #include "utils/misc.h"
28 
29 namespace mindspore {
30 using abstract::AbstractBasePtr;
31 using abstract::AbstractBasePtrList;
32 // value for Cell
33 
34 class MS_CORE_API Cell : public Named {
35  public:
Cell(const std::string & name)36   explicit Cell(const std::string &name) : Named(name) {}
37   MS_DECLARE_PARENT(Cell, Named);
38   abstract::AbstractBasePtr ToAbstract() override;
39   std::string ToString() const override;
40   std::string GetAttrString() const;
41 
attrs()42   const std::unordered_map<std::string, ValuePtr> &attrs() const { return attrs_; }
set_attrs(const std::unordered_map<std::string,ValuePtr> & attrs_input)43   void set_attrs(const std::unordered_map<std::string, ValuePtr> &attrs_input) { attrs_ = attrs_input; }
44 
AddAttr(const std::string & name,const ValuePtr & attr)45   void AddAttr(const std::string &name, const ValuePtr &attr) { attrs_[name] = attr; }
46   void DelAttr(const std::string &name);
GetAttr(const std::string & attr_name)47   ValuePtr GetAttr(const std::string &attr_name) const {
48     auto iter = attrs_.find(attr_name);
49     return iter == attrs_.cend() ? nullptr : iter->second;
50   }
51 
HasAttr(const std::string & attr_name)52   bool HasAttr(const std::string &attr_name) const {
53     auto iter = attrs_.find(attr_name);
54     return !(iter == attrs_.cend());
55   }
56 
57   bool operator==(const Value &other) const override;
58   bool operator==(const Cell &other) const;
59   ~Cell() override = default;
60 
61  private:
62   std::unordered_map<std::string, ValuePtr> attrs_;
63 };
64 
65 using CellPtr = std::shared_ptr<Cell>;
66 }  // namespace mindspore
67 #endif  // MINDSPORE_CCSRC_IR_CELL_H_
68