File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -42,6 +42,8 @@ namespace vix::config
4242 /* * @brief Load or reload the configuration file. */
4343 void loadConfig ();
4444
45+ void set (const std::string &dottedKey, const nlohmann::json &value);
46+
4547#if VIX_CORE_WITH_MYSQL
4648 namespace sql
4749 {
Original file line number Diff line number Diff line change @@ -143,6 +143,33 @@ namespace vix::config
143143 return DEFAULT_DB_PASS;
144144 }
145145
146+ void Config::set (const std::string &dottedKey, const nlohmann::json &value)
147+ {
148+ if (dottedKey.empty ())
149+ {
150+ return ;
151+ }
152+
153+ nlohmann::json *node = &rawConfig_;
154+ std::size_t start = 0 ;
155+
156+ while (start < dottedKey.size ())
157+ {
158+ const std::size_t dot = dottedKey.find (' .' , start);
159+ const std::string key =
160+ dottedKey.substr (start, dot == std::string::npos ? std::string::npos : dot - start);
161+
162+ if (dot == std::string::npos)
163+ {
164+ (*node)[key] = value;
165+ return ;
166+ }
167+
168+ node = &((*node)[key]);
169+ start = dot + 1 ;
170+ }
171+ }
172+
146173 const std::string &Config::getDbHost () const noexcept
147174 {
148175 return db_host;
You can’t perform that action at this time.
0 commit comments