OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4PacketList Class Reference

#include <C4PacketBase.h>

Inheritance diagram for C4PacketList:
[legend]
Collaboration diagram for C4PacketList:
[legend]

Public Member Functions

 C4PacketList ()
 
 C4PacketList (const C4PacketList &List2)
 
virtual ~C4PacketList ()
 
C4IDPacketfirstPkt () const
 
C4IDPacketnextPkt (C4IDPacket *pPkt) const
 
int32_t getPktCnt () const
 
void Add (C4IDPacket *pPkt)
 
void AddHead (C4IDPacket *pPkt)
 
void Add (C4PacketType eType, C4PacketBase *pPkt)
 
void AddHead (C4PacketType eType, C4PacketBase *pPkt)
 
void Take (C4PacketList &List)
 
void Append (const C4PacketList &List)
 
void Clear ()
 
void Remove (C4IDPacket *pPkt)
 
void Delete (C4IDPacket *pPkt)
 
virtual void CompileFunc (StdCompiler *pComp)
 
C4NetIOPacket pack (const C4NetIO::addr_t &addr=C4NetIO::addr_t()) const
 
C4NetIOPacket pack (uint8_t cStatus, const C4NetIO::addr_t &addr=C4NetIO::addr_t()) const
 
void unpack (const C4NetIOPacket &Pkt, char *pStatus=nullptr)
 

Protected Attributes

C4IDPacketpFirst
 
C4IDPacketpLast
 

Detailed Description

Definition at line 266 of file C4PacketBase.h.

Constructor & Destructor Documentation

C4PacketList::C4PacketList ( )

Definition at line 271 of file C4Packet2.cpp.

272  : pFirst(nullptr), pLast(nullptr)
273 {
274 
275 }
C4IDPacket * pFirst
Definition: C4PacketBase.h:274
C4IDPacket * pLast
Definition: C4PacketBase.h:274
C4PacketList::C4PacketList ( const C4PacketList List2)

Definition at line 277 of file C4Packet2.cpp.

References Append().

278  : C4PacketBase(List2),
279  pFirst(nullptr), pLast(nullptr)
280 {
281  Append(List2);
282 }
C4IDPacket * pFirst
Definition: C4PacketBase.h:274
C4IDPacket * pLast
Definition: C4PacketBase.h:274
void Append(const C4PacketList &List)
Definition: C4Packet2.cpp:329

Here is the call graph for this function:

C4PacketList::~C4PacketList ( )
virtual

Definition at line 284 of file C4Packet2.cpp.

References Clear().

285 {
286  Clear();
287 }
void Clear()
Definition: C4Packet2.cpp:335

Here is the call graph for this function:

Member Function Documentation

void C4PacketList::Add ( C4IDPacket pPkt)

Definition at line 297 of file C4Packet2.cpp.

References pFirst, pLast, and C4IDPacket::pNext.

Referenced by C4Control::Add(), Add(), Append(), CompileFunc(), and C4Playback::ExecuteControl().

298 {
299  assert(!pPkt->pNext);
300  (pLast ? pLast->pNext : pFirst) = pPkt;
301  pLast = pPkt;
302 }
C4IDPacket * pNext
Definition: C4PacketBase.h:251
C4IDPacket * pFirst
Definition: C4PacketBase.h:274
C4IDPacket * pLast
Definition: C4PacketBase.h:274

Here is the caller graph for this function:

void C4PacketList::Add ( C4PacketType  eType,
C4PacketBase pPkt 
)

Definition at line 312 of file C4Packet2.cpp.

References Add().

313 {
314  Add(new C4IDPacket(eType, pPkt));
315 }
void Add(C4IDPacket *pPkt)
Definition: C4Packet2.cpp:297

Here is the call graph for this function:

void C4PacketList::AddHead ( C4IDPacket pPkt)

Definition at line 304 of file C4Packet2.cpp.

References pFirst, pLast, and C4IDPacket::pNext.

Referenced by C4Control::AddHead(), and AddHead().

305 {
306  assert(!pPkt->pNext);
307  pPkt->pNext = pFirst;
308  pFirst = pPkt;
309  if (!pLast) pLast = pPkt;
310 }
C4IDPacket * pNext
Definition: C4PacketBase.h:251
C4IDPacket * pFirst
Definition: C4PacketBase.h:274
C4IDPacket * pLast
Definition: C4PacketBase.h:274

Here is the caller graph for this function:

void C4PacketList::AddHead ( C4PacketType  eType,
C4PacketBase pPkt 
)

Definition at line 317 of file C4Packet2.cpp.

References AddHead().

318 {
319  AddHead(new C4IDPacket(eType, pPkt));
320 }
void AddHead(C4IDPacket *pPkt)
Definition: C4Packet2.cpp:304

