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 } 00131 00132 /* 00133 * Change log : 00134 * 00135 * $Log: SolutionRequest.cpp,v $ 00136 * Revision 1.2 2004/05/27 10:08:10 thomas 00137 * added model-specific locations 00138 * 00139 * Revision 1.1.1.1 2004/05/22 17:37:20 cvsadm 00140 * created new repository GT2004_WM 00141 * 00142 * Revision 1.2 2004/01/24 14:55:29 loetzsch 00143 * created ATH AiboControl 00144 * 00145 * Revision 1.1 2003/10/07 10:13:24 cvsadm 00146 * Created GT2004 (M.J.) 00147 * 00148 * Revision 1.2 2003/09/01 15:19:01 juengel 00149 * SolutionRequest clean-up. 00150 * 00151 * Revision 1.1.1.1 2003/07/02 09:40:29 cvsadm 00152 * created new repository for the competitions in Padova from the 00153 * tamara CVS (Tuesday 2:00 pm) 00154 * 00155 * removed unused solutions 00156 * 00157 * Revision 1.13 2003/05/11 17:03:00 risler 00158 * added location.cfg 00159 * 00160 * Revision 1.12 2003/04/25 19:50:17 goehring 00161 * Added new module CollisionDetector 00162 * 00163 * Revision 1.11 2002/11/11 11:53:02 risler 00164 * added error message for wrong modules.cfg 00165 * 00166 * Revision 1.10 2002/11/09 11:22:51 risler 00167 * added errorWhileReading flag to SolutionRequest 00168 * 00169 * Revision 1.9 2002/11/07 15:36:58 risler 00170 * removed OUTPUT in SolutionRequest streaming operator 00171 * 00172 * Revision 1.8 2002/11/06 14:10:47 risler 00173 * added error message 00174 * 00175 * Revision 1.7 2002/10/11 10:47:54 risler 00176 * added error checking to streaming operator << 00177 * 00178 * Revision 1.6 2002/10/01 15:31:02 loetzsch 00179 * fixed gcc errors 00180 * 00181 * Revision 1.5 2002/09/25 10:25:13 loetzsch 00182 * removed the "executeVisionModules" variable 00183 * from SolutionRequest and ModuleHandler. 00184 * 00185 * Revision 1.4 2002/09/24 18:41:58 risler 00186 * human readable solutionrequest streaming operator 00187 * default module solutions read from modules.cfg 00188 * 00189 * Revision 1.3 2002/09/24 16:28:20 risler 00190 * preparation for reading default module solutions from file 00191 * 00192 * Revision 1.2 2002/09/10 17:53:26 loetzsch 00193 * First draft of new Module/Solution Architecture 00194 * 00195 * Revision 1.1 2002/09/10 15:53:59 cvsadm 00196 * Created new project GT2003 (M.L.) 00197 * - Cleaned up the /Src/DataTypes directory 00198 * - Removed challenge related source code 00199 * - Removed processing of incoming audio data 00200 * - Renamed AcousticMessage to SoundRequest 00201 * 00202 * Revision 1.2 2002/06/04 00:12:24 loetzsch 00203 * added == and != operator 00204 * added bool executeVisionModules 00205 * 00206 * Revision 1.1.1.1 2002/05/10 12:40:32 cvsadm 00207 * Moved GT2002 Project from ute to tamara. 00208 * 00209 * Revision 1.4 2002/02/18 14:07:00 juengel 00210 * streaming operators send and receive numberOfSolutions 00211 * 00212 * Revision 1.3 2002/01/20 13:00:18 risler 00213 * changed implementation of selecting default solution 00214 * 00215 * Revision 1.2 2002/01/17 14:35:48 risler 00216 * SolutionRequest added 00217 * 00218 */