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

Message.cpp

Go to the documentation of this file.
00001 //////////////////////////////////////////////////////////////////////////////////////////////////
00002 /*! \file Message.cpp
00003 *  \brief Implementation of the Message class.
00004 *  \author $Author: rsharo $
00005 *  \version $Revision: 1.3 $
00006 *  \date    $Date: 2003/11/01 21:00:13 $
00007 *//////////////////////////////////////////////////////////////////////////////////////////////////
00008 /*  
00009 */
00010 //////////////////////////////////////////////////////////////////////////////////////////////////
00011 
00012 #include "Message.h"
00013 #include <sstream>
00014 #include <iostream>
00015 
00016 string Message::Serialize() const
00017 {
00018     stringstream outMsgStream;
00019     string outMsg;
00020     outMsgStream << m_Destination;
00021     outMsgStream << ":";
00022     outMsgStream << m_Sender;
00023     outMsgStream << "_[";
00024     outMsgStream << m_Command;
00025     outMsgStream << ":";
00026     for(unsigned int ii = 0; ii < m_Parameters.size(); ++ii)
00027     {
00028         outMsgStream << m_Parameters[ii];
00029         if(ii != m_Parameters.size()-1)
00030             outMsgStream << ",";
00031     }
00032     outMsgStream << "]";
00033     outMsgStream >> outMsg;
00034     return outMsg;  
00035 }
00036 
00037 void Message::Parse(string _incomingMsg)
00038 {
00039     int finder = 0; 
00040     int efinder = 0;
00041     int finderLength;
00042     stringstream inMsgStream;
00043     efinder = _incomingMsg.find(':',finder);
00044     finderLength = efinder - finder;                                    // "how long is it?"
00045     m_Destination = _incomingMsg.substr(finder, finderLength);
00046     
00047     finder = efinder + 1;
00048     efinder = _incomingMsg.find('_',finder);
00049     finderLength = efinder - finder;                                    // "how long is it?"
00050     m_Sender = _incomingMsg.substr(finder, finderLength);
00051     
00052     finder = efinder + 2;
00053     efinder = _incomingMsg.find(':',finder);
00054     finderLength = efinder - finder;                                    // "how long is it?"
00055     m_Command = _incomingMsg.substr(finder, finderLength);
00056     
00057     while(1)
00058     {
00059         finder = efinder + 1;
00060         efinder = _incomingMsg.find(',',finder);
00061         finderLength = efinder - finder;                                        // "how long is it?"
00062         m_Parameters.push_back(atoi((_incomingMsg.substr(finder, finderLength)).c_str()));
00063         
00064         if(efinder < 0)
00065             return;
00066     }    
00067     return;        
00068 }
00069 // Do not change the comments below - they will be added automatically by CVS
00070 /*****************************************************************************
00071 *       $Log: Message.cpp,v $
00072 *       Revision 1.3  2003/11/01 21:00:13  rsharo
00073 *       changed "Time.h" includes to "utils/Time.h" includes. Also eliminated excess compile warnings.
00074 *       
00075 *       Revision 1.2  2003/06/13 15:34:30  nicmcp
00076 *       Changed the function name GetMessage() to Serialize() to match the Message.h file
00077 *       
00078 *       Revision 1.1.1.1  2003/06/06 18:44:15  simpliciter
00079 *       Initial submission.
00080 *       
00081 *
00082 ******************************************************************************/

Generated on Wed Sep 5 12:54:22 2007 for DSACSS Operational Code by  doxygen 1.3.9.1