Here is the call graph for this function:

void C4PacketList::Append ( const C4PacketList List)

Definition at line 329 of file C4Packet2.cpp.

References Add(), firstPkt(), and nextPkt().

Referenced by C4Control::Append(), C4PacketList(), and C4Control::Copy().

330 {
331  for (C4IDPacket *pPkt = List.firstPkt(); pPkt; pPkt = List.nextPkt(pPkt))
332  Add(new C4IDPacket(*pPkt));
333 }
void Add(C4IDPacket *pPkt)
Definition: C4Packet2.cpp:297
C4IDPacket * nextPkt(C4IDPacket *pPkt) const
Definition: C4PacketBase.h:278
C4IDPacket * firstPkt() const
Definition: C4PacketBase.h:277

Here is the call graph for this function:

Here is the caller graph for this function:

void C4PacketList::Clear ( )

Definition at line 335 of file C4Packet2.cpp.

References Delete(), and pFirst.

Referenced by C4Control::Clear(), C4Playback::ExecuteControl(), and ~C4PacketList().

336 {
337  while (pFirst)
338  Delete(pFirst);
339 }
C4IDPacket * pFirst
Definition: C4PacketBase.h:274
void Delete(C4IDPacket *pPkt)
Definition: C4Packet2.cpp:362

Here is the call graph for this function:

Here is the caller graph for this function:

void C4PacketList::CompileFunc ( StdCompiler pComp)
virtual

Implements C4PacketBase.

Definition at line 368 of file C4Packet2.cpp.

References Add(), C4IDPacket::getPkt(), StdCompiler::hasNaming(), StdCompiler::isDeserializer(), mkNamingAdapt(), StdCompiler::Name(), StdCompiler::NameEnd(), pFirst, C4IDPacket::pNext, and StdCompiler::Value().

369 {
370  // unpack packets
371  if (pComp->isDeserializer())
372  {
373  // Read until no further sections available
374  while (pComp->Name("IDPacket"))
375  {
376  // Read the packet
377  C4IDPacket *pPkt = new C4IDPacket();
378  try
379  {
380  pComp->Value(*pPkt);
381  pComp->NameEnd();
382  }
383  catch (...)
384  {
385  delete pPkt;
386  throw;
387  }
388  // Terminator?
389  if (!pPkt->getPkt()) { delete pPkt; break; }
390  // Add to list
391  Add(pPkt);
392  }
393  pComp->NameEnd();
394  }
395  else
396  {
397  // Write all packets
398  for (C4IDPacket *pPkt = pFirst; pPkt; pPkt = pPkt->pNext)
399  pComp->Value(mkNamingAdapt(*pPkt, "IDPacket"));
400  // Terminate, if no naming is available
401  if (!pComp->hasNaming())
402  {
403  C4IDPacket Pkt;
404  pComp->Value(mkNamingAdapt(Pkt, "IDPacket"));
405  }
406  }
407 }
virtual bool hasNaming()
Definition: StdCompiler.h:68
C4IDPacket * pNext
Definition: C4PacketBase.h:251
void Add(C4IDPacket *pPkt)
Definition: C4Packet2.cpp:297
C4IDPacket * pFirst
Definition: C4PacketBase.h:274
virtual bool Name(const char *szName)
Definition: StdCompiler.h:87
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:93
void Value(const T &rStruct)
Definition: StdCompiler.h:171
virtual bool isDeserializer()
Definition: StdCompiler.h:63
C4PacketBase * getPkt() const
Definition: C4PacketBase.h:255
virtual void NameEnd(bool fBreak=false)
Definition: StdCompiler.h:88

Here is the call graph for this function:

void C4PacketList::Delete ( C4IDPacket pPkt)

Definition at line 362 of file C4Packet2.cpp.

References Remove().

Referenced by C4Playback::Check(), Clear(), C4Playback::Clear(), and C4Control::Delete().

363 {
364  Remove(pPkt);
365  delete pPkt;
366 }
void Remove(C4IDPacket *pPkt)
Definition: C4Packet2.cpp:341

Here is the call graph for this function:

Here is the caller graph for this function:

C4IDPacket* C4PacketList::firstPkt ( ) const
inline

Definition at line 277 of file C4PacketBase.h.

References pFirst.

Referenced by Append(), C4Playback::Check(), C4Playback::Clear(), C4Playback::ExecuteControl(), and C4Control::firstPkt().

277 { return pFirst; }
C4IDPacket * pFirst
Definition: C4PacketBase.h:274

Here is the caller graph for this function:

int32_t C4PacketList::getPktCnt ( ) const

Definition at line 289 of file C4Packet2.cpp.

References iCnt, pFirst, and C4IDPacket::pNext.

