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.

common.h 2.0 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /**
  2. * Copyright 2020-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. #ifndef MINDSPORE_CCSRC_DEBUG_COMMON_H_
  17. #define MINDSPORE_CCSRC_DEBUG_COMMON_H_
  18. #include <string>
  19. #include <optional>
  20. #include "utils/contract.h"
  21. namespace mindspore {
  22. static const int maxDirectoryLength = 1024;
  23. static const int maxFilenameLength = 128;
  24. static const int maxOSFilenameLength = 255;
  25. class Common {
  26. public:
  27. Common() = default;
  28. ~Common() = default;
  29. static std::optional<std::string> GetRealPath(const std::string &input_path);
  30. static std::optional<std::string> GetConfigFile(const std::string &env);
  31. static std::optional<std::string> GetEnvConfigFile();
  32. static bool IsStrLengthValid(const std::string &str, const int &length_limit, const std::string &error_message = "",
  33. const bool &print_str = true);
  34. static bool IsPathValid(const std::string &path, const int &length_limit, const std::string &error_message = "",
  35. const bool &print_str = true);
  36. static bool IsFilenameValid(const std::string &filename, const int &length_limit,
  37. const std::string &error_message = "");
  38. private:
  39. static bool CreateNotExistDirs(const std::string &path);
  40. static bool IsEveryFilenameValid(const std::string &path, const int &length_limit, const std::string &error_message);
  41. };
  42. } // namespace mindspore
  43. #endif // MINDSPORE_CCSRC_DEBUG_COMMON_H_