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)
 
 ~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 266 of file C4PacketBase.h.

Constructor & Destructor Documentation

C4PacketList::C4PacketList ( )
default
C4PacketList::C4PacketList ( const C4PacketList List2)

Definition at line 259 of file C4Packet2.cpp.

References Append().

260  : C4PacketBase(List2),
261  pFirst(nullptr), pLast(nullptr)
262 {
263  Append(List2);
264 }
C4IDPacket * pFirst
Definition: C4PacketBase.h:274
C4IDPacket * pLast
Definition: C4PacketBase.h:274
void Append(const C4PacketList &List)
Definition: C4Packet2.cpp:311

Here is the call graph for this function:

C4PacketList::~C4PacketList ( )
override

Definition at line 266 of file C4Packet2.cpp.

References Clear().

267 {
268  Clear();
269 }
void Clear()
Definition: C4Packet2.cpp:317

Here is the call graph for this function:

Member Function Documentation

void C4PacketList::Add ( C4IDPacket pPkt)

Definition at line 279 of file C4Packet2.cpp.

References pFirst, pLast, and C4IDPacket::pNext.

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

280 {
281  assert(!pPkt->pNext);
282  (pLast ? pLast->pNext : pFirst) = pPkt;
283  pLast = pPkt;
284 }
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 294 of file C4Packet2.cpp.

References Add().

295 {
296  Add(new C4IDPacket(eType, pPkt));
297 }
void Add(C4IDPacket *pPkt)
Definition: C4Packet2.cpp:279

Here is the call graph for this function:

void C4PacketList::AddHead ( C4IDPacket pPkt)

Definition at line 286 of file C4Packet2.cpp.

References pFirst, pLast, and C4IDPacket::pNext.

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

287 {
288  assert(!pPkt->pNext);
289  pPkt->pNext = pFirst;
290  pFirst = pPkt;
291  if (!pLast) pLast = pPkt;
292 }
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 299 of file C4Packet2.cpp.

References AddHead().

300 {
301  AddHead(new C4IDPacket(eType, pPkt));
302 }
void AddHead(C4IDPacket *pPkt)
Definition: C4Packet2.cpp:286

Here is the call graph for this function:

void C4PacketList::Append ( const C4PacketList List)

Definition at line 311 of file C4Packet2.cpp.

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

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

312 {
313  for (C4IDPacket *pPkt = List.firstPkt(); pPkt; pPkt = List.nextPkt(pPkt))
314  Add(new C4IDPacket(*pPkt));
315 }
void Add(C4IDPacket *pPkt)
Definition: C4Packet2.cpp:279
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 317 of file C4Packet2.cpp.

References Delete(), and pFirst.

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

318 {
319  while (pFirst)
320  Delete(pFirst);
321 }
C4IDPacket * pFirst
Definition: C4PacketBase.h:274
void Delete(C4IDPacket *pPkt)
Definition: C4Packet2.cpp:344

Here is the call graph for this function:

Here is the caller graph for this function:

void C4PacketList::CompileFunc ( StdCompiler pComp)
overridevirtual

Implements C4PacketBase.

Definition at line 350 of file C4Packet2.cpp.

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

351 {
352  // unpack packets
353  if (pComp->isDeserializer())
354  {
355  // Read until no further sections available
356  while (pComp->Name("IDPacket"))
357  {
358  // Read the packet
359  C4IDPacket *pPkt = new C4IDPacket();
360  try
361  {
362  pComp->Value(*pPkt);
363  pComp->NameEnd();
364  }
365  catch (...)
366  {
367  delete pPkt;
368  throw;
369  }
370  // Terminator?
371  if (!pPkt->getPkt()) { delete pPkt; break; }
372  // Add to list
373  Add(pPkt);
374  }
375  pComp->NameEnd();
376  }
377  else
378  {
379  // Write all packets
380  for (C4IDPacket *pPkt = pFirst; pPkt; pPkt = pPkt->pNext)
381  pComp->Value(mkNamingAdapt(*pPkt, "IDPacket"));
382  // Terminate, if no naming is available
383  if (!pComp->hasNaming())
384  {
385  C4IDPacket Pkt;
386  pComp->Value(mkNamingAdapt(Pkt, "IDPacket"));
387  }
388  }
389 }
virtual bool hasNaming()
Definition: StdCompiler.h:58
C4IDPacket * pNext
Definition: C4PacketBase.h:251
void Add(C4IDPacket *pPkt)
Definition: C4Packet2.cpp:279
C4IDPacket * pFirst
Definition: C4PacketBase.h:274
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:255
virtual void NameEnd(bool fBreak=false)
Definition: StdCompiler.h:78

Here is the call graph for this function:

void C4PacketList::Delete ( C4IDPacket pPkt)

Definition at line 344 of file C4Packet2.cpp.

References Remove().

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

345 {
346  Remove(pPkt);
347  delete pPkt;
348 }
void Remove(C4IDPacket *pPkt)
Definition: C4Packet2.cpp:323

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 271 of file C4Packet2.cpp.

References iCnt, pFirst, and C4IDPacket::pNext.

272 {
273  int32_t iCnt = 0;
274  for (C4IDPacket *pPkt = pFirst; pPkt; pPkt = pPkt->pNext)
275  iCnt++;
276  return iCnt;
277 }
C4IDPacket * pNext
Definition: C4PacketBase.h:251
C4IDPacket * pFirst
Definition: C4PacketBase.h:274
int iCnt
Definition: TstC4NetIO.cpp:32
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 149 of file C4Packet2.cpp.

Referenced by MkC4NetIOPacket().

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

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 154 of file C4Packet2.cpp.

References mkDecompileAdapt(), and mkInsertAdapt().

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

Here is the call graph for this function:

void C4PacketList::Remove ( C4IDPacket pPkt)

Definition at line 323 of file C4Packet2.cpp.

References pFirst, pLast, and C4IDPacket::pNext.

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

324 {
325  if (pPkt == pFirst)
326  {
327  pFirst = pPkt->pNext;
328  if (pPkt == pLast)
329  pLast = nullptr;
330  }
331  else
332  {
333  C4IDPacket *pPrev;
334  for (pPrev = pFirst; pPrev && pPrev->pNext != pPkt; pPrev = pPrev->pNext) {}
335  if (pPrev)
336  {
337  pPrev->pNext = pPkt->pNext;
338  if (pPkt == pLast)
339  pLast = pPrev;
340  }
341  }
342 }
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 304 of file C4Packet2.cpp.

References pFirst, and pLast.

Referenced by C4Control::Take().

305 {
306  pFirst = List.pFirst;
307  pLast = List.pLast;
308  List.pFirst = List.pLast = nullptr;
309 }
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 159 of file C4Packet2.cpp.

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

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

C4IDPacket* C4PacketList::pFirst {nullptr}
protected

Definition at line 274 of file C4PacketBase.h.

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

C4IDPacket * C4PacketList::pLast {nullptr}
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: