Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

message.cpp

00001 /***************************************************************************
00002                         message.cpp  -  description
00003                             -------------------
00004     begin                : nov 29th 2005
00005     copyright            : (C) 2005-2006 by Duong-Khang NGUYEN
00006     email                : neoneurone @ users sourceforge net
00007     author               : Victor STINNER
00008     
00009     $Id: message.cpp 32 2006-08-06 18:59:25Z neoneurone $
00010  ***************************************************************************/
00011 
00012 /***************************************************************************
00013  *                                                                         *
00014  *   This program is free software; you can redistribute it and/or modify  *
00015  *   it under the terms of the GNU General Public License as published by  *
00016  *   the Free Software Foundation; either version 2 of the License, or     *
00017  *   any later version.                                                    *
00018  *                                                                         *
00019  ***************************************************************************/
00020 
00021 
00022 #include "message.h"
00023 #include "agent.h"
00024 
00025 #include <cassert>
00026 
00027 
00028    /*=====================================================================*/
00029 Message::Message():
00030 m_sender(NULL),
00031 m_type(MSG_UNDEFINED)
00032 {}
00033 
00034 
00035    /*=====================================================================*/
00036 Message::Message(Message_t type, Agent *sender):
00037 m_sender(sender),
00038 m_type(type)
00039 {}
00040 
00041 
00042    /*=====================================================================*/
00043 Message::Message_t Message::getType() const
00044 {
00045     return m_type;
00046 }
00047 
00048 
00049    /*=====================================================================*/
00050 Agent* Message::getSender() const
00051 {
00052     return m_sender;
00053 }
00054 
00055 
00056    /*=====================================================================*/
00057 Message&
00058 Message::setSender(Agent* sender)
00059 {
00060     m_sender = sender;
00061     return *this;
00062 }
00063 
00064 
00065    /*=====================================================================*/
00066 unsigned int Message::size() const
00067 {
00068     return arguments.size();
00069 }
00070 
00071 
00072    /*=====================================================================*/
00073 Message& Message::operator<< (int value)
00074 {
00075     arguments.push_back(Any(value)); return *this;
00076 }
00077 
00078 
00079    /*=====================================================================*/
00080 Message& Message::operator<< (unsigned int value)
00081 {
00082     arguments.push_back(Any(value)); return *this;
00083 }
00084 
00085 
00086    /*=====================================================================*/
00087 Message& Message::operator<< (double value)
00088 {
00089     arguments.push_back(Any(value)); return *this;
00090 }
00091 
00092 
00093    /*=====================================================================*/
00094 Message& Message::operator<< (const std::string &value)
00095 {
00096     arguments.push_back(Any(value)); return *this;
00097 }
00098 
00099 
00100    /*=====================================================================*/
00101 Any& Message::operator[] (unsigned int index)
00102 {
00103     return arguments.at(index);
00104 }
00105 
00106 
00107    /*=====================================================================*/
00108 const Any& Message::operator[] (unsigned int index) const
00109 {
00110     return arguments.at(index);
00111 }
00112 
00113 
00114    /*=====================================================================*/
00115 std::ostream& operator<< (std::ostream& os, const Message &msg)
00116 {
00117     std::vector<Any>::const_iterator
00118         it=msg.arguments.begin(),
00119         end=msg.arguments.end();
00120     bool separator=false;
00121     os << "Message <type=" << msg.getType() << ", args={";
00122     for (; it != end; ++it)
00123     {
00124         if (separator)
00125             os << ", ";
00126         else
00127             separator = true;
00128         os << *it;
00129     }
00130     os << "}>";
00131     return os;
00132 }
00133 
00134 
00135 
00136 
00137 
00138 
00139 
00140 
00141 
00142 
00143 
00144 
00145 
00146 
00147 
00148 
00149 
00150 
00151 
00152 
00153 
00154 
00155 
00156 
00157 
00158 
00159 
00160 
00161 
00162 
00163 
00164 
00165 
00166 

Generated on Sat Nov 11 10:21:10 2006 for OpenCity by  doxygen 1.4.2