Skip to content

Commit

Permalink
create a DLElement object from a json string
Browse files Browse the repository at this point in the history
  • Loading branch information
zoujh committed Oct 26, 2021
1 parent 610a6e6 commit 74728d5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions SniperKernel/SniperKernel/Sniper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions SniperKernel/src/Sniper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ namespace Sniper
std::vector<std::string> LoadDlls;
}

DLElement *Sniper::create(const std::string &json_str)
{
auto json = SniperJSON::loads(json_str);

DLElement *pobj = DLEFactory::instance().create(json["identifier"].get<std::string>());
pobj->eval(json);

return pobj;
}

DLElement *Sniper::eval(const char *fname)
{
std::ifstream ifs(fname);
Expand Down
1 change: 1 addition & 0 deletions SniperPython/src/SniperExp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ void export_Sniper_Sniper()
{
using namespace boost::python;

def("create", &Sniper::create, return_value_policy<reference_existing_object>());
def("eval", &Sniper::eval, return_value_policy<reference_existing_object>());
def("setLogLevel", SniperExp::setLogLevel);
def("setColorful", SniperExp::setColorful);
Expand Down

0 comments on commit 74728d5

Please sign in to comment.