-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmarbles_bag.h
61 lines (51 loc) · 1.82 KB
/
marbles_bag.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef MARBLES_BAG_H
#define MARBLES_BAG_H
#include <vector>
#include <sst/core/component.h>
#include <sst/core/subcomponent.h>
#include <sst/elements/MarblesDemo/marbles.h>
namespace SST {
namespace MarblesDemo {
class MarblesBag : public Component {
public:
SST_ELI_REGISTER_COMPONENT(
MarblesBag,
"MarblesDemo",
"MarblesBag",
SST_ELI_ELEMENT_VERSION(1,0,0),
"A component that holds marbles",
COMPONENT_CATEGORY_UNCATEGORIZED
)
SST_ELI_DOCUMENT_PARAMS(
{"max_marbles", "The maximum number of marbles that can be held in the bag", "10"}
)
SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(
{"marbleSlot", "Slot to load a marble subcomponent", "SST::MarblesDemo::Marble"}
)
MarblesBag(ComponentId_t id, Params& params) : Component(id) {
output = new SST::Output("MarblesBag", 1, 0, SST::Output::STDOUT);
int maxMarbles = params.find<int>("max_marbles", 10);
SubComponentSlotInfo* info = getSubComponentSlotInfo("marbleSlot");
if (info) { // at least one SubComponent was loaded
int maxSlot = info->getMaxPopulatedSlotNumber();
int marbleLimit = std::min(maxSlot + 1, maxMarbles);
marbles.resize(marbleLimit);
for (int i = 0; i < marbleLimit; i++) {
if (info->isPopulated(i)) { // check for holes in the vector
marbles[i] = info->create<Marble>(i, ComponentInfo::SHARE_NONE);
}
}
}
output->output("\nMarble Bag Inventory:\n\n");
for (int i = 0; i < marbles.size(); i++) {
marbles[i]->print(output);
}
output->output("\n");
}
private:
std::vector<Marble*> marbles;
SST::Output *output;
};
} // namespace MarblesDemo
} // namespace SST
#endif // MARBLES_BAG_H