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  * @param str A possibly-wide character string
33  * @return A single-byte character string
34  */
35 INFERENCE_ENGINE_DEPRECATED("Use OS-native conversion utilities")
36 inline std::string fileNameToString(const file_name_t& str) {
37 #ifdef UNICODE
38  size_t maxlen = (str.length() + 1) * sizeof(wchar_t) / sizeof(char);
39  std::vector<char> mbstr(maxlen);
40  mbstr[0] = 0;
41  std::wcstombs(&mbstr[0], str.c_str(), maxlen);
42  std::string res = std::string(&mbstr[0]);
43  return res;
44 #else
45  return str;
46 #endif
47 }
48 
49 /**
50  * @deprecated Use OS-native conversion utilities
51  * @brief Conversion from single-byte character string to a possibly-wide one
52  * @param str A single-byte character string
53  * @return A possibly-wide character string
54  */
55 INFERENCE_ENGINE_DEPRECATED("Use OS-native conversion utilities")
56 inline file_name_t stringToFileName(const std::string& str) {
57 #ifdef UNICODE
58  size_t maxlen = str.length() + 1;
59  std::vector<wchar_t> wcstr(maxlen);
60  wcstr[0] = 0;
61  std::mbstowcs(&wcstr[0], str.c_str(), maxlen);
62  file_name_t res = file_name_t(&wcstr[0]);
63  return res;
64 #else
65  return str;
66 #endif
67 }
68 
69 } // namespace InferenceEngine