• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

cyclus / cyclus / 16384544356

19 Jul 2025 03:38AM UTC coverage: 36.53% (-4.7%) from 41.231%
16384544356

push

github

web-flow
Merge pull request #1881 from dean-krueger/clang-format

Clang Format Cyclus src

1517 of 26176 new or added lines in 94 files covered. (5.8%)

309 existing lines in 19 files now uncovered.

51830 of 141883 relevant lines covered (36.53%)

14764.59 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.54
/src/dynamic_module.cc
1
#include "dynamic_module.h"
2

3
#include <boost/filesystem.hpp>
4
#include <boost/algorithm/string.hpp>
5
#include <boost/algorithm/string/predicate.hpp>
6

7
#include "context.h"
8
#include "env.h"
9
#include "agent.h"
10
#include "platform.h"
11
#include "pyhooks.h"
12

13
#include DYNAMICLOADLIB
14

15
namespace fs = boost::filesystem;
16

17
namespace cyclus {
18

19
AgentSpec::AgentSpec(std::string path, std::string lib, std::string agent,
1✔
20
                     std::string alias)
1✔
21
    : path_(path), lib_(lib), agent_(agent), alias_(alias) {
3✔
22
  if (lib_ == "") {
1✔
23
    lib_ = agent_;
24
  }
25
  if (alias_ == "") {
1✔
26
    alias = agent_;
27
  }
28
}
1✔
29

30
AgentSpec::AgentSpec(InfileTree* t) {
1,214✔
31
  agent_ = t->GetString("name");
2,428✔
32
  lib_ = OptionalQuery<std::string>(t, "lib", agent_);
2,428✔
33
  path_ = OptionalQuery<std::string>(t, "path", "");
2,428✔
34
  alias_ = OptionalQuery<std::string>(t, "alias", agent_);
2,428✔
35
}
1,214✔
36

37
AgentSpec::AgentSpec(std::string str_spec) {
13,229✔
38
  std::vector<std::string> strs;
39
  boost::split(strs, str_spec, boost::is_any_of(":"));
26,458✔
40
  if (strs.size() != 3) {
13,229✔
41
    throw ValueError("invalid agent spec string '" + str_spec + "'");
×
42
  }
43
  path_ = strs[0];
44
  lib_ = strs[1];
45
  agent_ = strs[2];
46
  alias_ = agent_;
47
}
13,229✔
48

49
std::string AgentSpec::Sanitize() {
12,585✔
50
  std::string s = str();
12,585✔
51
  boost::replace_all(s, "/", "_");
12,585✔
52
  boost::replace_all(s, "-", "_");
12,585✔
53
  boost::replace_all(s, ":", "_");
12,585✔
54
  boost::replace_all(s, ".", "_");
12,585✔
55
  return s;
12,585✔
56
}
57

58
std::string AgentSpec::LibPath() {
430✔
59
  return (fs::path(path_) / fs::path("lib" + lib_ + SUFFIX)).string();
948✔
60
}
61

62
std::string AgentSpec::str() {
28,598✔
63
  return path_ + ":" + lib_ + ":" + agent_;
57,196✔
64
}
65

66
std::map<std::string, DynamicModule*> DynamicModule::modules_;
67
std::map<std::string, AgentCtor*> DynamicModule::man_ctors_;
68

69
Agent* DynamicModule::Make(Context* ctx, AgentSpec spec) {
3,638✔
70
  if (man_ctors_.count(spec.str()) > 0) {  // for testing
7,276✔
71
    Agent* a = man_ctors_[spec.str()](ctx);
156✔
72
    a->spec(spec.str());
156✔
73
    return a;
156✔
74
  } else if (modules_.count(spec.str()) == 0) {
6,964✔
75
    DynamicModule* dyn = new DynamicModule(spec);
406✔
76
    modules_[spec.str()] = dyn;
404✔
77
  }
78

79
  DynamicModule* dyn = modules_[spec.str()];
3,481✔
80
  Agent* a;
81
  if (boost::starts_with(dyn->path(), "<py>")) {
6,962✔
82
    /// go down a separate execution pathway if we are asked to load a
83
    /// Python module.
84
    a = MakePyAgent(spec.lib(), spec.agent(), ctx);
568✔
85
  } else {
86
    // build a C++ agent.
87
    a = dyn->ConstructInstance(ctx);
3,221✔
88
  }
89
  a->spec(spec.str());
3,481✔
90
  return a;
3,481✔
91
}
92

93
bool DynamicModule::Exists(AgentSpec spec) {
25✔
94
  bool rtn = true;
95
  try {
96
    DynamicModule dyn(spec);
25✔
97
  } catch (cyclus::Error& e) {
25✔
98
    rtn = false;
99
  }
2✔
100
  return rtn;
25✔
101
}
102

103
void DynamicModule::CloseAll() {
134✔
104
  std::map<std::string, DynamicModule*>::iterator it;
105
  for (it = modules_.begin(); it != modules_.end(); it++) {
531✔
106
    it->second->CloseLibrary();
397✔
107
    delete it->second;
397✔
108
  }
109
  modules_.clear();
110
  man_ctors_.clear();
111
  ClearPyAgentRefs();
134✔
112
}
134✔
113

114
bool DynamicModule::IsPyAgent(AgentSpec spec) {
×
115
  bool rtn = false;
NEW
116
  if (DynamicModule::Exists(spec) &&
×
NEW
117
      boost::starts_with(modules_[spec.str()]->path(), "<py>")) {
×
118
    rtn = true;
119
  }
120
  return rtn;
×
121
}
122

123
DynamicModule::DynamicModule(AgentSpec spec) : module_library_(0), ctor_(NULL) {
430✔
124
  path_ = Env::FindModule(spec.LibPath(), spec.lib());
909✔
125
  if (boost::starts_with(path_, "<py>")) {
428✔
126
    /// python module, so no need to do more
127
    return;
128
  }
129
  ctor_name_ = "Construct" + spec.agent();
731✔
130
  OpenLibrary();
364✔
131
  SetConstructor();
364✔
132
}
133

134
Agent* DynamicModule::ConstructInstance(Context* ctx) {
3,221✔
135
  return ctor_(ctx);
3,221✔
136
}
137

138
std::string DynamicModule::path() {
3,481✔
139
  return path_;
3,481✔
140
}
141

142
}  // namespace cyclus
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc