// Class automatically generated by Dev-C++ New Class wizard #include "nodelibrary.h" // class's header file // class constructor nodeLibrary::nodeLibrary() { strcpy(rootName,"RoOt: "); Node *root; root = new Node(rootName); nodeCount = 0; numNodes = 0; cout << "Setting Library Root (default) to: " << rootName << endl; root->thresh = 0; library[0] = root; } nodeLibrary::nodeLibrary(char rtN[20]) { strcpy(rootName, rtN); Node *root; root = new Node(rootName); nodeCount = 0; numNodes = 0; cout << "Setting Library Root to: " << rootName << endl; root->thresh = 0; library[0] = root; strcpy(library[0]->rootName, rootName); } // class destructor nodeLibrary::~nodeLibrary() { // insert your code here } void nodeLibrary::addNode(Node *adding) { nodeCount++; numNodes++; library[nodeCount] = adding; strcpy(library[nodeCount]->rootName, rootName); //Set new node with this librarys rootname //cout << "Node #" << nodeCount << " inserted :" << library[nodeCount]->name << endl; //cout << "Connected to root: " << library[nodeCount]->rootName << endl; } void nodeLibrary::addInput(Node *a, Node *b) { a->addInput(b); } void nodeLibrary::addInput(Node *a, Node *b, float w) { a->addInput(b, w); } void nodeLibrary::showOut(Node *showing) { showing->showOut(); } void nodeLibrary::showIn(Node *showing) { showing->showIn(); } int nodeLibrary::findNode(char name[20]) { // cout << "Searching for " << name << endl; for (int i=0; i<=nodeCount; i++) { if (strcmpi(library[i]->name, name) == 0) { //cout << "found :" << name << " at position "<< i << "- returning" << endl; return i; //Returns library position } } //cout << "Node Not Found" << endl; return 9999; } void nodeLibrary::save() { for (int q=0; q<=numNodes; q++) { for (int r=0; rinNode; r++) // for all of Q's inputs { library[q]->inputsLibRef[r]=findNode(library[q]->inputs[r]->name); } //What just happened there? I set Q's #r inputLibRef to the library position of Q's #r input pointer for (int r=0; routNode; r++) // for all of Q's outputs { library[q]->outputsLibRef[r]=findNode(library[q]->outputs[r]->name); } // Again, Q's #r outputLibRef set to this.library position of Q's #r output pointer lib[q]=*library[q]; // now that q is processed, sent the node to array cout << "Node #"<< q << " named: "<< library[q]->name<< " going to stack as " << lib[q].name << endl; } // Move to next node Q // FYI - File saving should happen outside library\ // All pointers should be backed-up by a physical location (inputsLibRef/outputsLibRef) } void nodeLibrary::load() { // Library array, etc. should already be set(outside the library) for (int i=0; i<=numNodes; i++) { library[i] = &lib[i]; //Set the pointers to the appropriate nodes in the array } // Must set all nodes first for the nodes to be able to point at others for (int i=0; i<=numNodes; i++) { for (int j=0; jinNode; j++) // for all of I's inputs { library[i]->inputs[j]=library[ library[i]->inputsLibRef[j] ]; } //What just happened there? I set I's #j inputs pointer to the Node at library position of Q's #r inputLibRef for (int j=0; joutNode; j++) // for all of I's inputs { library[i]->outputs[j]=library[ library[i]->outputsLibRef[j] ]; // point to node at position (I's outputLibRef #r) } //Again? I set I's #j outputs pointer to the Node at library position of Q's #r outputLibRef cout << "Node #"<< i << " named: "<< library[i]->name<< " retrieved from stack" <