#include "sectionToExecute.h" #include "softwareUnknown.h" #include "softwareParmela.h" #include "softwareTransport.h" #include "softwareGenerator.h" #include "softwareGenerator.h" #include "softwareUsersprogram.h" #include "softwareTest.h" #include "softwareMadx.h" //xx sectionToExecute::sectionToExecute(abstractElement* f, abstractSoftware* s,dataManager* data,sector* sect) { dataManager_ = data; sector_ = sect; elements_.push_back(f); if (s == NULL) { software_ = new softwareUnknown(); } else { software_ = s; } } bool sectionToExecute::insertAfter(abstractElement* previousElement,abstractElement* currentElement) { std::vector::iterator it; for (it = elements_.begin(); it < elements_.end(); it++) { if (*it == previousElement ) { elements_.insert (it+1,currentElement); return true; } } return false; } void sectionToExecute::setSoftware(std::string logiciel) { abstractSoftware* prog; string inputFileName; if(logiciel == "parmela") { inputFileName = "parmin"; prog = new softwareParmela(inputFileName, this,dataManager_ ); } else if (logiciel == "transport") { inputFileName = "transport.input"; prog = new softwareTransport(inputFileName, this,dataManager_ ); } else if (logiciel == "generator") { inputFileName = "generator.in"; prog = new softwareGenerator(inputFileName, this,dataManager_ ); } else if (logiciel == "madx") { inputFileName = "madx.input"; prog = new softwareMadx(inputFileName,this,dataManager_ ); } else if (logiciel == "usersprogram") { inputFileName = "dummy"; prog = new softwareUsersprogram(inputFileName, this,dataManager_ ); } else if (logiciel == "test") { prog = new softwareTest(inputFileName, this,dataManager_ ); } else { prog = new softwareUnknown(); } setSoftware(prog); } void sectionToExecute::setFirstElement(int index) { // This will set the beginning of this section to the element with the given name // Possible cases : // // | section 1 | section 2 | section 3 | section 4 | section 5 | // | a b c d | e f g h | i j k l | m n o p | q r | Before (example) // Moved in a previous section : // | a b c d | e f | _g_ h i j k l | m n o p | q r | Case 1 : move beginning of section 3 to "g" // | a b c | | _d_ e f g h i j k l | m n o p | q r | Case 2 : move beginning of section 3 to "d" => section 2 will be removed ! // => all elements from "d"/"g" to "l" will be moved in the 3rd section // Moved in the same section : // | a b c d | e f g h i j | _k_ l | m n o p | q r | Case 3 : move beginning of section 3 to "k" // => all elements from "i"(begin of 3rd section) to before "k" will be moved in the 2nd (3-1) section // Moved in a next section : // | a b c d | e f g h i j k l m | _n_ | o p | q r | Case 4 : move beginning of section 3 to "n" // | a b c d | e f g h i j k l m n o p | _q_ | | r | Case 5 : move beginning of section 3 to "q" => remove section 4 ! // => all elements from "i"(begin of 3rd section) to before "n"/"q" will be moved in the 2nd (3-1) section // => "n"/"q" element is set to be alone in 3rd section std::vector sectVect = sector_->getSectionsToExecute(); unsigned int sectionNumber = 0; int newBeginSectionNumber = 0; unsigned long indexOfNewBeginSectionNumber = 0; // get this section number // get the section number of the new begin element unsigned int n = 0; bool newFound = false; for (unsigned int a=0; a< sectVect.size(); a++) { if (sectVect[a] == this) { sectionNumber = a; } n += sectVect[a]->getElements().size(); if ((n >index ) && (!newFound)) { newBeginSectionNumber = a; indexOfNewBeginSectionNumber = index - (n-sectVect[a]->getElements().size()); newFound = true; } } if (!newFound ) { return; // Impossible to find this index } // Moved in a previous section if ( newBeginSectionNumber < sectionNumber ) { for (int a = sectionNumber-1 ; a >= newBeginSectionNumber; a--) { std::vector< abstractElement* > elemsVect = sectVect[a]->getElements(); long stop = 0; long start = elemsVect.size(); if (a == newBeginSectionNumber) { stop = indexOfNewBeginSectionNumber; } for (long elemIndex = start; elemIndex > stop; elemIndex--) { insertAtFirst(elemsVect.back()); elemsVect.pop_back(); // remove elements sectVect[a]->removeLastElement(); } } // Moved in the same section : } else if (( newBeginSectionNumber == sectionNumber ) && (sectionNumber > 0)){ for (long elemIndex = 0; elemIndex < indexOfNewBeginSectionNumber; elemIndex++) { sectVect[sectionNumber-1]->insertAtLast(elements_.front()); removeFirstElement(); } // Moved in a next section : } else if ( newBeginSectionNumber > sectionNumber ) { } // Suppress the empty sections for (unsigned int a=0; a< sectVect.size(); a++) { if (sectVect[a]->getElements().size() == 0 ) { sector_->clearSectionToExecute(a); } } } bool sectionToExecute::isInside(abstractElement* previousElement) { for (unsigned int a=0; a< elements_.size(); a++) { if (elements_[a] == previousElement ) { return true; } } return false; } void sectionToExecute::removeElement(abstractElement* previousElement){ std::vector::iterator it; for (it = elements_.begin(); it < elements_.end(); it++) { if (*it == previousElement ) { elements_.erase(it); return; } } }