From c0506f94bf3bcb5a64cd02026976dddc15f4b568 Mon Sep 17 00:00:00 2001 From: HanishKVC Date: Sat, 11 May 2024 00:17:08 +0530 Subject: [PATCH] SimpCfg: Allow for direct initialization lists based init This should pave way for having a default chat templates dataset in the code, without needing to load it from a config file, if one doesnt want to. TODO: allow for loading config from json into simpcfg, so that a program which uses llama.cpp can decide, whether it is ok with what is already there in the internal dataset, or allow for loading template info at runtime using the simpcfg's simple text file or additionally include the json code to load template info at runtime from json file. --- common/simpcfg.hpp | 48 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/common/simpcfg.hpp b/common/simpcfg.hpp index 93d0b7539..694f822cf 100644 --- a/common/simpcfg.hpp +++ b/common/simpcfg.hpp @@ -279,16 +279,19 @@ std::string str(std::vector values) { typedef std::variant SimpCfgData; typedef std::vector MultiPart; +typedef std::map> SimpCfgMapMapVariant; class SimpCfg { private: - std::map> mapV = {}; + SimpCfgMapMapVariant mapV = {}; std::regex rInt {R"(^[-+]?\d+$)"}; std::regex rFloat {R"(^[-+]?\d+(?:\.\d+)?(?:[eE][-+]?\d+)?$)"}; public: + SimpCfg(SimpCfgMapMapVariant defaultMap) : mapV(defaultMap) {} + static std::string joiner(const MultiPart& parts) { std::stringstream joined; int iCnt = 0; @@ -354,6 +357,8 @@ public: set_double(group, keyParts, dvalue); } + // Dump info about the specified group. + // If group is empty, then dump info about all groups maintained in this instance. void dump(const std::string &group) { for (auto gm: mapV) { if (!group.empty() && (gm.first != group)) { @@ -604,16 +609,28 @@ void check_strings() { SimpCfg::locale_restore(sSavedLocale); } -int main(int argc, char **argv) { - if (argc != 2) { - LERRR_LN("USAGE:%s simp.cfg", argv[0]); - exit(1); - } +void sc_inited() { + SimpCfg sc = {{ + {"Group1",{ + {"testkey11", 11}, + {"testkey12", true} + }}, + {"Group2", { + {"key21", "val21"}, + {"key22", 22}, + {"key23", 2.3} + }} + }}; - check_strings(); + std::cout << "**** sc inited **** " << std::endl; + sc.dump(""); - std::string fname {argv[1]}; - SimpCfg sc; +} + +void sc_set(const std::string &fname) { + + std::cout << "**** sc set **** " << std::endl; + SimpCfg sc = {{}}; sc.load(fname); sc.dump(""); @@ -646,6 +663,19 @@ int main(int argc, char **argv) { sc.set_string("testme", {"keyA301", "2"}, "AkashaGanga"); sc.get_vector("testme", {"keyA300"}, {1, 2, 3}); sc.get_vector("testme", {"keyA301"}, { "yes 1", "No 2", "very well 3" }); +} + +int main(int argc, char **argv) { + if (argc != 2) { + LERRR_LN("USAGE:%s simp.cfg", argv[0]); + exit(1); + } + + check_strings(); + sc_inited(); + std::string fname {argv[1]}; + sc_set(fname); + return 0; } #endif