3 #include <boost/filesystem.hpp> 4 #include <boost/algorithm/string.hpp> 5 #include <boost/algorithm/string/predicate.hpp> 13 #include DYNAMICLOADLIB 15 namespace fs = boost::filesystem;
36 lib_ = OptionalQuery<std::string>(t,
"lib", agent_);
37 path_ = OptionalQuery<std::string>(t,
"path",
"");
38 alias_ = OptionalQuery<std::string>(t,
"alias", agent_);
42 std::vector<std::string> strs;
44 if (strs.size() != 3) {
45 throw ValueError(
"invalid agent spec string '" + str_spec +
"'");
55 boost::replace_all(s,
"/",
"_");
56 boost::replace_all(s,
"-",
"_");
57 boost::replace_all(s,
":",
"_");
58 boost::replace_all(s,
".",
"_");
63 return (fs::path(path_) / fs::path(
"lib" + lib_ +
SUFFIX)).string();
67 return path_ +
":" + lib_ +
":" + agent_;
70 std::map<std::string, DynamicModule*> DynamicModule::modules_;
71 std::map<std::string, AgentCtor*> DynamicModule::man_ctors_;
74 if (man_ctors_.count(spec.
str()) > 0) {
75 Agent* a = man_ctors_[spec.
str()](ctx);
78 }
else if (modules_.count(spec.
str()) == 0) {
80 modules_[spec.
str()] = dyn;
85 if (boost::starts_with(dyn->
path(),
"<py>")) {
91 a = dyn->ConstructInstance(ctx);
108 std::map<std::string, DynamicModule*>::iterator it;
109 for (it = modules_.begin(); it != modules_.end(); it++) {
110 it->second->CloseLibrary();
127 : module_library_(0),
130 if (boost::starts_with(path_,
"<py>")) {
134 ctor_name_ =
"Construct" + spec.
agent();
A generic mechanism to manually manage exceptions.
static bool Exists(AgentSpec spec)
Tests that an agent spec really exists.
For values that are too big, too small, etc.
static bool IsPyAgent(AgentSpec spec)
Tests that an agent spec is for a Python Agent.
A class for extracting information from a given XML parser.
void ClearPyAgentRefs(void)
Removes all Python agents from the internal cache.
static std::string FindModule(std::string path)
Returns the full path to a module by searching through default install and CYCLUS_PATH directories...
static void CloseAll()
Closes all statically loaded dynamic modules.
Agent * MakePyAgent(std::string lib, std::string agent, void *ctx)
Finds a Python module and returns an agent pointer from it.
virtual std::string GetString(std::string query, int index=0)
investigates the current status and returns a string representing the content of a query at a given i...
std::string spec()
The string representation of the agent spec that uniquely identifies the concrete agent class/module...
std::string path()
The path to the module's shared object library.
DynamicModule()
Do-nothing constructor.
A simulation context provides access to necessary simulation-global functions and state...
The abstract base class used by all types of agents that live and interact in a simulation.
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or.org/Osi/browser/trunk.
static Agent * Make(Context *ctx, AgentSpec spec)
Returns a newly constructed agent for the given module spec.
std::vector< std::string > split(const std::string &s, char delim)