Created
July 14, 2012 12:55
-
-
Save tomthorogood/3111137 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void submitBroadcast(BroadcastMessage* broadcast) | |
{ | |
namespace TypeBits = Enums::SignalTypes; | |
unsigned char signalType = broadcast->getSignalType(); | |
// Verify the integrity of this broadcast. | |
if (signalType < SIGNALRANGE[0] || signalType > SIGNALRANGE[1]) | |
{ | |
//@TODO: Throw Error! | |
} | |
/* If this is the first time we're transmitting this broadcast, | |
* determine who should be listening to it. | |
*/ | |
ListenerMap::iterator iter = listenerMap.find(broadcast); | |
if (iter == listenerMap.end()) | |
{ | |
/*Listeners is a typedef for: HungryVector <Moldable*> | |
*HungryVector is an implementatino of a standard vector that | |
* saves on resizing operations by doubling the vector size whenever its | |
* current limit is reached. I have tested this baby thoroughly, but you | |
* can also find it in my github if you'd like to examine it yourself. | |
*/ | |
Listeners* listener = new Listeners(); | |
listener->add(broadcast->getBroadcaster()); | |
listener->trim(); | |
listenerMap[broadcast] = listener; | |
} | |
//... | |
} | |
// That is where the original vector is created. | |
// Here is where more vector operations happen: | |
// I am going for infinite recursion here, and allowing signals between widgets | |
// to rebroadcast ad nauseam, so this updates the listeners vector with the next | |
// "level" of listeners, either up to the parent, down to the children, laterally | |
// to any siblings, or if nothing else, staying with itself. I know the 'self' one is | |
// really just wasted operations; it's a new algorithm. | |
void getNuclearFamily(BroadcastMessage* broadcast) | |
{ | |
namespace Family = Enums::Family; | |
Family::_Family familyMembers = broadcast->getListenerType(); | |
Listeners* current_listeners = listenerMap[broadcast]; | |
Listeners* new_listeners = new Listeners(); | |
unsigned int num_current = current_listeners->size(); | |
for (unsigned int c = 0; c < num_current; c++) | |
{ | |
Moldable* listener = current_listeners->at(c); | |
switch(familyMembers) | |
{ | |
case Family::children:{ | |
unsigned int num_children = listener->countMoldableChildren(); | |
for (unsigned int k = 0; k < num_children; k++) | |
{ | |
Moldable* child = listener->child(k); | |
new_listeners->add(child); | |
} | |
break;} | |
case Family::parent:{ | |
Moldable* parent = (Moldable*) listener->parent(); | |
new_listeners->add(parent); | |
break;} | |
case Family::siblings:{ | |
Moldable* parent = (Moldable*) listener->parent(); | |
unsigned int num_siblings = parent->countMoldableChildren(); | |
for (unsigned int k = 0; k < num_siblings; k++) | |
{ | |
Moldable* sibling = parent->child(k); | |
if (sibling != listener) | |
{ | |
new_listeners->add(sibling); | |
} | |
} | |
break;} | |
default: | |
new_listeners->add(listener); | |
} | |
} | |
new_listeners->trim(); | |
unsigned int num_listeners_debug = new_listeners->size(); | |
listenerMap[broadcast] = new_listeners; | |
/* Deletes the origianl vector of pointers which, as far as I understand, does not | |
* call the destructors of the objects being pointed to. | |
*/ | |
delete current_listeners; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment