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 269 of file C4PacketBase.h.

Constructor & Destructor Documentation

◆ C4PacketList() [1/2]

C4PacketList::C4PacketList ( )
default

Referenced by C4IDPacket::CompileFunc().

Here is the caller graph for this function:

◆ C4PacketList() [2/2]

C4PacketList::C4PacketList ( const C4PacketList List2)

Definition at line 260 of file C4Packet2.cpp.

References Append().

261  : C4PacketBase(List2),
262  pFirst(nullptr), pLast(nullptr)
263 {
264  Append(List2);
265 }
C4IDPacket * pFirst
Definition: C4PacketBase.h:277
C4IDPacket * pLast
Definition: C4PacketBase.h:277
void Append(const C4PacketList &List)
Definition: C4Packet2.cpp:312
Here is the call graph for this function:

◆ ~C4PacketList()

C4PacketList::~C4PacketList ( )
override

Definition at line 267 of file C4Packet2.cpp.

References Clear().

268 {
269  Clear();
270 }
void Clear()
Definition: C4Packet2.cpp:318
Here is the call graph for this function:

Member Function Documentation

◆ Add() [1/2]

void C4PacketList::Add ( C4IDPacket pPkt)

Definition at line 280 of file C4Packet2.cpp.

References pFirst, pLast, and C4IDPacket::pNext.

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

281 {
282  assert(!pPkt->pNext);
283  (pLast ? pLast->pNext : pFirst) = pPkt;
284  pLast = pPkt;
285 }
C4IDPacket * pNext
Definition: C4PacketBase.h:254
C4IDPacket * pFirst
Definition: C4PacketBase.h:277
C4IDPacket * pLast
Definition: C4PacketBase.h:277
Here is the caller graph for this function:

◆ Add() [2/2]

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

Definition at line 295 of file C4Packet2.cpp.

References Add().

296 {
297  Add(new C4IDPacket(eType, pPkt));
298 }
void Add(C4IDPacket *pPkt)
Definition: C4Packet2.cpp:280
Here is the call graph for this function:

◆ AddHead() [1/2]

void C4PacketList::AddHead ( C4IDPacket pPkt)

Definition at line 287 of file C4Packet2.cpp.

References pFirst, pLast, and C4IDPacket::pNext.

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

288 {
289  assert(!pPkt->pNext);
290  pPkt->pNext = pFirst;
291  pFirst = pPkt;
292  if (!pLast) pLast = pPkt;
293 }
C4IDPacket * pNext
Definition: C4PacketBase.h:254
C4IDPacket * pFirst
Definition: C4PacketBase.h:277
C4IDPacket * pLast
Definition: C4PacketBase.h:277
Here is the caller graph for this function:

◆ AddHead() [2/2]

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

Definition at line 300 of file C4Packet2.cpp.

References AddHead().

301 {
302  AddHead(new C4IDPacket(eType, pPkt));
303 }
void AddHead(C4IDPacket *pPkt)
Definition: C4Packet2.cpp:287
Here is the call graph for this function:

◆ Append()

void C4PacketList::Append ( const C4PacketList List)

Definition at line 312 of file C4Packet2.cpp.

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

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

313 {
314  for (C4IDPacket *pPkt = List.firstPkt(); pPkt; pPkt = List.nextPkt(pPkt))
315  Add(new C4IDPacket(*pPkt));
316 }
void Add(C4IDPacket *pPkt)
Definition: C4Packet2.cpp:280
C4IDPacket * firstPkt() const
Definition: C4PacketBase.h:280
C4IDPacket * nextPkt(C4IDPacket *pPkt) const
Definition: C4PacketBase.h:281
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Clear()

void C4PacketList::Clear ( )

Definition at line 318 of file C4Packet2.cpp.

References Delete(), and pFirst.

Referenced by C4IDPacket::getPkt(), and ~C4PacketList().

