Skip to content

Commit

Permalink
Support parsing config from string
Browse files Browse the repository at this point in the history
  • Loading branch information
smirnov-alexey committed Jan 10, 2025
1 parent 6c1550b commit 91f8e0b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,8 @@ class Config final {

std::string toString() const;

void fromString(const std::string& str);

private:
std::shared_ptr<const OptionsDesc> _desc;
ImplMap _impl;
Expand Down
25 changes: 25 additions & 0 deletions src/plugins/intel_npu/src/al/src/config/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,31 @@ std::string Config::toString() const {
return resultStream.str();
}

void Config::fromString(const std::string& str) {
std::map<std::string, std::string> 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
//
Expand Down

0 comments on commit 91f8e0b

Please sign in to comment.