290 {
291  int32_t iCnt = 0;
292  for (C4IDPacket *pPkt = pFirst; pPkt; pPkt = pPkt->pNext)
293  iCnt++;
294  return iCnt;
295 }
C4IDPacket * pNext
Definition: C4PacketBase.h:251
C4IDPacket * pFirst
Definition: C4PacketBase.h:274
int iCnt
Definition: TstC4NetIO.cpp:35
C4IDPacket* C4PacketList::nextPkt ( C4IDPacket pPkt) const
inline

Definition at line 278 of file C4PacketBase.h.

References C4IDPacket::pNext.

Referenced by Append(), and C4Control::nextPkt().

278 { return pPkt->pNext; }
C4IDPacket * pNext
Definition: C4PacketBase.h:251

Here is the caller graph for this function:

C4NetIOPacket C4PacketBase::pack ( const C4NetIO::addr_t addr = C4NetIO::addr_t()) const
inherited

Definition at line 156 of file C4Packet2.cpp.

Referenced by MkC4NetIOPacket().

157 {
158  return C4NetIOPacket(DecompileToBuf<StdCompilerBinWrite>(*this), addr);
159 }

Here is the caller graph for this function:

C4NetIOPacket C4PacketBase::pack ( uint8_t  cStatus,
const C4NetIO::addr_t addr = C4NetIO::addr_t() 
) const
inherited

Definition at line 161 of file C4Packet2.cpp.

References mkDecompileAdapt(), and mkInsertAdapt().

162 {
163  return C4NetIOPacket(DecompileToBuf<StdCompilerBinWrite>(mkInsertAdapt(mkDecompileAdapt(*this), cStatus)), addr);
164 }
StdDecompileAdapt< T > mkDecompileAdapt(const T &rValue)
Definition: StdAdaptors.h:154
StdInsertAdapt< T, I > mkInsertAdapt(T &&rObj, I &&rIns, bool fBefore=true)
Definition: StdAdaptors.h:435

Here is the call graph for this function:

void C4PacketList::Remove ( C4IDPacket pPkt)

Definition at line 341 of file C4Packet2.cpp.

References pFirst, pLast, and C4IDPacket::pNext.

Referenced by Delete(), and C4Control::Remove().

342 {
343  if (pPkt == pFirst)
344  {
345  pFirst = pPkt->pNext;
346  if (pPkt == pLast)
347  pLast = nullptr;
348  }
349  else
350  {
351  C4IDPacket *pPrev;
352  for (pPrev = pFirst; pPrev && pPrev->pNext != pPkt; pPrev = pPrev->pNext) {}
353  if (pPrev)
354  {
355  pPrev->pNext = pPkt->pNext;
356  if (pPkt == pLast)
357  pLast = pPrev;
358  }
359  }
360 }
C4IDPacket * pNext
Definition: C4PacketBase.h:251
C4IDPacket * pFirst
Definition: C4PacketBase.h:274
C4IDPacket * pLast
Definition: C4PacketBase.h:274

Here is the caller graph for this function:

void C4PacketList::Take ( C4PacketList List)

Definition at line 322 of file C4Packet2.cpp.

References pFirst, and pLast.

Referenced by C4Control::Take().

323 {
324  pFirst = List.pFirst;
325  pLast = List.pLast;
326  List.pFirst = List.pLast = nullptr;
327 }
C4IDPacket * pFirst
Definition: C4PacketBase.h:274
C4IDPacket * pLast
Definition: C4PacketBase.h:274

Here is the caller graph for this function:

void C4PacketBase::unpack ( const C4NetIOPacket Pkt,
char *  pStatus = nullptr 
)
inherited

Definition at line 166 of file C4Packet2.cpp.

References C4NetIOPacket::getPBuf(), C4NetIOPacket::getRef(), and C4NetIOPacket::getStatus().

Referenced by C4IDPacket::C4IDPacket(), and C4Network2IO::HandlePacket().

167 {
168  if (pStatus) *pStatus = Pkt.getStatus();
169  CompileFromBuf<StdCompilerBinRead>(*this, pStatus ? Pkt.getPBuf() : Pkt.getRef());
170 }
StdBuf getPBuf() const
Definition: C4NetIO.h:321
C4NetIOPacket getRef() const
Definition: C4NetIO.h:324
uint8_t getStatus() const
Definition: C4NetIO.h:318

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

C4IDPacket* C4PacketList::pFirst
protected

Definition at line 274 of file C4PacketBase.h.

Referenced by Add(), AddHead(), Clear(), CompileFunc(), firstPkt(), getPktCnt(), Remove(), and Take().

C4IDPacket * C4PacketList::pLast
protected

Definition at line 274 of file C4PacketBase.h.

Referenced by Add(), AddHead(), Remove(), and Take().


The documentation for this class was generated from the following files: