ie_unicode.hpp
Go to the documentation of this file.
1 // Copyright (C) 2018-2020 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 
5 /**
6  * @brief This is a header file with common inference engine definitions
7  *
8  * @file ie_unicode.hpp
9  */
10 #pragma once
11 
12 #include <algorithm>
13 #include <cstdlib>
14 #include <memory>
15 #include <ostream>
16 #include <string>
17 #include <vector>
18 
19 #ifdef UNICODE
20 typedef wchar_t tchar;
21 typedef std::wstring file_name_t;
22 #else
23 typedef char tchar;
24 typedef std::string file_name_t;
25 #endif
26 
27 namespace InferenceEngine {
28 
29 /**
30  * @deprecated Use OS-native conversion utilities
31  * @brief Conversion from possibly-wide character string to a single-byte chain.
32  */
33 INFERENCE_ENGINE_DEPRECATED("Use OS-native conversion utilities")
34 inline std::string fileNameToString(const file_name_t& str) {
35 #ifdef UNICODE
36  size_t maxlen = (str.length() + 1) * sizeof(wchar_t) / sizeof(char);
37  std::vector<char> mbstr(maxlen);
38  mbstr[0] = 0;
39  std::wcstombs(&mbstr[0], str.c_str(), maxlen);
40  std::string res = std::string(&mbstr[0]);
41  return res;
42 #else
43  return str;
44 #endif
45 }
46 
47 /**
48  * @deprecated Use OS-native conversion utilities
49  * @brief Conversion from single-byte character string to a possibly-wide one
50  */
51 INFERENCE_ENGINE_DEPRECATED("Use OS-native conversion utilities")
52 inline file_name_t stringToFileName(const std::string& str) {
53 #ifdef UNICODE
54  size_t maxlen = str.length() + 1;
55  std::vector<wchar_t> wcstr(maxlen);
56  wcstr[0] = 0;
57  std::mbstowcs(&wcstr[0], str.c_str(), maxlen);
58  file_name_t res = file_name_t(&wcstr[0]);
59  return res;
60 #else
61  return str;
62 #endif
63 }
64 
65 } // namespace InferenceEngine