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.

utils.cc 2.1 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * Copyright 2022 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 "debug/utils.h"
  17. #include "mindspore/core/utils/log_adapter.h"
  18. namespace mindspore {
  19. bool CheckStoull(uint64_t *const output_digit, const std::string &input_str) {
  20. try {
  21. *output_digit = std::stoull(input_str);
  22. } catch (const std::out_of_range &oor) {
  23. MS_LOG(ERROR) << "Out of Range error: " << oor.what() << " when parse " << input_str;
  24. return false;
  25. } catch (const std::invalid_argument &ia) {
  26. MS_LOG(ERROR) << "Invalid argument: " << ia.what() << " when parse " << input_str;
  27. return false;
  28. }
  29. return true;
  30. }
  31. bool CheckStoul(size_t *const output_digit, const std::string &input_str) {
  32. try {
  33. *output_digit = std::stoul(input_str);
  34. } catch (const std::out_of_range &oor) {
  35. MS_LOG(ERROR) << "Out of Range error: " << oor.what() << " when parse " << input_str;
  36. return false;
  37. } catch (const std::invalid_argument &ia) {
  38. MS_LOG(ERROR) << "Invalid argument: " << ia.what() << " when parse " << input_str;
  39. return false;
  40. }
  41. return true;
  42. }
  43. bool CheckStoi(int64_t *const output_digit, const std::string &input_str) {
  44. try {
  45. *output_digit = std::stoi(input_str);
  46. } catch (const std::out_of_range &oor) {
  47. MS_LOG(ERROR) << "Out of Range error: " << oor.what() << " when parse " << input_str;
  48. return false;
  49. } catch (const std::invalid_argument &ia) {
  50. MS_LOG(ERROR) << "Invalid argument: " << ia.what() << " when parse " << input_str;
  51. return false;
  52. }
  53. return true;
  54. }
  55. } // namespace mindspore