You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

any.cc 1.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * Copyright 2019-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. #include "utils/any.h"
  17. #include <cxxabi.h>
  18. #include <memory>
  19. namespace mindspore {
  20. // only support (int, float, bool) as Literal
  21. bool AnyIsLiteral(const Any &any) {
  22. static const std::type_index typeid_int = std::type_index(typeid(int));
  23. static const std::type_index typeid_float = std::type_index(typeid(float));
  24. static const std::type_index typeid_bool = std::type_index(typeid(bool));
  25. auto typeid_any = std::type_index(any.type());
  26. return typeid_int == typeid_any || typeid_float == typeid_any || typeid_bool == typeid_any;
  27. }
  28. Any &Any::operator=(const Any &other) {
  29. if (m_ptr == other.m_ptr || &other == this) {
  30. return *this;
  31. }
  32. m_ptr = other.clone();
  33. m_tpIndex = other.m_tpIndex;
  34. return *this;
  35. }
  36. bool Any::operator<(const Any &other) const { return this < &other; }
  37. Any &Any::operator=(Any &&other) {
  38. if (this != &other) {
  39. if (m_ptr == other.m_ptr || &other == this) {
  40. return *this;
  41. }
  42. m_ptr = std::move(other.m_ptr);
  43. m_tpIndex = std::move(other.m_tpIndex);
  44. other.m_ptr = nullptr;
  45. }
  46. return *this;
  47. }
  48. } // namespace mindspore