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

Tools/MessageQueue/InMessage.cpp

Go to the documentation of this file.
00001 /**
00002 * @file InMessage.cpp
00003 *
00004 * Implementation of class InMessageQueue, InBinaryMessage, InTextMessage,
00005 * InConfigMessage and InMessage.
00006 *
00007 * @author Martin Lötzsch
00008 */
00009 
00010 #include "InMessage.h"
00011 
00012 InMessageQueue::InMessageQueue() 
00013 : queue(0) 
00014 {
00015 }
00016 
00017 bool InMessageQueue::exists() const 
00018 { 
00019   return true; 
00020 }
00021 
00022 bool InMessageQueue::getEof() const 
00023 { 
00024   return (queue != 0 ? queue->eof() : false); 
00025 }
00026 
00027 void InMessageQueue::open(MessageQueueBase* q) 
00028 { 
00029   if (queue == 0) queue = q; 
00030 }
00031 
00032 void InMessageQueue::readFromStream(void* p,int size) 
00033 { 
00034   if (queue != 0) queue->read(p,size); 
00035 }
00036 
00037 InBinaryMessage::InBinaryMessage(MessageQueueBase* q) 
00038 { 
00039   open(q); 
00040 }
00041 
00042 InTextMessage::InTextMessage(MessageQueueBase* q) 
00043 { 
00044   open(q); 
00045 }
00046 
00047 void InTextMessage::readAll(char* buf)
00048 {
00049   while(!getEof())
00050   {
00051     nextChar(*this);
00052     if (theChar != ' ') 
00053     {
00054       if(theChar == '\\') nextChar(*this);
00055       *buf++ = theChar;
00056     }    
00057   }
00058   *buf = 0;
00059 }
00060 
00061 InConfigMessage::InConfigMessage(MessageQueueBase* q) 
00062 { 
00063   open(q); 
00064 }
00065 
00066 InMessage::InMessage(MessageQueueBase& queue) 
00067 : queue(queue), bin(&queue), text(&queue), config(&queue) 
00068 {
00069 }
00070 
00071 unsigned long InMessage::getTimeStamp() const
00072 { 
00073   return queue.getTimeStamp(); 
00074 }
00075 
00076 MessageID InMessage::getMessageID() const
00077 { 
00078   return queue.getMessageID(); 
00079 }
00080 
00081 int InMessage::getMessageSize() const
00082 { 
00083   return queue.getMessageSize(); 
00084 }
00085   
00086 Player::teamColor InMessage::getTeamColor() const
00087 {
00088   return queue.getTeamColor();
00089 }
00090 
00091 Player::playerNumber InMessage::getPlayerNumber() const
00092 {
00093   return queue.getPlayerNumber();
00094 }
00095 
00096 int InMessage::getRobotNumber() const
00097 {
00098   if (queue.getPlayerNumber()==Player::undefinedPlayerNumber) return 8;
00099   if (queue.getTeamColor()==Player::undefinedTeamColor) return 8;
00100   return (4*queue.getTeamColor()+queue.getPlayerNumber());
00101 }
00102 bool InMessage::getMessageWasSentFromAPhysicalRobot() const
00103 {
00104   return queue.getMessageWasSentFromAPhysicalRobot();
00105 }
00106 
00107 void InMessage::resetReadPosition() 
00108 { 
00109   queue.resetReadPosition(); 
00110   config.reset();
00111   text.reset();
00112 }
00113 
00114 const char* InMessage::getData() const
00115 {
00116   return queue.getData();
00117 }
00118 
00119 /*
00120 * Change Log:
00121 *
00122 * $Log: InMessage.cpp,v $
00123 * Revision 1.1.1.1  2004/05/22 17:37:15  cvsadm
00124 * created new repository GT2004_WM
00125 *
00126 * Revision 1.3  2003/12/06 23:39:07  loetzsch
00127 * added getRobotNumber()
00128 *
00129 * Revision 1.2  2003/12/06 23:23:55  loetzsch
00130 * messages in a MessageQueue now contain
00131 * - the team color of the robot which sent the message
00132 * - the player number of the robot which sent the message
00133 * - if the message was sent from a physical robot or not
00134 *
00135 * Revision 1.1  2003/10/07 10:13:24  cvsadm
00136 * Created GT2004 (M.J.)
00137 *
00138 * Revision 1.1.1.1  2003/07/02 09:40:28  cvsadm
00139 * created new repository for the competitions in Padova from the 
00140 * tamara CVS (Tuesday 2:00 pm)
00141 *
00142 * removed unused solutions
00143 *
00144 * Revision 1.2  2003/01/26 19:36:23  loetzsch
00145 * config and text now are also reset in resetReadReadposition()
00146 *
00147 * Revision 1.1  2002/09/10 15:53:59  cvsadm
00148 * Created new project GT2003 (M.L.)
00149 * - Cleaned up the /Src/DataTypes directory
00150 * - Removed challenge related source code
00151 * - Removed processing of incoming audio data
00152 * - Renamed AcousticMessage to SoundRequest
00153 *
00154 * Revision 1.2  2002/08/30 14:37:21  dueffert
00155 * removed unused includes
00156 *
00157 * Revision 1.1  2002/07/23 13:47:14  loetzsch
00158 * - new streaming classes
00159 * - new debug message handling
00160 * - exchanged StaticQueue by MessageQueue
00161 *
00162 */

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