Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/onnx/common/path.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002  * SPDX-License-Identifier: Apache-2.0
0003  */
0004 
0005 // Copyright (c) ONNX Project Contributors.
0006 
0007 #pragma once
0008 
0009 #include <string>
0010 #ifdef _WIN32
0011 #include <windows.h>
0012 
0013 #include <filesystem>
0014 
0015 #include "onnx/checker.h"
0016 #endif
0017 
0018 namespace ONNX_NAMESPACE {
0019 
0020 #ifdef _WIN32
0021 constexpr const char k_preferred_path_separator = '\\';
0022 #else // POSIX
0023 constexpr const char k_preferred_path_separator = '/';
0024 #endif
0025 
0026 #ifdef _WIN32
0027 inline std::wstring path_join(const std::wstring& origin, const std::wstring& append) {
0028   return (std::filesystem::path(origin) / std::filesystem::path(append)).wstring();
0029 }
0030 inline std::wstring utf8str_to_wstring(const std::string& utf8str) {
0031   if (utf8str.size() > INT_MAX) {
0032     fail_check("utf8str_to_wstring: string is too long for converting to wstring.");
0033   }
0034   int size_required = MultiByteToWideChar(CP_UTF8, 0, utf8str.c_str(), (int)utf8str.size(), NULL, 0);
0035   std::wstring ws_str(size_required, 0);
0036   MultiByteToWideChar(CP_UTF8, 0, utf8str.c_str(), (int)utf8str.size(), &ws_str[0], size_required);
0037   return ws_str;
0038 }
0039 
0040 #else
0041 std::string path_join(const std::string& origin, const std::string& append);
0042 // TODO: also use std::filesystem::path for clean_relative_path after ONNX has supported C++17 for POSIX
0043 // Clean up relative path when there is ".." in the path, e.g.: a/b/../c -> a/c
0044 // It cannot work with absolute path
0045 std::string clean_relative_path(const std::string& path);
0046 #endif
0047 
0048 } // namespace ONNX_NAMESPACE