Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

Tools/Module/SolutionRequest.cpp

Go to the documentation of this file.
00001 /**
00002 * @file SolutionRequest.cpp
00003 *
00004 * Implementation of class SolutionRequest
00005 *
00006 * @author Martin Lötzsch
00007 * @author Max Risler
00008 */
00009 
00010 #include "SolutionRequest.h"
00011 #include "Tools/Debugging/Debugging.h"
00012 #include "Platform/GTAssert.h"
00013 #include "Tools/Streams/InStreams.h"
00014 #include "Tools/Location.h"
00015 
00016 SolutionRequest::SolutionRequest(bool setDefault)
00017 {
00018   errorWhileReading = false;
00019   if (setDefault) 
00020     setDefaultSolutions();
00021   else
00022   {
00023     for (int i=0;i<numOfModules;i++)
00024     {
00025       solutions[i] = disabled;
00026     }
00027   }
00028 }
00029 
00030 void SolutionRequest::setDefaultSolutions()
00031 {
00032   InConfigFile modulesFile(getLocation().getModelFilename("modules.cfg"));
00033   if (!modulesFile.exists() || modulesFile.eof()) {
00034     errorWhileReading = true;
00035 //    OUTPUT(idText,text,"SolutionRequest : Error, modules.cfg not found.");
00036     for (int i=0;i<numOfModules;i++)
00037     {
00038       solutions[i] = disabled;
00039     }
00040   } else {
00041     modulesFile >> *this;
00042     if (errorWhileReading) {
00043 //      PRINT("SolutionRequest : Error, modules.cfg contained errors. Please check or write new modules.cfg with Settings Dialog.");
00044     }
00045   }
00046 }
00047 
00048 bool SolutionRequest::operator == (const SolutionRequest& other)
00049 {
00050   for (int i=0;i<numOfModules;i++)
00051   {
00052     if (solutions[i] != other.solutions[i]) return false;
00053   }
00054   return true;
00055 }
00056 
00057 In& operator>>(In& stream,SolutionRequest& solutionRequest)
00058 {
00059   char module[80];
00060   char solution[80];
00061   int i;
00062 
00063   solutionRequest.errorWhileReading = false;
00064   for (i=0; i<SolutionRequest::numOfModules; i++)
00065     solutionRequest.solutions[i] = (SolutionRequest::ModuleSolutionID)-2;
00066 
00067   while (!stream.eof())
00068   {
00069     stream >> module;
00070     if (strlen(module) > 0) {
00071       if (stream.eof())
00072       {
00073         solutionRequest.errorWhileReading = true;
00074         //OUTPUT(idText,text,"SolutionRequest : Error while reading from stream, unexpected end.");
00075         break;
00076       }
00077       stream >> solution;
00078       for (i=0; i<SolutionRequest::numOfModules; i++) {
00079         if (strcmp(module,SolutionRequest::getModuleName((SolutionRequest::ModuleID)i))==0) 
00080         {
00081           int j;
00082           for (j=-1; j<SolutionRequest::getNumOfSolutions((SolutionRequest::ModuleID)i); j++) {
00083             if (strcmp(solution,SolutionRequest::getModuleSolutionName((SolutionRequest::ModuleID)i,(SolutionRequest::ModuleSolutionID)j))==0) {
00084               solutionRequest.solutions[i] = (SolutionRequest::ModuleSolutionID)j;
00085               break;
00086             }
00087           }
00088           if (j == SolutionRequest::getNumOfSolutions((SolutionRequest::ModuleID)i)) {
00089             solutionRequest.errorWhileReading = true;
00090             //OUTPUT(idText,text,"SolutionRequest : Error while reading from stream, invalid solution " << solution << " was requested for module " << module << ".");
00091           }
00092           break;
00093         }
00094       }
00095       if (i == SolutionRequest::numOfModules) {
00096         solutionRequest.errorWhileReading = true;
00097 //        OUTPUT(idText,text,"SolutionRequest : Error while reading from stream, invalid module " << module << ".");
00098       }
00099     }
00100   }
00101 
00102   for (i=0; i<SolutionRequest::numOfModules; i++)
00103     if (solutionRequest.solutions[i] == -2) {
00104       solutionRequest.errorWhileReading = true;
00105       solutionRequest.solutions[i] = SolutionRequest::disabled;
00106     }
00107     
00108   return stream;
00109 }      
00110   
00111 
00112 Out& operator<<(Out& stream, const SolutionRequest& solutionRequest)
00113 {
00114   stream << endl;
00115   for (int i=0;i<SolutionRequest::numOfModules;i++)
00116   {
00117     stream << SolutionRequest::getModuleName((SolutionRequest::ModuleID)i);
00118     if (solutionRequest.solutions[i] < SolutionRequest::disabled || 
00119       solutionRequest.solutions[i] >= SolutionRequest::getNumOfSolutions((SolutionRequest::ModuleID)i))
00120     {
00121       //OUTPUT is a bad idea here, since this may be called from another OUTPUT
00122       //OUTPUT(idText,text,"SolutionRequest : Error while writing to stream, SolutionRequest contained invalid value for module " << SolutionRequest::getModuleName((SolutionRequest::ModuleID)i) << ", value was " << solutionRequest.solutions[i] << ".");
00123       stream << "disabled";
00124     }
00125     else
00126       stream << SolutionRequest::getModuleSolutionName((SolutionRequest::ModuleID)i,solutionRequest.solutions[i]);
00127     stream << endl;
00128   }
00129   return stream;
00130 }

Generated on Mon Mar 20 22:00:07 2006 for GT2005 by doxygen 1.3.6