OpenClonk
C4PacketList Class Reference

#include <C4PacketBase.h>

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

Public Member Functions

 C4PacketList ()
 
 C4PacketList (const C4PacketList &List2)
 
 ~C4PacketList () override
 
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)
 
void CompileFunc (StdCompiler *pComp) override
 
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 {nullptr}
 
C4IDPacketpLast {nullptr}
 

Detailed Description

Definition at line 271 of file C4PacketBase.h.

Constructor & Destructor Documentation

◆ C4PacketList() [1/2]

C4PacketList::C4PacketList ( )
default

◆ C4PacketList() [2/2]

C4PacketList::C4PacketList ( const C4PacketList List2)

Definition at line 263 of file C4Packet2.cpp.

264  : C4PacketBase(List2),
265  pFirst(nullptr), pLast(nullptr)
266 {
267  Append(List2);
268 }
C4IDPacket * pFirst
Definition: C4PacketBase.h:279
C4IDPacket * pLast
Definition: C4PacketBase.h:279
void Append(const C4PacketList &List)
Definition: C4Packet2.cpp:315

References Append().

Here is the call graph for this function:

◆ ~C4PacketList()

C4PacketList::~C4PacketList ( )
override

Definition at line 270 of file C4Packet2.cpp.

271 {
272  Clear();
273 }
void Clear()
Definition: C4Packet2.cpp:321

References Clear().

Here is the call graph for this function:

Member Function Documentation

◆ Add() [1/2]

void C4PacketList::Add ( C4IDPacket pPkt)

Definition at line 283 of file C4Packet2.cpp.

284 {
285  assert(!pPkt->pNext);
286  (pLast ? pLast->pNext : pFirst) = pPkt;
287  pLast = pPkt;
288 }
C4IDPacket * pNext
Definition: C4PacketBase.h:256

References pFirst, pLast, and C4IDPacket::pNext.

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

Here is the caller graph for this function:

◆ Add() [2/2]

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

Definition at line 298 of file C4Packet2.cpp.

299 {
300  Add(new C4IDPacket(eType, pPkt));
301 }
void Add(C4IDPacket *pPkt)
Definition: C4Packet2.cpp:283

References Add().

Here is the call graph for this function:

◆ AddHead() [1/2]

void C4PacketList::AddHead ( C4IDPacket pPkt)

Definition at line 290 of file C4Packet2.cpp.

291 {
292  assert(!pPkt->pNext);
293  pPkt->pNext = pFirst;
294  pFirst = pPkt;
295  if (!pLast) pLast = pPkt;
296 }

References pFirst, pLast, and C4IDPacket::pNext.

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

Here is the caller graph for this function:

◆ AddHead() [2/2]

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

Definition at line 303 of file C4Packet2.cpp.

304 {
305  AddHead(new C4IDPacket(eType, pPkt));
306 }
void AddHead(C4IDPacket *pPkt)
Definition: C4Packet2.cpp:290

References AddHead().

Here is the call graph for this function:

◆ Append()

void C4PacketList::Append ( const C4PacketList List)

Definition at line 315 of file C4Packet2.cpp.

316 {
317  for (C4IDPacket *pPkt = List.firstPkt(); pPkt; pPkt = List.nextPkt(pPkt))
318  Add(new C4IDPacket(*pPkt));
319 }
C4IDPacket * firstPkt() const
Definition: C4PacketBase.h:282
C4IDPacket * nextPkt(C4IDPacket *pPkt) const
Definition: C4PacketBase.h:283

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

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Clear()

void C4PacketList::Clear ( )

Definition at line 321 of file C4Packet2.cpp.

322 {
323  while (pFirst)
324  Delete(pFirst);
325 }
void Delete(C4IDPacket *pPkt)
Definition: C4Packet2.cpp:348

References Delete(), and pFirst.

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CompileFunc()

void C4PacketList::CompileFunc ( StdCompiler pComp)
overridevirtual

Implements C4PacketBase.

Definition at line 354 of file C4Packet2.cpp.

355 {
356  // unpack packets
357  if (pComp->isDeserializer())
358  {
359  // Read until no further sections available
360  while (pComp->Name("IDPacket"))
361  {
362  // Read the packet
363  C4IDPacket *pPkt = new C4IDPacket();
364  try
365  {
366  pComp->Value(*pPkt);
367  pComp->NameEnd();
368  }
369  catch (...)
370  {
371  delete pPkt;
372  throw;
373  }
374  // Terminator?
375  if (!pPkt->getPkt()) { delete pPkt; break; }
376  // Add to list
377  Add(pPkt);
378  }
379  pComp->NameEnd();
380  }
381  else
382  {
383  // Write all packets
384  for (C4IDPacket *pPkt = pFirst; pPkt; pPkt = pPkt->pNext)
385  pComp->Value(mkNamingAdapt(*pPkt, "IDPacket"));
386  // Terminate, if no naming is available
387  if (!pComp->hasNaming())
388  {
389  C4IDPacket Pkt;
390  pComp->Value(mkNamingAdapt(Pkt, "IDPacket"));
391  }
392  }
393 }
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:92
C4PacketBase * getPkt() const
Definition: C4PacketBase.h:260
void Value(const T &rStruct)
Definition: StdCompiler.h:161
virtual void NameEnd(bool fBreak=false)
Definition: StdCompiler.h:78
virtual bool isDeserializer()
Definition: StdCompiler.h:53
virtual bool Name(const char *szName)
Definition: StdCompiler.h:77
virtual bool hasNaming()
Definition: StdCompiler.h:58

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

Here is the call graph for this function:

◆ Delete()

void C4PacketList::Delete ( C4IDPacket pPkt)

Definition at line 348 of file C4Packet2.cpp.

349 {
350  Remove(pPkt);
351  delete pPkt;
352 }
void Remove(C4IDPacket *pPkt)
Definition: C4Packet2.cpp:327

References Remove().

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ firstPkt()

C4IDPacket* C4PacketList::firstPkt ( ) const
inline

Definition at line 282 of file C4PacketBase.h.

282 { return pFirst; }

References pFirst.

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

Here is the caller graph for this function:

◆ getPktCnt()

int32_t C4PacketList::getPktCnt ( ) const

Definition at line 275 of file C4Packet2.cpp.

276 {
277  int32_t iCnt = 0;
278  for (C4IDPacket *pPkt = pFirst; pPkt; pPkt = pPkt->pNext)
279  iCnt++;
280  return iCnt;
281 }
int iCnt
Definition: TstC4NetIO.cpp:32

References iCnt, pFirst, and C4IDPacket::pNext.

◆ nextPkt()

C4IDPacket* C4PacketList::nextPkt ( C4IDPacket pPkt) const
inline

Definition at line 283 of file C4PacketBase.h.

283 { return pPkt->pNext; }

References C4IDPacket::pNext.

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

Here is the caller graph for this function:

◆ pack() [1/2]

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

Definition at line 150 of file C4Packet2.cpp.

151 {
152  return C4NetIOPacket(DecompileToBuf<StdCompilerBinWrite>(*this), addr);
153 }

Referenced by MkC4NetIOPacket().

Here is the caller graph for this function:

◆ pack() [2/2]

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

Definition at line 155 of file C4Packet2.cpp.

156 {
157  return C4NetIOPacket(DecompileToBuf<StdCompilerBinWrite>(mkInsertAdapt(mkDecompileAdapt(*this), cStatus)), addr);
158 }
StdInsertAdapt< T, I > mkInsertAdapt(T &&rObj, I &&rIns, bool fBefore=true)
Definition: StdAdaptors.h:469
StdDecompileAdapt< T > mkDecompileAdapt(const T &rValue)
Definition: StdAdaptors.h:153

References mkDecompileAdapt(), and mkInsertAdapt().

Here is the call graph for this function:

◆ Remove()

void C4PacketList::Remove ( C4IDPacket pPkt)

Definition at line 327 of file C4Packet2.cpp.

328 {
329  if (pPkt == pFirst)
330  {
331  pFirst = pPkt->pNext;
332  if (pPkt == pLast)
333  pLast = nullptr;
334  }
335  else
336  {
337  C4IDPacket *pPrev;
338  for (pPrev = pFirst; pPrev && pPrev->pNext != pPkt; pPrev = pPrev->pNext) {}
339  if (pPrev)
340  {
341  pPrev->pNext = pPkt->pNext;
342  if (pPkt == pLast)
343  pLast = pPrev;
344  }
345  }
346 }

References pFirst, pLast, and C4IDPacket::pNext.

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

Here is the caller graph for this function:

◆ Take()

void C4PacketList::Take ( C4PacketList List)

Definition at line 308 of file C4Packet2.cpp.

309 {
310  pFirst = List.pFirst;
311  pLast = List.pLast;
312  List.pFirst = List.pLast = nullptr;
313 }

References pFirst, and pLast.

Referenced by C4Control::Take().

Here is the caller graph for this function:

◆ unpack()

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

Definition at line 160 of file C4Packet2.cpp.

161 {
162  if (pStatus) *pStatus = Pkt.getStatus();
163  CompileFromBuf<StdCompilerBinRead>(*this, pStatus ? Pkt.getPBuf() : Pkt.getRef());
164 }
uint8_t getStatus() const
Definition: C4NetIO.h:319
StdBuf getPBuf() const
Definition: C4NetIO.h:322
C4NetIOPacket getRef() const
Definition: C4NetIO.h:325

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

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

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ pFirst

C4IDPacket* C4PacketList::pFirst {nullptr}
protected

Definition at line 279 of file C4PacketBase.h.

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

◆ pLast

C4IDPacket * C4PacketList::pLast {nullptr}
protected

Definition at line 279 of file C4PacketBase.h.

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


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