Packet.hh

00001 /*
00002 ** TowBowlTactics, an adaptation of the tabletop game Blood Bowl.
00003 **
00004 ** Copyright (C) 2006, 2007 The TBT Team.
00005 **
00006 ** This program is free software; you can redistribute it and/or
00007 ** modify it under the terms of the GNU General Public License
00008 ** as published by the Free Software Foundation; either version 2
00009 ** of the License, or (at your option) any later version.
00010 **
00011 ** The complete GNU General Public Licence Notice can be found as the
00012 ** `NOTICE' file in the root directory.
00013 **
00014 ** The TBT Team consists of people listed in the `AUTHORS' file.
00015 */
00016 
00017 #ifndef PACKET_HH_
00018 # define PACKET_HH_
00019 
00020 # include <sstream>
00021 
00028 struct Packet
00029 {
00031   unsigned      token;
00035   int           client_id;
00037   unsigned      data_size;
00038 
00039   Packet(int token = 0, int client_id = -1);
00040   friend std::ostream& operator<< (std::ostream& os, const Packet& pkt);
00041 };
00042 
00043 
00044 inline Packet::Packet(int token, int client_id)
00045   : token(token), client_id(client_id)
00046 {
00047   data_size = sizeof(*this);
00048 }
00049 
00050 inline std::ostream& operator<< (std::ostream& os, const Packet& pkt)
00051 {
00052   os << "*** Packet dump ***" << std::endl;
00053   os << "  - token : " << pkt.token << std::endl;
00054   os << "  - player_id : " << pkt.client_id << std::endl;
00055   os << "  - data_size : " << pkt.data_size << std::endl;
00056   return os;
00057 }
00058 
00061 
00066 void          stringToPacket(int* dst, const std::string& src, unsigned max_size);
00067 
00069 std::string   packetToString(const int* src);
00070 
00072 
00073 #endif /* !PACKET_HH_ */

Generated on Sat Jun 23 16:07:23 2007 for Stechec/TBT by  doxygen 1.4.7