319 {
320  while (pFirst)
321  Delete(pFirst);
322 }
C4IDPacket * pFirst
Definition: C4PacketBase.h:277
void Delete(C4IDPacket *pPkt)
Definition: C4Packet2.cpp:345
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 351 of file C4Packet2.cpp.

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

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

◆ Delete()

void C4PacketList::Delete ( C4IDPacket pPkt)

Definition at line 345 of file C4Packet2.cpp.

References Remove().

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

346 {
347  Remove(pPkt);
348  delete pPkt;
349 }
void Remove(C4IDPacket *pPkt)
Definition: C4Packet2.cpp:324
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 280 of file C4PacketBase.h.

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

280 { return pFirst; }
C4IDPacket * pFirst
Definition: C4PacketBase.h:277
Here is the caller graph for this function:

◆ getPktCnt()

int32_t C4PacketList::getPktCnt ( ) const

Definition at line 272 of file C4Packet2.cpp.

References iCnt, pFirst, and C4IDPacket::pNext.

273 {
274  int32_t iCnt = 0;
275  for (C4IDPacket *pPkt = pFirst; pPkt; pPkt = pPkt->pNext)
276  iCnt++;
277  return iCnt;
278 }
C4IDPacket * pNext
Definition: C4PacketBase.h:254
C4IDPacket * pFirst
Definition: C4PacketBase.h:277
int iCnt
Definition: TstC4NetIO.cpp:32

◆ nextPkt()

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

Definition at line 281 of file C4PacketBase.h.

References C4PacketBase::CompileFunc(), and C4IDPacket::pNext.

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

281 { return pPkt->pNext; }
C4IDPacket * pNext
Definition: C4PacketBase.h:254
Here is the call graph for this function:
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.

Referenced by MkC4NetIOPacket().

151 {
152  return C4NetIOPacket(DecompileToBuf<StdCompilerBinWrite>(*this), addr);
153 }
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.

References mkDecompileAdapt(), and mkInsertAdapt().

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

◆ Remove()

void C4PacketList::Remove ( C4IDPacket pPkt)

Definition at line 324 of file C4Packet2.cpp.

References pFirst, pLast, and C4IDPacket::pNext.

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

325 {
326  if (pPkt == pFirst)
327  {
328  pFirst = pPkt->pNext;
329  if (pPkt == pLast)
330  pLast = nullptr;
331  }
332  else
333  {
334  C4IDPacket *pPrev;
335  for (pPrev = pFirst; pPrev && pPrev->pNext != pPkt; pPrev = pPrev->pNext) {}
336  if (pPrev)
337  {
338  pPrev->pNext = pPkt->pNext;
339  if (pPkt == pLast)
340  pLast = pPrev;
341  }
342  }
343 }
C4IDPacket * pNext
Definition: C4PacketBase.h:254
C4IDPacket * pFirst
Definition: C4PacketBase.h:277
C4IDPacket * pLast
Definition: C4PacketBase.h:277
Here is the caller graph for this function:

◆ Take()

void C4PacketList::Take ( C4PacketList List)

Definition at line 305 of file C4Packet2.cpp.

References pFirst, and pLast.

Referenced by C4Control::Take().

306 {
307  pFirst = List.pFirst;
308  pLast = List.pLast;
309  List.pFirst = List.pLast = nullptr;
310 }
C4IDPacket * pFirst
Definition: C4PacketBase.h:277
C4IDPacket * pLast
Definition: C4PacketBase.h:277
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.

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

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

161 {
162  if (pStatus) *pStatus = Pkt.getStatus();
163  CompileFromBuf<StdCompilerBinRead>(*this, pStatus ? Pkt.getPBuf() : Pkt.getRef());
164 }
uint8_t getStatus() const
Definition: C4NetIO.h:318
StdBuf getPBuf() const
Definition: C4NetIO.h:321
C4NetIOPacket getRef() const
Definition: C4NetIO.h:324
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 277 of file C4PacketBase.h.

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

◆ pLast

C4IDPacket * C4PacketList::pLast {nullptr}
protected

Definition at line 277 of file C4PacketBase.h.

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


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