• 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.19
/src/xml_flat_loader.cc
1
#include "xml_flat_loader.h"
2

3
#include "agent.h"
4
#include "context.h"
5
#include "discovery.h"
6
#include "env.h"
7
#include "error.h"
8
#include "infile_tree.h"
9
#include "logger.h"
10
#include "recorder.h"
11
#include "timer.h"
12

13
namespace cyclus {
14

15
std::string BuildFlatMasterSchema(std::string schema_path,
4✔
16
                                  std::vector<AgentSpec> specs) {
17
  Timer ti;
4✔
18
  Recorder rec;
4✔
19
  Context ctx(&ti, &rec);
4✔
20

21
  std::stringstream schema("");
4✔
22
  LoadStringstreamFromFile(schema, schema_path);
12✔
23
  std::string master = schema.str();
24

25
  std::string subschemas;
26
  for (int i = 0; i < specs.size(); ++i) {
12✔
27
    Agent* m = DynamicModule::Make(&ctx, specs[i]);
8✔
28
    subschemas += "<element name=\"" + specs[i].alias() + "\">\n";
16✔
29
    subschemas += m->schema() + "\n";
16✔
30
    subschemas += "</element>\n";
31
    ctx.DelAgent(m);
8✔
32
  }
33

34
  // replace refs in master rng template file
35
  std::string search_str = std::string("@MODEL_SCHEMAS@");
4✔
36
  size_t pos = master.find(search_str);
37
  if (pos != std::string::npos) {
4✔
38
    master.replace(pos, search_str.size(), subschemas);
39
  }
40

41
  return master;
4✔
42
}
4✔
43

44
std::string BuildFlatMasterSchema(std::string schema_path, std::string infile) {
4✔
45
  std::vector<AgentSpec> specs = ParseSpecs(infile);
12✔
46

47
  return BuildFlatMasterSchema(schema_path, specs);
16✔
48
}
4✔
49

50
std::string BuildFlatMasterSchema(std::string schema_path) {
×
51
  std::vector<AgentSpec> specs =
NEW
52
      ParseSpecs(cyclus::DiscoverSpecsInCyclusPath());
×
53

54
  return BuildFlatMasterSchema(schema_path, specs);
×
UNCOV
55
}
×
56

57
std::string XMLFlatLoader::master_schema() {
4✔
58
  return BuildFlatMasterSchema(schema_path_, file_);
12✔
59
}
60

61
void XMLFlatLoader::LoadInitialAgents() {
4✔
62
  InfileTree xqe(*parser_);
4✔
63

64
  // create prototypes
65
  int num_protos = xqe.NMatches("/*/prototype");
4✔
66
  for (int i = 0; i < num_protos; i++) {
12✔
67
    InfileTree* qe = xqe.SubTree("/*/prototype", i);
8✔
68
    std::string prototype = qe->GetString("name");
8✔
69
    std::string alias = qe->SubTree("config")->GetElementName(0);
8✔
70
    AgentSpec spec = specs_[alias];
8✔
71

72
    Agent* agent = DynamicModule::Make(ctx_, spec);
8✔
73

74
    // call manually without agent impl injected to keep all Agent state in a
75
    // single, consolidated db table
76
    agent->Agent::InfileToDb(qe, DbInit(agent, true));
8✔
77

78
    agent->InfileToDb(qe, DbInit(agent));
8✔
79
    rec_->Flush();
8✔
80

81
    std::vector<Cond> conds;
82
    conds.push_back(Cond("SimId", "==", rec_->sim_id()));
24✔
83
    conds.push_back(Cond("AgentId", "==", agent->id()));
16✔
84
    conds.push_back(Cond("SimTime", "==", static_cast<int>(0)));
16✔
85
    CondInjector ci(b_, conds);
8✔
86
    PrefixInjector pi(&ci, "AgentState");
8✔
87

88
    // call manually without agent impl injected
89
    agent->Agent::InitFrom(&pi);
8✔
90

91
    pi = PrefixInjector(&ci, "AgentState" + spec.Sanitize());
24✔
92
    agent->InitFrom(&pi);
8✔
93
    ctx_->AddPrototype(prototype, agent);
24✔
94
  }
8✔
95

96
  // retrieve agent hierarchy and initial inventories
97
  int num_agents = xqe.NMatches("/*/agent");
8✔
98
  std::map<std::string, std::string> protos;   // map<name, prototype>
99
  std::map<std::string, std::string> parents;  // map<agent, parent>
100
  std::set<std::string> agents;                // set<agent_name>
101
  std::map<std::string, InfileTree*> invs;     // map<agent, qe>;
102
  for (int i = 0; i < num_agents; i++) {
12✔
103
    InfileTree* qe = xqe.SubTree("/*/agent", i);
8✔
104
    std::string name = qe->GetString("name");
8✔
105
    std::string proto = qe->GetString("prototype");
8✔
106
    std::string parent = OptionalQuery<std::string>(qe, "parent", "");
16✔
107
    protos[name] = proto;
8✔
108
    parents[name] = parent;
8✔
109
    invs[name] = qe;
8✔
110
    agents.insert(name);
111
  }
112

113
  // build agents starting at roots (no parent) down.
114
  std::map<std::string, Agent*> built;  // map<agent_name, agent_ptr>
115
  std::set<std::string>::iterator it = agents.begin();
116
  while (agents.size() > 0) {
12✔
117
    std::string name = *it;
118
    std::string proto = protos[name];
8✔
119
    std::string parent = parents[name];
8✔
120
    if (parent == "") {
8✔
121
      built[name] = BuildAgent(proto, NULL);
16✔
122
      ++it;
123
      agents.erase(name);
124
    } else if (built.count(parent) > 0) {
125
      built[name] = BuildAgent(proto, built[parent]);
×
126
      ++it;
127
      agents.erase(name);
128
    } else {
129
      ++it;
130
    }
131
    if (it == agents.end()) {
8✔
132
      it = agents.begin();
133
    }
134
  }
135
}
4✔
136

137
}  // 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