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 <details/ie_exception.hpp>
15 #include <memory>
16 #include <ostream>
17 #include <string>
18 #include <vector>
19 
20 #ifdef UNICODE
21 typedef wchar_t tchar;
22 typedef std::wstring file_name_t;
23 #else
24 typedef char tchar;
25 typedef std::string file_name_t;
26 #endif
27 
28 namespace InferenceEngine {
29 
30 /**
31  * @brief Conversion from possibly-wide character string to a single-byte chain.
32  */
33 inline std::string fileNameToString(const file_name_t& str) {
34 #ifdef UNICODE
35  size_t maxlen = (str.length() + 1) * sizeof(wchar_t) / sizeof(char);
36  std::vector<char> mbstr(maxlen);
37  mbstr[0] = 0;
38  std::wcstombs(&mbstr[0], str.c_str(), maxlen);
39  std::string res = std::string(&mbstr[0]);
40  return res;
41 #else
42  return str;
43 #endif
44 }
45 
46 /**
47  * @brief Conversion from single-byte character string to a possibly-wide one
48  */
49 inline file_name_t stringToFileName(const std::string& str) {
50 #ifdef UNICODE
51  size_t maxlen = str.length() + 1;
52  std::vector<wchar_t> wcstr(maxlen);
53  wcstr[0] = 0;
54  std::mbstowcs(&wcstr[0], str.c_str(), maxlen);
55  file_name_t res = file_name_t(&wcstr[0]);
56  return res;
57 #else
58  return str;
59 #endif
60 }
61 
62 } // namespace InferenceEngine
Inference Engine API.
Definition: ie_argmax_layer.hpp:15
file_name_t stringToFileName(const std::string &str)
Conversion from single-byte character string to a possibly-wide one.
Definition: ie_unicode.hpp:49
A header file for the main Inference Engine exception.
std::string fileNameToString(const file_name_t &str)
Conversion from possibly-wide character string to a single-byte chain.
Definition: ie_unicode.hpp:33