MFMv2.0.10
Movable Feast Machine Simulator 2.0.10
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Packet.h
Go to the documentation of this file.
1 /* -*- mode:C++ -*-
2  Packet.h Basic type for inter-tile communication
3  Copyright (C) 2014 The Regents of the University of New Mexico. All rights reserved.
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
18  USA
19 */
20 
27 #ifndef PACKET_H
28 #define PACKET_H
29 
30 #include "Dirs.h"
31 #include "itype.h"
32 
33 namespace MFM
34 {
35 
40  typedef enum
41  {
46  PACKET_WRITE = 0,
47 
53  PACKET_EVENT_COMPLETE,
54 
62  PACKET_EVENT_ACKNOWLEDGE
63 
64  }PacketType;
65 
70  template <class T>
71  class Packet
72  {
73  private:
74 
79  u8 m_type;
80 
84  u8 m_toNeighbor;
85 
89  u8 m_generation;
90 
94  SSPoint m_edgeLoc;
95 
99  T m_atom;
100 
101  public:
102 
106  Packet(PacketType type, u8 generation) :
107  m_type(type),
108  m_toNeighbor(Dirs::DIR_COUNT), // Init invalid
109  m_generation(generation)
110  { }
111 
112  const char* GetTypeString()
113  {
114  switch(m_type)
115  {
116  case PACKET_WRITE: return "Write";
117  case PACKET_EVENT_COMPLETE: return "Event Complete";
118  case PACKET_EVENT_ACKNOWLEDGE: return "Event Acknowledge";
119  }
120  return "INVALID";
121  }
122 
128  PacketType GetType()
129  {
130  return (PacketType) m_type;
131  }
132 
138  void SetType(PacketType type)
139  {
140  m_type = type;
141  }
142 
149  void SetAtom(const T& atom)
150  {
151  m_atom = atom;
152  }
153 
159  void SetReceivingNeighbor(Dir dir)
160  {
161  m_toNeighbor = dir;
162  }
163 
170  {
171  return m_toNeighbor;
172  }
173 
179  T& GetAtom()
180  {
181  return m_atom;
182  }
183 
189  void SetLocation(const SPoint& fromPt)
190  {
191  m_edgeLoc = SSPoint(fromPt.GetX(), fromPt.GetY());
192  }
193 
199  const SPoint GetLocation() const
200  {
201  return SPoint(m_edgeLoc.GetX(), m_edgeLoc.GetY());
202  }
203 
209  const u8 GetGeneration() const
210  {
211  return m_generation;
212  }
213 
219  void SetGeneration(u8 generation)
220  {
221  m_generation = generation;
222  }
223 
231  bool IsObsolete(u8 ourGeneration) const
232  {
233  return ((u8) (m_generation - ourGeneration)) >= U8_MAX / 2;
234  }
235  };
236 } /* namespace MFM */
237 
238 #endif /*PACKET_H*/
#define U8_MAX
Definition: itype.h:91
u32 GetReceivingNeighbor()
Definition: Packet.h:169
Definition: Dirs.h:38
PacketType GetType()
Definition: Packet.h:128
void SetReceivingNeighbor(Dir dir)
Definition: Packet.h:159
void SetGeneration(u8 generation)
Definition: Packet.h:219
T GetY() const
Definition: Point.tcc:40
T & GetAtom()
Definition: Packet.h:179
void SetAtom(const T &atom)
Definition: Packet.h:149
Definition: Packet.h:71
bool IsObsolete(u8 ourGeneration) const
Definition: Packet.h:231
void SetType(PacketType type)
Definition: Packet.h:138
Packet(PacketType type, u8 generation)
Definition: Packet.h:106
void SetLocation(const SPoint &fromPt)
Definition: Packet.h:189
const u8 GetGeneration() const
Definition: Packet.h:209
const SPoint GetLocation() const
Definition: Packet.h:199
T GetX() const
Definition: Point.tcc:34