ie_unicode.hpp
1 // Copyright (C) 2018-2019 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  * @file ie_common.h
8  */
9 #pragma once
10 
11 #include <vector>
12 #include <memory>
13 #include <string>
14 #include <ostream>
15 #include <algorithm>
16 #include <cstdlib>
17 #include <details/ie_exception.hpp>
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 * @brief Conversion from possibly-wide character string to a single-byte chain.
31 */
32 inline std::string fileNameToString(const file_name_t& str) {
33 #ifdef UNICODE
34  size_t maxlen = (str.length() + 1) * sizeof(wchar_t) / sizeof(char);
35  std::vector<char> mbstr(maxlen);
36  mbstr[0] = 0;
37  std::wcstombs(&mbstr[0], str.c_str(), maxlen);
38  std::string res = std::string(&mbstr[0]);
39  return res;
40 #else
41  return str;
42 #endif
43 }
44 
45 /**
46 * @brief Conversion from single-byte character string to a possibly-wide one
47 */
48 inline file_name_t stringToFileName(const std::string& str) {
49 #ifdef UNICODE
50  size_t maxlen = str.length() + 1;
51  std::vector<wchar_t> wcstr(maxlen);
52  wcstr[0] = 0;
53  std::mbstowcs(&wcstr[0], str.c_str(), maxlen);
54  file_name_t res = file_name_t(&wcstr[0]);
55  return res;
56 #else
57  return str;
58 #endif
59 }
60 
61 } // namespace InferenceEngine
Definition: ie_argmax_layer.hpp:11
A header file for the main Inference Engine exception.