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

Tools/Streams/InStreams.cpp

Go to the documentation of this file.
00001 /**
00002 * @file InStreams.cpp
00003 *
00004 * Implementation of in stream classes.
00005 *
00006 * @author Thomas Röfer
00007 * @author Martin Lötzsch
00008 */
00009 
00010 #include "InStreams.h"
00011 #include <string.h>
00012 #include "Platform/GTAssert.h"
00013 
00014 void StreamReader::skipData(int size, PhysicalInStream& stream)
00015 {
00016   // default implementation
00017   char* dummy = new char[size];
00018   readData(dummy, size, stream);
00019   delete [] dummy;
00020 }
00021 
00022 void PhysicalInStream::skipInStream(int size)
00023 {
00024   // default implementation
00025   char* dummy = new char[size];
00026   readFromStream(dummy, size);
00027   delete [] dummy;
00028 }
00029 
00030 void InText::readString(char* value, PhysicalInStream& stream)
00031 {
00032   skipWhitespace(stream);
00033   while(!isEof(stream) && !isWhitespace())
00034   {
00035     if(theChar == '\\')
00036       nextChar(stream);
00037     *value++ = theChar;
00038     if(!isEof(stream))
00039       nextChar(stream);
00040   }
00041   *value = 0;
00042   skipWhitespace(stream);
00043 }
00044 
00045 void InText::readData(void *p,int size, PhysicalInStream& stream)
00046 {
00047   for(int i = 0; i < size; ++i)
00048     readChar(*((char*&) p)++,stream);
00049 }
00050 
00051 bool InText::isWhitespace()
00052 {
00053   return theChar == ' ' || theChar == '\n' || theChar == '\r' || theChar == '\t';
00054 }
00055 
00056 void InText::skipWhitespace(PhysicalInStream& stream)
00057 {
00058   while(!isEof(stream) && isWhitespace())
00059     nextChar(stream);
00060 }
00061 
00062 void InConfig::create(const char* sectionName, PhysicalInStream& stream)
00063 {
00064   if(stream.exists() && sectionName) 
00065   {
00066     char fileEntry[200];
00067     char section[200];
00068     
00069     ASSERT(strlen(sectionName) + 2 < sizeof(section));
00070     strcpy(section,"[");
00071     strcat(section,sectionName);
00072     strcat(section,"]");
00073     
00074     while(!isEof(stream)) 
00075     {
00076       readString(fileEntry,stream);
00077       if(!strcmp(fileEntry,section)) 
00078         break;
00079     }
00080     readSection = true;
00081   }
00082 }
00083 
00084 bool InConfig::isWhitespace()
00085 {
00086   return theChar == '/' || theChar == '#' || InText::isWhitespace();
00087 }
00088 
00089 void InConfig::skipWhitespace(PhysicalInStream& stream)
00090 {
00091   while(!isEof(stream) && isWhitespace())
00092   {
00093     while(!isEof(stream) && InText::isWhitespace())
00094       nextChar(stream);
00095     if(!isEof(stream))
00096       if(theChar == '/')
00097       {
00098         nextChar(stream);
00099         if(theChar == '/')
00100           skipLine(stream);
00101         else if(theChar == '*')
00102           skipComment(stream);
00103         else
00104           ASSERT(false); // "/" used in stream
00105       }
00106       else if(theChar == '#')
00107         skipLine(stream);
00108   }
00109 }
00110 
00111 void InConfig::nextChar(PhysicalInStream& stream) 
00112 {
00113   InText::nextChar(stream);
00114   if (readSection && theChar == '[')
00115     while (!isEof(stream)) 
00116       InText::nextChar(stream);
00117 }
00118 
00119 void InConfig::skipLine(PhysicalInStream& stream)
00120 {
00121   while(!isEof(stream) && theChar != '\n')
00122     nextChar(stream);
00123   if(!isEof(stream))
00124     nextChar(stream);
00125 }
00126 
00127 void InConfig::skipComment(PhysicalInStream& stream)
00128 {
00129   while(!isEof(stream) && theChar != '/')
00130   {
00131     while(!isEof(stream) && theChar != '*')
00132       nextChar(stream);
00133     if(!isEof(stream))
00134       nextChar(stream);
00135   }
00136   if(!isEof(stream))
00137     nextChar(stream);
00138 }
00139 
00140 void InMemory::readFromStream(void* p, int size)
00141 {
00142   if (memory!=0) 
00143   { 
00144     memcpy(p,memory,size); 
00145     memory += size; 
00146   }
00147 }
00148 
00149 
00150 /*
00151 * Change Log:
00152 *
00153 * $Log: InStreams.cpp,v $
00154 * Revision 1.1.1.1  2004/05/22 17:37:38  cvsadm
00155 * created new repository GT2004_WM
00156 *
00157 * Revision 1.2  2003/12/30 20:12:04  roefer
00158 * Image size is now 208 x 160. Smaller images are placed in the upper left corner
00159 *
00160 * Revision 1.1  2003/10/07 10:13:24  cvsadm
00161 * Created GT2004 (M.J.)
00162 *
00163 * Revision 1.1.1.1  2003/07/02 09:40:29  cvsadm
00164 * created new repository for the competitions in Padova from the 
00165 * tamara CVS (Tuesday 2:00 pm)
00166 *
00167 * removed unused solutions
00168 *
00169 * Revision 1.3  2002/10/11 21:21:16  roefer
00170 * eof() handling in text input corrected
00171 *
00172 * Revision 1.2  2002/09/24 18:41:58  risler
00173 * human readable solutionrequest streaming operator
00174 * default module solutions read from modules.cfg
00175 *
00176 * Revision 1.1  2002/09/10 15:53:59  cvsadm
00177 * Created new project GT2003 (M.L.)
00178 * - Cleaned up the /Src/DataTypes directory
00179 * - Removed challenge related source code
00180 * - Removed processing of incoming audio data
00181 * - Renamed AcousticMessage to SoundRequest
00182 *
00183 * Revision 1.6  2002/08/29 13:48:21  dueffert
00184 * includes in correct case, system includes in <>
00185 *
00186 * Revision 1.5  2002/08/22 14:41:04  risler
00187 * added some doxygen comments
00188 *
00189 * Revision 1.4  2002/08/04 17:53:18  roefer
00190 * SimGT2002 connection to physical robots added
00191 *
00192 * Revision 1.3  2002/07/28 21:24:20  roefer
00193 * EOF-handling improved
00194 *
00195 * Revision 1.2  2002/07/23 16:40:13  roefer
00196 * Router and SimGT2002 adapted to new message queue and streams
00197 *
00198 * Revision 1.1  2002/07/23 13:46:43  loetzsch
00199 * - new streaming classes
00200 *
00201 */

Generated on Thu Sep 23 19:57:41 2004 for GT2004 by doxygen 1.3.6