From 91f8e0b926228e055d390b6c210e5ddc9d1e16ef Mon Sep 17 00:00:00 2001 From: Alexey Smirnov Date: Fri, 10 Jan 2025 17:15:13 +0000 Subject: [PATCH] Support parsing config from string --- .../al/include/intel_npu/config/config.hpp | 2 ++ .../intel_npu/src/al/src/config/config.cpp | 25 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/plugins/intel_npu/src/al/include/intel_npu/config/config.hpp b/src/plugins/intel_npu/src/al/include/intel_npu/config/config.hpp index a274c8d1c1cae6..371091b6bd1f3d 100644 --- a/src/plugins/intel_npu/src/al/include/intel_npu/config/config.hpp +++ b/src/plugins/intel_npu/src/al/include/intel_npu/config/config.hpp @@ -423,6 +423,8 @@ class Config final { std::string toString() const; + void fromString(const std::string& str); + private: std::shared_ptr _desc; ImplMap _impl; diff --git a/src/plugins/intel_npu/src/al/src/config/config.cpp b/src/plugins/intel_npu/src/al/src/config/config.cpp index a4e2b515b8e3f6..b370de8a76e2c0 100644 --- a/src/plugins/intel_npu/src/al/src/config/config.cpp +++ b/src/plugins/intel_npu/src/al/src/config/config.cpp @@ -244,6 +244,31 @@ std::string Config::toString() const { return resultStream.str(); } +void Config::fromString(const std::string& str) { + std::map config; + std::string str_cfg(str); + + auto parse_token = [&](const std::string& token){ + auto pos_eq = token.find('='); + auto key = token.substr(0, pos_eq); + auto value = token.substr(pos_eq + 2, token.size() - pos_eq - 3); + config[key] = value; + }; + + size_t pos = 0; + std::string token, key, value; + while ((pos = str_cfg.find(' ')) != std::string::npos) { + token = str_cfg.substr(0, pos); + parse_token(token); + str_cfg.erase(0, pos + 1); + } + + // Process tail + parse_token(str_cfg); + + update(config); +} + // // envVarStrToBool //