215{
216 auto rgb_hex_to_dec = [](const std::string& hexstr, FlushPredict::RGBColor& color)->bool
217 {
218 if (hexstr.empty() || hexstr.length() != 7 || hexstr[0] != '#')
219 {
220 assert(false);
221 color.r = 0, color.g = 0, color.b = 0;
222 return false;
223 }
224
225 auto hexToByte = [](const std::string& hex)->int
226 {
227 unsigned int byte;
228 std::istringstream(hex) >> std::hex >> byte;
229 return byte;
230 };
231 color.r = hexToByte(hexstr.substr(1, 2));
232 color.g = hexToByte(hexstr.substr(3, 2));
233 color.b = hexToByte(hexstr.substr(5, 2));
234 return true;
235 };
236
237 std::ifstream in(data_file);
238 if (!in.is_open()) {
240 return;
241 }
242 std::string line;
243 std::getline(in, line);
244 std::getline(in, line);
245
246 {
247 std::istringstream in(line);
248 std::string color;
249 while (in >> color) {
251 if (!rgb_hex_to_dec(color, c)) {
253 return;
254 }
256 }
257 }
258 std::getline(in, line);
259 while (std::getline(in, line)) {
260 std::istringstream iss(line);
261 std::string rgb_from, rgb_to;
262 float value;
263 if (iss >> rgb_from >> rgb_to >> value) {
265
266 if (!rgb_hex_to_dec(rgb_from, from)) {
268 return;
269 }
270 if (!rgb_hex_to_dec(rgb_to, to)) {
272 return;
273 }
274
277 }
278 else {
280 return;
281 }
282 }
284}
uint64_t generate_hash_key(const RGB &from, const RGB &to)
Definition FlushVolPredictor.cpp:202
bool m_valid
Definition FlushVolPredictor.cpp:192
std::vector< RGB > m_colors
Definition FlushVolPredictor.cpp:191
std::unordered_map< uint64_t, float > m_flush_map
Definition FlushVolPredictor.cpp:190
FlushPredict::RGBColor RGB
Definition FlushVolPredictor.cpp:182