Packet.h

Go to the documentation of this file.
00001 /* -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 5 -*- */
00002 
00003 /*
00004  * Combination of a first person action and a real time strategy battle game.
00005  */
00006 
00007 /*
00008  * Packet.h
00009  * MetalWarriors
00010  * $Revision: 1.3 $
00011  *
00012  * Copyright (c) 2003-2005 Daniel Aarno and Erik Ytterberg
00013  * All rights reserved.
00014  *
00015  *     This program is free software; you can redistribute it and/or modify
00016  *     it under the terms of the GNU General Public License as published by
00017  *     the Free Software Foundation; either version 2 of the License, or
00018  *     (at your option) any later version.
00019  *
00020  *     This program is distributed in the hope that it will be useful,
00021  *     but WITHOUT ANY WARRANTY; without even the implied warranty of
00022  *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023  *     GNU General Public License for more details.
00024  *
00025  *     You should have received a copy of the GNU General Public License
00026  *     along with this program; if not, write to the Free Software
00027  *     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00028  */
00029 
00030 #include <string>
00031 #include <stdio.h>
00032 
00033 #ifndef _PACKET_
00034 #define _PACKET_
00035 
00036 class Network;
00037 class PacketSender;
00038 
00039 class Packet {
00040      friend class Network;
00041      friend class PacketSender;
00042 public:
00043      typedef long uri_t;
00044      static const char* PACKET_EMPTY_STR;
00045      
00046 protected:
00047      std::string msg;
00048      std::string type;
00049      
00050 public:
00051      Packet(const std::string &type = PACKET_EMPTY_STR);
00052      ~Packet() {}
00053      
00054      void pushString(const std::string &str);
00055      void pushChar(char c);
00056      void pushShort(short s);
00057      void pushLong(long l);
00058      void pushFloat(float f);
00059      void pushDouble(double d);
00060      void pushURI(const uri_t &uri);
00061 
00062      std::string popFrontString();
00063      char popFrontChar();
00064      short popFrontShort();
00065      long popFrontLong();
00066      float popFrontFloat();
00067      double popFrontDouble();
00068      uri_t popFrontURI();
00069      
00070      const std::string& getType() const { return type; }
00071      const std::string& getMessage() const { return msg; }
00072      
00073      void dumpToFile(FILE *fp = stderr) const;
00074 
00075      bool isEmpty() { return type == PACKET_EMPTY_STR; }
00076      
00077 protected:
00078      static Packet String2Packet(const std::string &s);
00079 };
00080  
00081 #endif

Generated on Sun Mar 11 15:33:23 2007 for MetalWarriors by  doxygen 1.4.7