CYCLUS
Loading...
Searching...
No Matches
dynamic_module.h
Go to the documentation of this file.
1#ifndef CYCLUS_SRC_DYNAMIC_MODULE_H_
2#define CYCLUS_SRC_DYNAMIC_MODULE_H_
3
4#include <string>
5#include <map>
6
7#include "error.h"
8
9// for testing
10class SimInitTest;
11
12namespace cyclus {
13
14class Agent;
15class Context;
16
18
19class InfileTree;
20
21class AgentSpec {
22 public:
25 AgentSpec(std::string path, std::string lib, std::string agent,
26 std::string alias);
27 AgentSpec(std::string str_spec);
28
29 std::string Sanitize();
30 std::string LibPath();
31 std::string str();
32
33 std::string path() { return path_; }
34 std::string lib() { return lib_; }
35 std::string agent() { return agent_; }
36 std::string alias() { return alias_; }
37
38 private:
39 std::string path_;
40 std::string lib_;
41 std::string agent_;
42 std::string alias_;
43};
44
45std::string SanitizeSpec(std::string module_spec);
46
47std::string ModuleConstructor(std::string module_spec);
48
50 public:
51 /// Convenience class for using a stack variable to auto-destruct all loaded
52 /// dynamic modules.
53 class Closer {
54 public:
56 CloseAll();
57 }
58 };
59
60 /// Do-nothing constructor
62
63 /// Returns a newly constructed agent for the given module spec.
64 static Agent* Make(Context* ctx, AgentSpec spec);
65
66 /// Tests that an agent spec really exists.
67 static bool Exists(AgentSpec spec);
68
69 /// Closes all statically loaded dynamic modules. This should always be called
70 /// before process termination. This must be called AFTER all agents have
71 /// been destructed.
72 static void CloseAll();
73
74 /// Tests that an agent spec is for a Python Agent. This will also return false
75 /// if the agent doesn't already exist.
76 static bool IsPyAgent(AgentSpec spec);
77
78 /// The path to the module's shared object library.
79 std::string path();
80
81 private:
82 /// Creates a new dynamically loadable module.
83 /// @param name the name of the module
85
86 /// construct an instance of this module
87 /// @return a fresh instance
88 Agent* ConstructInstance(Context* ctx);
89
90 /// closes the loaded module dynamic lib
91 void CloseLibrary();
92
93 /// all dynamically loaded modules are
94 /// added to this map when loaded.
95 static std::map<std::string, DynamicModule*> modules_;
96
97 /// for testing - see sim_init_tests
98 friend class ::SimInitTest;
99 static std::map<std::string, AgentCtor*> man_ctors_;
100
101 /// the name of the module
102 std::string path_;
103
104 /// the name of the module
105 std::string ctor_name_;
106
107 /// the library to open and close
108 void* module_library_;
109
110 /// a functor for the constructor
111 AgentCtor* ctor_;
112
113 /// uses dlopen to open the module shared lib
114 void OpenLibrary();
115
116 /// sets the constructor member
117 void SetConstructor();
118};
119
120} // namespace cyclus
121
122#endif // CYCLUS_SRC_DYNAMIC_MODULE_H_
a holding class for information related to a TradeExecutor
std::string alias()
std::string path()
std::string Sanitize()
std::string str()
std::string agent()
std::string LibPath()
std::string lib()
The abstract base class used by all types of agents that live and interact in a simulation.
Definition agent.h:49
A simulation context provides access to necessary simulation-global functions and state.
Definition context.h:145
Convenience class for using a stack variable to auto-destruct all loaded dynamic modules.
static void CloseAll()
Closes all statically loaded dynamic modules.
static bool IsPyAgent(AgentSpec spec)
Tests that an agent spec is for a Python Agent.
DynamicModule()
Do-nothing constructor.
static Agent * Make(Context *ctx, AgentSpec spec)
Returns a newly constructed agent for the given module spec.
static bool Exists(AgentSpec spec)
Tests that an agent spec really exists.
std::string path()
The path to the module's shared object library.
A class for extracting information from a given XML parser.
Definition infile_tree.h:22
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
Definition agent.cc:14
Agent * AgentCtor(Context *)
std::string SanitizeSpec(std::string module_spec)
std::string ModuleConstructor(std::string module_spec)
T OptionalQuery(InfileTree *tree, std::string query, T default_val)
a query method for optional parameters