-
Notifications
You must be signed in to change notification settings - Fork 190
Expand file tree
/
Copy pathutils.h
More file actions
159 lines (136 loc) · 4.65 KB
/
utils.h
File metadata and controls
159 lines (136 loc) · 4.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*******************************************************************************
* Copyright (C) 2018-2026 Intel Corporation
*
* SPDX-License-Identifier: MIT
******************************************************************************/
#pragma once
#define UNUSED(x) ((void)(x))
#ifdef __cplusplus
#include <cstdint>
#include <exception>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <unordered_set>
#include <vector>
#ifdef _MSC_VER
#define PRETTY_FUNCTION_NAME __FUNCSIG__
#else
#define PRETTY_FUNCTION_NAME __PRETTY_FUNCTION__
#endif
#define TOTAL_CORES_PTL_H 16
namespace Utils {
const std::string dpcppInstructionMsg = "Seems DPC++ dependency is not installed. Please follow installation guide: "
"https://dlstreamer.github.io/get_started/install/"
"install_guide_ubuntu.html#step-7-install-intel-oneapi-dpc-c-compiler-optional";
std::string createNestedErrorMsg(const std::exception &e, std::string &&msg = "", int level = 0);
template <typename OutputIter>
void splitString(const std::string &input, OutputIter out_iter, char delimiter = ',') {
std::string token;
std::istringstream tokenStream(input);
while (std::getline(tokenStream, token, delimiter)) {
*out_iter++ = token;
}
}
std::vector<std::string> splitString(const std::string &input, char delimiter = ',');
template <typename Iter>
std::string join(Iter begin, Iter end, char delimiter = ',') {
std::ostringstream result;
for (auto iter = begin; iter != end; iter++) {
if (iter == begin)
result << *iter;
else
result << delimiter << *iter;
}
return result.str();
}
/**
* Parses a label filter configuration string in the format `label1:label2:label3:...`.
* Labels values are added to the output set for filtering.
*
* @param config_str The configuration string to parse (e.g., "person:car:bike").
* @param filtered_set Output set that will contain only the relevant labels.
* @param delimiter The delimiter used to separate label entries (default is ':').
*/
void parseFilterConfig(const std::string &config_str, std::unordered_set<std::string> &filtered_set,
char delimiter = ':');
/**
* Converts string in format `key1=val1,key2=val2,...` to key/value pairs.
*
* @param[in] s string to convert.
* @param[in] rec_delim delimiter to use between records (by default - `,`).
* @param[in] kv_delim delimiter to use between key and value (by default - `=`).
*
* @return map container with key/value pairs of strings.
*/
std::map<std::string, std::string> stringToMap(const std::string &s, char rec_delim = ',', char kv_delim = '=');
bool fileExists(const std::string &path);
bool symLink(const std::string &path);
constexpr bool IsLinux() {
#ifdef __linux__
return true;
#else
return false;
#endif
}
size_t GetFileSize(const std::string &file_path);
bool CheckFileSize(const std::string &path, size_t size_threshold);
/**
* Parses GPU device name and returns relative GPU index from it.
*
* @param[in] device GPU device name in forms: GPU, GPU.0, etc.
*
* @return relative GPU index.
*/
uint32_t getRelativeGpuDeviceIndex(const std::string &device);
/**
* Converts string to boolean value.
* Valid values are: 1, 0, true, false
*
* @param s string to convert.
* @return boolean value.
* @exception std::invalid_argument if no conversion can be performed.
*/
bool strToBool(const std::string &s);
/**
* Returns number of planes for specified format.
*
* @param fourcc data format as FourCC value.
* @return number of planes.
*/
uint32_t GetPlanesCount(int fourcc) noexcept;
/**
* @brief Returns number of channels for specified format
*
* @param fourcc data format as FourCC value
* @return number of channels
*/
uint32_t GetChannelsCount(int fourcc) noexcept;
/**
* Checks if all keys in config are known.
*
* @param known_keys set of known keys.
* @param config configuration map whose keys should be checked.
* @return true if all config keys are from the set of known keys.
*/
bool checkAllKeysAreKnown(const std::set<std::string> &known_keys, const std::map<std::string, std::string> &config);
/*
* @brief Trims path and replaces leading ~ symbol with the HOME path
*
* @param path
* @return correct absolute path
*/
std::string fixPath(std::string path);
#ifndef _WIN32
/*
* @brief Checks if the CPU is from Intel® Core™ Ultra Series 3 processors with 16 cores (H)
* which is a part of PTL-H series.
*
* @return true if the CPU is from Intel® Core™ Ultra Series 3 processors with 16 cores (H),
* false otherwise.
*/
bool isCPUPTLHSeries(void);
#endif
} // namespace Utils
#endif