Skip to content
Snippets Groups Projects
Commit b6e0281b authored by KyleKlenk's avatar KyleKlenk
Browse files

Created structure to hold actors

parent 9f05b702
No related branches found
No related tags found
No related merge requests found
......@@ -46,6 +46,10 @@ class ActorRefList {
return actor;
}
bool isEmpty() {
return list.empty();
}
......@@ -55,16 +59,65 @@ class OutputManager {
private:
int numVectors;
std::vector<std::vector<caf::actor>> actorRefList;
int avgSizeOfActorList;
std::vector<ActorRefList*> list;
public:
// Constructor
OutputManager(){}
OutputManager(int numVectors, int totalNumActors){
this->numVectors = numVectors;
int sizeOfOneVector = totalNumActors / numVectors;
this->avgSizeOfActorList = sizeOfOneVector;
// Create the first n-1 vectors with the same size
for (int i = 0; i < numVectors - 1; i++) {
auto refList = new ActorRefList(sizeOfOneVector);
totalNumActors = totalNumActors - sizeOfOneVector;
list.push_back(refList);
}
// Create the last vector with size however many actors are left
auto refList = new ActorRefList(totalNumActors);
list.push_back(refList);
}
// Deconstructor
~OutputManager(){};
void addActor(caf::actor actor, int index) {
// Index has to be subtracted by 1 because Fortran array starts at 1
int listIndex = (index - 1) / this->avgSizeOfActorList;
if (listIndex > this->numVectors - 1 || listIndex < 0) {
throw "List Index Out Of Range";
}
this->list[listIndex]->addActor(actor);
}
caf::actor popActor(int index) {
if (index > this->numVectors - 1 || index < 0) {
throw "List Index Out Of Range";
} else if (this->list[index]->isEmpty()) {
throw "List is Empty, Nothing to pop";
}
return this->list[index]->popActor();
}
bool isFull(int listIndex) {
if (listIndex > this->numVectors - 1) {
throw "List Index Out Of Range";
}
return this->list[listIndex]->isFull();
}
int getSize(int listIndex) {
if (listIndex > this->numVectors - 1) {
throw "List Index Out Of Range";
}
return this->list[listIndex]->getCurrentSize();
}
};
#endif
\ No newline at end of file
......@@ -9,7 +9,6 @@
using namespace caf;
behavior test_coordinator(stateful_actor<test_state>* self) {
aout(self) << "Starting Test Actor\n";
return {
};
}
......@@ -94,7 +93,7 @@ void test_calculateTime() {
}
void testOutputManager(caf::actor_system& sys) {
void testActorRefList(caf::actor_system& sys) {
auto a1 = sys.spawn(test_coordinator);
auto a2 = sys.spawn(test_coordinator);
auto a3 = sys.spawn(test_coordinator);
......@@ -144,21 +143,122 @@ void testOutputManager(caf::actor_system& sys) {
std::cerr << msg << std::endl;
IS_TRUE(om->getCurrentSize() == 0)
}
}
void testOutputManager(caf::actor_system& sys) {
auto a1 = sys.spawn(test_coordinator);
auto a2 = sys.spawn(test_coordinator);
auto a3 = sys.spawn(test_coordinator);
auto a4 = sys.spawn(test_coordinator);
auto a5 = sys.spawn(test_coordinator);
auto a6 = sys.spawn(test_coordinator);
auto a7 = sys.spawn(test_coordinator);
auto a8 = sys.spawn(test_coordinator);
auto a9 = sys.spawn(test_coordinator);
auto a10 = sys.spawn(test_coordinator);
auto OM = new OutputManager(5, 10);
for (int i = 0; i < 5; i++) {
IS_TRUE(OM->getSize(i) == 0)
}
try {
OM->getSize(8);
} catch (const char* msg) {
std::cerr << msg << std::endl;
}
OM->addActor(a1, 1);
IS_TRUE(OM->getSize(0) == 1);
IS_TRUE(OM->getSize(1) == 0);
IS_TRUE(OM->getSize(2) == 0);
IS_TRUE(OM->getSize(3) == 0);
IS_TRUE(OM->getSize(4) == 0);
OM->addActor(a2, 2);
IS_TRUE(OM->getSize(0) == 2);
IS_TRUE(OM->getSize(1) == 0);
IS_TRUE(OM->getSize(2) == 0);
IS_TRUE(OM->getSize(3) == 0);
IS_TRUE(OM->getSize(4) == 0);
OM->addActor(a3, 3);
IS_TRUE(OM->getSize(0) == 2);
IS_TRUE(OM->getSize(1) == 1);
IS_TRUE(OM->getSize(2) == 0);
IS_TRUE(OM->getSize(3) == 0);
IS_TRUE(OM->getSize(4) == 0);
OM->addActor(a4, 4);
IS_TRUE(OM->getSize(0) == 2);
IS_TRUE(OM->getSize(1) == 2);
IS_TRUE(OM->getSize(2) == 0);
IS_TRUE(OM->getSize(3) == 0);
IS_TRUE(OM->getSize(4) == 0);
OM->addActor(a5, 5);
IS_TRUE(OM->getSize(0) == 2);
IS_TRUE(OM->getSize(1) == 2);
IS_TRUE(OM->getSize(2) == 1);
IS_TRUE(OM->getSize(3) == 0);
IS_TRUE(OM->getSize(4) == 0);
OM->addActor(a6, 6);
IS_TRUE(OM->getSize(0) == 2);
IS_TRUE(OM->getSize(1) == 2);
IS_TRUE(OM->getSize(2) == 2);
IS_TRUE(OM->getSize(3) == 0);
IS_TRUE(OM->getSize(4) == 0);
OM->addActor(a7, 7);
IS_TRUE(OM->getSize(0) == 2);
IS_TRUE(OM->getSize(1) == 2);
IS_TRUE(OM->getSize(2) == 2);
IS_TRUE(OM->getSize(3) == 1);
IS_TRUE(OM->getSize(4) == 0);
OM->addActor(a8, 8);
IS_TRUE(OM->getSize(0) == 2);
IS_TRUE(OM->getSize(1) == 2);
IS_TRUE(OM->getSize(2) == 2);
IS_TRUE(OM->getSize(3) == 2);
IS_TRUE(OM->getSize(4) == 0);
OM->addActor(a9, 9);
IS_TRUE(OM->getSize(0) == 2);
IS_TRUE(OM->getSize(1) == 2);
IS_TRUE(OM->getSize(2) == 2);
IS_TRUE(OM->getSize(3) == 2);
IS_TRUE(OM->getSize(4) == 1);
IS_TRUE(!OM->isFull(4))
OM->addActor(a10, 10);
IS_TRUE(OM->getSize(0) == 2);
IS_TRUE(OM->getSize(1) == 2);
IS_TRUE(OM->getSize(2) == 2);
IS_TRUE(OM->getSize(3) == 2);
IS_TRUE(OM->getSize(4) == 2);
IS_TRUE(OM->isFull(0))
IS_TRUE(OM->isFull(1))
IS_TRUE(OM->isFull(2))
IS_TRUE(OM->isFull(3))
IS_TRUE(OM->isFull(4))
auto a11 = OM->popActor(0);
IS_TRUE(a11 == a2);
auto a14 = OM->popActor(0);
IS_TRUE(a14 == a1);
auto a12 = OM->popActor(1);
IS_TRUE(a12 == a4);
auto a13 = OM->popActor(4);
IS_TRUE(a13 == a10);
IS_TRUE(OM->getSize(0) == 0);
IS_TRUE(OM->getSize(1) == 1);
IS_TRUE(OM->getSize(2) == 2);
IS_TRUE(OM->getSize(3) == 2);
IS_TRUE(OM->getSize(4) == 1);
}
void caf_main(caf::actor_system& sys) {
caf::scoped_actor self{sys};
aout(self) << "Starting Test \n";
// test_calculateTime();
testActorRefList(sys);
testOutputManager(sys);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment