1 /** 2 * Copyright 2019-2021 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 #include "base/base.h" 18 19 namespace mindspore { Base(const Base & other)20Base::Base(const Base &other) : std::enable_shared_from_this<Base>(other) {} 21 operator ==(const Base & rhs)22bool Base::operator==(const Base &rhs) { 23 if (this == &rhs) { 24 return true; 25 } 26 return false; 27 } 28 operator =(const Base & other)29Base &Base::operator=(const Base &other) { 30 if (this == &other) { 31 return *this; 32 } 33 user_data_ = other.user_data_; 34 return *this; 35 } 36 hash() const37std::size_t Base::hash() const { return tid(); } 38 ToString() const39std::string Base::ToString() const { return type_name(); } 40 dump() const41void Base::dump() const { std::cout << ToString() << std::endl; } 42 DumpText() const43std::string Base::DumpText() const { return ToString(); } 44 IsFromTypeId(uint32_t tid) const45bool Base::IsFromTypeId(uint32_t tid) const { return Base::IsDerivedFrom(tid); } 46 IsSameTypeId(uint32_t tid) const47bool Base::IsSameTypeId(uint32_t tid) const { return tid == Base::kTypeId; } 48 type_name() const49std::string Base::type_name() const { return "Base"; } 50 tid() const51uint32_t Base::tid() const { return Base::kTypeId; } 52 IsDerivedFrom(uint32_t tid)53bool Base::IsDerivedFrom(uint32_t tid) { return tid == Base::kTypeId; } 54 has_user_data(const std::string & key) const55bool Base::has_user_data(const std::string &key) const { return user_data_.has(key); } 56 CloneUserData(const std::shared_ptr<Base> & other)57void Base::CloneUserData(const std::shared_ptr<Base> &other) { user_data_ = other->user_data_; } 58 CloneUserData(const UserData & other)59void Base::CloneUserData(const UserData &other) { user_data_ = other; } 60 GetUserData() const61const UserData &Base::GetUserData() const { return user_data_; } 62 } // namespace mindspore 63