From 74728d50be43156b1726c732b89b36392f697ef4 Mon Sep 17 00:00:00 2001 From: zoujh Date: Tue, 26 Oct 2021 19:21:19 +0800 Subject: [PATCH] create a DLElement object from a json string --- SniperKernel/SniperKernel/Sniper.h | 3 +++ SniperKernel/src/Sniper.cc | 10 ++++++++++ SniperPython/src/SniperExp.cc | 1 + 3 files changed, 14 insertions(+) diff --git a/SniperKernel/SniperKernel/Sniper.h b/SniperKernel/SniperKernel/Sniper.h index 1082d15..6cdded2 100644 --- a/SniperKernel/SniperKernel/Sniper.h +++ b/SniperKernel/SniperKernel/Sniper.h @@ -24,6 +24,9 @@ class DLElement; namespace Sniper { + //create a DLElement from a json string + DLElement *create(const std::string &json_str); + //eval a SNiPER job from a json config file DLElement *eval(const char *fname); void setLogLevel(int level); diff --git a/SniperKernel/src/Sniper.cc b/SniperKernel/src/Sniper.cc index beae33a..cee7957 100644 --- a/SniperKernel/src/Sniper.cc +++ b/SniperKernel/src/Sniper.cc @@ -39,6 +39,16 @@ namespace Sniper std::vector LoadDlls; } +DLElement *Sniper::create(const std::string &json_str) +{ + auto json = SniperJSON::loads(json_str); + + DLElement *pobj = DLEFactory::instance().create(json["identifier"].get()); + pobj->eval(json); + + return pobj; +} + DLElement *Sniper::eval(const char *fname) { std::ifstream ifs(fname); diff --git a/SniperPython/src/SniperExp.cc b/SniperPython/src/SniperExp.cc index 863be29..63790af 100644 --- a/SniperPython/src/SniperExp.cc +++ b/SniperPython/src/SniperExp.cc @@ -60,6 +60,7 @@ void export_Sniper_Sniper() { using namespace boost::python; + def("create", &Sniper::create, return_value_policy()); def("eval", &Sniper::eval, return_value_policy()); def("setLogLevel", SniperExp::setLogLevel); def("setColorful", SniperExp::setColorful);