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