Skip to content

Commit

Permalink
get dlls and valid DLE classes in SNiPER
Browse files Browse the repository at this point in the history
  • Loading branch information
zoujh committed Nov 26, 2021
1 parent be1198b commit ec8df20
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 22 deletions.
5 changes: 5 additions & 0 deletions SniperKernel/SniperKernel/Sniper.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ namespace Sniper
void setLogFile(const char *fname, bool append = false);
void setLogStdout();

//load a dll into SNiPER
void loadDll(const char *dll);
//the names of loaded DLLs (the return value is in json format)
std::string dlls();
//the names of valid DLEs (the return value is in json format)
std::string validTypes();

namespace System
{
Expand Down
47 changes: 25 additions & 22 deletions SniperKernel/SniperPrivate/DLEFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,44 +19,47 @@
#define SNIPER_DLE_FACTORY_H

#include <string>
#include <vector>
#include <map>

class DLElement;

class DLEFactory
{
public :
public:
typedef DLElement *(*DLECreator)(const std::string &);

typedef DLElement* (*DLECreator)(const std::string&);
// get the singleton instance
static DLEFactory &instance();

//get the singleton instance
static DLEFactory& instance();
// release the singleton instance
static void release();

//release the singleton instance
static void release();
// create a DLE object with its name
DLElement *create(const std::string &name);

//create a DLE object with its name
DLElement* create(const std::string& name);
// book the creator of new DLE types
bool book(const std::string &type, DLECreator creator);

//book the creator of new DLE types
bool book(const std::string& type, DLECreator creator);
// name
const std::string &objName() { return m_name; }

//name
const std::string& objName() { return m_name; }
// valid types
const std::vector<std::string> &validTypes() { return m_types; }

private :
private:
typedef std::map<std::string, DLECreator> Type2CreatorMap;

typedef std::map<std::string, DLECreator> Type2CreatorMap;
// standard constructor
DLEFactory();
~DLEFactory();

//standard constructor
DLEFactory();
~DLEFactory();
// members
std::string m_name;
std::vector<std::string> m_types;
Type2CreatorMap m_creators;

//members
std::string m_name;
Type2CreatorMap m_creators;

static DLEFactory* s_obj;
static DLEFactory *s_obj;
};

#endif
1 change: 1 addition & 0 deletions SniperKernel/src/DLEFactory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ bool DLEFactory::book(const std::string& type, DLECreator creator)
{
Type2CreatorMap::iterator it = m_creators.find(type);
if ( it == m_creators.end() ) {
m_types.push_back(type);
m_creators.insert(std::make_pair(type, creator));
return true;
}
Expand Down
12 changes: 12 additions & 0 deletions SniperKernel/src/Sniper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,18 @@ void Sniper::loadDll(const char *dll)
}
}

std::string Sniper::dlls()
{
return SniperJSON().from(Sniper::LoadDlls).str(-9);
}

std::string Sniper::validTypes()
{
static auto& factory = DLEFactory::instance();
auto& types = factory.validTypes();
return SniperJSON().from(types).str(-9);
}

std::string Sniper::System::sysDate()
{
time_t t = time(0);
Expand Down
2 changes: 2 additions & 0 deletions SniperPython/src/SniperExp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,6 @@ void export_Sniper_Sniper()
def("setLogFile", SniperExp::setLogFile2);
def("setLogStdout", &Sniper::setLogStdout);
def("loadDll", &Sniper::loadDll);
def("dlls", &Sniper::dlls);
def("validTypes", &Sniper::validTypes);
}

0 comments on commit ec8df20

Please sign in to comment.