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 }

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