5c1de2b1e2fe7789ca31664e2c38cce35f803cff
[platform/upstream/dldt.git] / inference-engine / src / vpu / graph_transformer / src / utils / enums.cpp
1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4
5 #include <vpu/utils/enums.hpp>
6
7 #include <string>
8 #include <algorithm>
9 #include <unordered_map>
10 #include <vector>
11
12 #include <vpu/utils/string.hpp>
13 #include <vpu/utils/containers.hpp>
14
15 namespace vpu {
16
17 namespace {
18
19 void removeCharFromString(std::string& str, char ch) {
20     str.erase(std::remove(str.begin(), str.end(), ch), str.end());
21 }
22
23 }  // namespace
24
25 std::ostream& printValue(std::ostream& os, const std::string& strMap, int32_t val) {
26     std::string strMapCopy = strMap;
27
28     removeCharFromString(strMapCopy, ' ');
29     removeCharFromString(strMapCopy, '(');
30
31     SmallVector<std::string> enumTokens;
32     splitStringList(strMapCopy, enumTokens, ',');
33
34     int32_t inxMap = 0;
35     for (const auto& token : enumTokens) {
36         // Token: [EnumName | EnumName=EnumValue]
37         std::string enumName;
38         if (token.find('=') == std::string::npos) {
39             enumName = token;
40         } else {
41             SmallVector<std::string, 2> enumNameValue;
42             splitStringList(token, enumNameValue, '=');
43             IE_ASSERT(enumNameValue.size() == 2);
44
45             enumName = enumNameValue[0];
46             inxMap = std::stoi(enumNameValue[1], nullptr, 0);
47         }
48
49         if (inxMap == val) {
50             os << enumName;
51             return os;
52         }
53
54         ++inxMap;
55     }
56
57     os << std::to_string(val);
58     return os;
59 }
60
61 }  // namespace vpu