PacketHistory.hh

00001 /*
00002 ** TowBowlTactics, a turn-based strategy football game.
00003 **
00004 ** Copyright (C) 2010-2010 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 PACKETHISTORY_HH_
00018 # define PACKETHISTORY_HH_
00019 
00020 # include "Packet.hh"
00021 
00029 class PacketHistory
00030 {
00031 public:
00032   PacketHistory();
00033   ~PacketHistory();
00034 
00037   void addCopy(const Packet* pkt);
00038 
00042   const Packet* at(unsigned int i) const;
00043 
00046   unsigned int size() const;
00047 
00048 private:
00049   std::vector<Packet*> packets_;
00050 };
00051 
00052 inline PacketHistory::PacketHistory()
00053 {
00054 }
00055 
00056 inline PacketHistory::~PacketHistory()
00057 {
00058   while (!packets_.empty())
00059     {
00060       free(packets_.back());
00061       packets_.pop_back();
00062     }
00063 }
00064 
00065 inline void PacketHistory::addCopy(const Packet* pkt)
00066 {
00067   Packet* pkt_copy = static_cast<Packet*>(malloc(pkt->data_size));
00068   memcpy(pkt_copy, pkt, pkt->data_size);
00069   packets_.push_back(pkt_copy);
00070 }
00071 
00072 inline const Packet* PacketHistory::at(unsigned int index) const
00073 {
00074   return packets_.at(index);
00075 }
00076 
00077 inline unsigned int PacketHistory::size() const
00078 {
00079   return packets_.size();
00080 }
00081 
00082 #endif /* !PACKETHISTORY_HH_ */
Generated on Mon Apr 5 21:17:12 2010 for Stechec/TBT by  doxygen 1.6.3