OpenClonk
C4NetIOPacket Class Reference

#include <C4NetIO.h>

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

Public Member Functions

 C4NetIOPacket ()
 
 C4NetIOPacket (const void *pnData, size_t inSize, bool fCopy=false, const C4NetIO::addr_t &naddr=C4NetIO::addr_t())
 
 C4NetIOPacket (const StdBuf &Buf, const C4NetIO::addr_t &naddr)
 
 C4NetIOPacket (uint8_t cStatusByte, const char *pnData, size_t inSize, const C4NetIO::addr_t &naddr=C4NetIO::addr_t())
 
 ~C4NetIOPacket ()
 
const C4NetIO::addr_tgetAddr () const
 
uint8_t getStatus () const
 
const char * getPData () const
 
size_t getPSize () const
 
StdBuf getPBuf () const
 
C4NetIOPacket getRef () const
 
C4NetIOPacket Duplicate () const
 
void SetAddr (const C4NetIO::addr_t &naddr)
 
void Clear ()
 
bool isNull () const
 
const void * getData () const
 
void * getMData ()
 
size_t getSize () const
 
bool isRef () const
 
const void * getPtr (size_t i) const
 
void * getMPtr (size_t i)
 
StdBuf getPart (size_t iStart, size_t inSize) const
 
void Ref (const void *pnData, size_t inSize)
 
void Ref (const StdBuf &Buf2)
 
void Take (void *pnData, size_t inSize)
 
void Take (StdBuf &Buf2)
 
void Take (StdBuf &&Buf2)
 
void * GrabPointer ()
 
void New (size_t inSize)
 
void Write (const void *pnData, size_t inSize, size_t iAt=0)
 
void Write (const StdBuf &Buf2, size_t iAt=0)
 
void Move (size_t iFrom, size_t inSize, size_t iTo=0)
 
int Compare (const void *pCData, size_t iCSize, size_t iAt=0) const
 
int Compare (const StdBuf &Buf2, size_t iAt=0) const
 
void Grow (size_t iGrow)
 
void Shrink (size_t iShrink)
 
void SetSize (size_t inSize)
 
void Copy (size_t inSize)
 
void Copy ()
 
void Copy (const void *pnData, size_t inSize)
 
void Copy (const StdBuf &Buf2)
 
void Append (const void *pnData, size_t inSize)
 
void Append (const StdBuf &Buf2)
 
bool LoadFromFile (const char *szFile)
 
bool SaveToFile (const char *szFile) const
 
bool operator! () const
 
StdBuf operator+= (const StdBuf &Buf2)
 
StdBuf operator+ (const StdBuf &Buf2) const
 
bool operator== (const StdBuf &Buf2) const
 
bool operator!= (const StdBuf &Buf2) const
 
int GetHash () const
 
void CompileFunc (class StdCompiler *pComp, int iType=0)
 

Static Public Member Functions

static void DeletePointer (void *data)
 

Protected Attributes

C4NetIO::addr_t addr
 
bool fRef = true
 
union {
const void * pData = nullptr
 
void * pMData
 
}; 
 
unsigned int iSize = 0
 

Detailed Description

Definition at line 294 of file C4NetIO.h.

Constructor & Destructor Documentation

◆ C4NetIOPacket() [1/4]

C4NetIOPacket::C4NetIOPacket ( )
default

Referenced by C4NetIO::SetError().

Here is the caller graph for this function:

◆ C4NetIOPacket() [2/4]

C4NetIOPacket::C4NetIOPacket ( const void *  pnData,
size_t  inSize,
bool  fCopy = false,
const C4NetIO::addr_t naddr = C4NetIO::addr_t() 
)

Definition at line 765 of file C4NetIO.cpp.

766  : StdCopyBuf(pnData, inSize, fCopy), addr(naddr)
767 {
768 }
C4NetIO::addr_t addr
Definition: C4NetIO.h:312
StdCopyBuf()=default

◆ C4NetIOPacket() [3/4]

C4NetIOPacket::C4NetIOPacket ( const StdBuf Buf,
const C4NetIO::addr_t naddr 
)
explicit

Definition at line 770 of file C4NetIO.cpp.

771  : StdCopyBuf(Buf), addr(naddr)
772 {
773 }
C4NetIO::addr_t addr
Definition: C4NetIO.h:312
StdCopyBuf()=default

◆ C4NetIOPacket() [4/4]

C4NetIOPacket::C4NetIOPacket ( uint8_t  cStatusByte,
const char *  pnData,
size_t  inSize,
const C4NetIO::addr_t naddr = C4NetIO::addr_t() 
)

Definition at line 775 of file C4NetIO.cpp.

References StdBuf::New(), and StdBuf::Write().

776 {
777  // Create buffer
778  New(sizeof(cStatusByte) + inSize);
779  // Write data
780  *getMBufPtr<uint8_t>(*this) = cStatusByte;
781  Write(pnData, inSize, sizeof(cStatusByte));
782 }
void New(size_t inSize)
Definition: StdBuf.h:146
void Write(const void *pnData, size_t inSize, size_t iAt=0)
Definition: StdBuf.h:153
Here is the call graph for this function:

◆ ~C4NetIOPacket()

C4NetIOPacket::~C4NetIOPacket ( )

Definition at line 784 of file C4NetIO.cpp.

References Clear().

785 {
786  Clear();
787 }
void Clear()
Definition: C4NetIO.cpp:789
Here is the call graph for this function:

Member Function Documentation

◆ Append() [1/2]

void StdBuf::Append ( const void *  pnData,
size_t  inSize 
)
inlineinherited

Definition at line 254 of file StdBuf.h.

References StdBuf::Grow(), and StdBuf::Write().

Referenced by StdBuf::Append(), StdStrBuf::Append(), StdStrBuf::AppendFormatV(), StdStrBuf::AppendUntil(), StdStrBuf::Copy(), StdBuf::operator+(), StdBuf::operator+=(), StdStrBuf::operator+=(), C4Network2RefServer::PackPacket(), C4Network2HTTPClient::PackPacket(), C4Playback::ReadBinary(), and CStdFile::SaveBuffer().

255  {
256  Grow(inSize);
257  Write(pnData, inSize, iSize - inSize);
258  }
void Grow(size_t iGrow)
Definition: StdBuf.h:171
void Write(const void *pnData, size_t inSize, size_t iAt=0)
Definition: StdBuf.h:153
unsigned int iSize
Definition: StdBuf.h:92
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Append() [2/2]

void StdBuf::Append ( const StdBuf Buf2)
inlineinherited

Definition at line 260 of file StdBuf.h.

References StdBuf::Append(), StdBuf::getData(), and StdBuf::getSize().

261  {
262  Append(Buf2.getData(), Buf2.getSize());
263  }
size_t getSize() const
Definition: StdBuf.h:101
const void * getData() const
Definition: StdBuf.h:99
void Append(const void *pnData, size_t inSize)
Definition: StdBuf.h:254
Here is the call graph for this function:

◆ Clear()

void C4NetIOPacket::Clear ( )

Definition at line 789 of file C4NetIO.cpp.

References addr, and StdBuf::Clear().

Referenced by C4NetIOUDP::Packet::AddFragment(), C4NetIOUDP::InitBroadcast(), and ~C4NetIOPacket().

790 {
791  addr = C4NetIO::addr_t();
792  StdBuf::Clear();
793 }
void Clear()
Definition: StdBuf.h:190
C4NetIO::addr_t addr
Definition: C4NetIO.h:312
EndpointAddress addr_t
Definition: C4NetIO.h:212
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Compare() [1/2]

int StdBuf::Compare ( const void *  pCData,
size_t  iCSize,
size_t  iAt = 0 
) const
inlineinherited

Definition at line 165 of file StdBuf.h.

References StdBuf::getPtr(), and StdBuf::getSize().

Referenced by C4NetIOUDP::Packet::AddFragment(), StdBuf::Compare(), StdStrBuf::Compare(), StdStrBuf::Compare_(), C4NetIOUDP::DoLoopbackTest(), StdBuf::operator==(), and StdStrBuf::operator==().

166  {
167  assert(iAt + iCSize <= getSize());
168  return std::memcmp(getPtr(iAt), pCData, iCSize);
169  }
const void * getPtr(size_t i) const
Definition: StdBuf.h:104
size_t getSize() const
Definition: StdBuf.h:101
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Compare() [2/2]

int StdBuf::Compare ( const StdBuf Buf2,
size_t  iAt = 0 
) const
inlineinherited

Definition at line 219 of file StdBuf.h.

References StdBuf::Compare(), StdBuf::getData(), and StdBuf::getSize().

220  {
221  return Compare(Buf2.getData(), Buf2.getSize(), iAt);
222  }
size_t getSize() const
Definition: StdBuf.h:101
const void * getData() const
Definition: StdBuf.h:99
int Compare(const void *pCData, size_t iCSize, size_t iAt=0) const
Definition: StdBuf.h:165
Here is the call graph for this function:

◆ CompileFunc()

void StdBuf::CompileFunc ( class StdCompiler pComp,
int  iType = 0 
)
inherited

Definition at line 114 of file StdBuf.cpp.

References StdBuf::getData(), StdBuf::getMData(), StdBuf::getSize(), GetWideChar(), GetWideCharBuf(), StdCompiler::isDeserializer(), StdBuf::iSize, mkIntPackAdapt(), StdBuf::New(), StdCompiler::Raw(), StdCompiler::SEP_PART2, StdCompiler::Separator(), StdBuf::SetSize(), StdStrBuf::StdStrBuf(), and StdCompiler::Value().

Referenced by StdStrBuf::EscapeString(), and StdBuf::GetHash().

115 {
116  // Size (guess it is a small value most of the time - if it's big, an extra byte won't hurt anyway)
117  uint32_t tmp = iSize; pComp->Value(mkIntPackAdapt(tmp)); iSize = tmp;
118  pComp->Separator(StdCompiler::SEP_PART2);
119  // Read/write data
120  if (pComp->isDeserializer())
121  {
122  New(iSize);
123  pComp->Raw(getMData(), iSize, StdCompiler::RawCompileType(iType));
124  }
125  else
126  {
127  pComp->Raw(const_cast<void *>(getData()), iSize, StdCompiler::RawCompileType(iType));
128  }
129 }
void New(size_t inSize)
Definition: StdBuf.h:146
const void * getData() const
Definition: StdBuf.h:99
StdIntPackAdapt< T > mkIntPackAdapt(T &rVal)
Definition: StdAdaptors.h:777
unsigned int iSize
Definition: StdBuf.h:92
void * getMData()
Definition: StdBuf.h:100
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Copy() [1/4]

void StdBuf::Copy ( size_t  inSize)
inlineinherited

Definition at line 225 of file StdBuf.h.

References StdBuf::getData(), StdBuf::iSize, StdBuf::isNull(), StdBuf::New(), and StdBuf::Write().

Referenced by C4PktBuf::C4PktBuf(), C4NetIOUDP::ClearStatistic(), EditorWindowState::CompileFunc(), and StdBuf::Duplicate().

226  {
227  if (isNull() && !inSize) return;
228  const void *pOldData = getData();
229  size_t iOldSize = iSize;
230  New(inSize);
231  Write(pOldData, std::min(iOldSize, inSize));
232  }
bool isNull() const
Definition: StdBuf.h:98
void New(size_t inSize)
Definition: StdBuf.h:146
const void * getData() const
Definition: StdBuf.h:99
void Write(const void *pnData, size_t inSize, size_t iAt=0)
Definition: StdBuf.h:153
unsigned int iSize
Definition: StdBuf.h:92
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Copy() [2/4]

void StdBuf::Copy ( )
inlineinherited

Definition at line 233 of file StdBuf.h.

Referenced by StdBuf::Copy(), StdStrBuf::Copy(), StdBuf::GrabPointer(), StdBuf::Grow(), StdCopyBuf::operator=(), StdCopyStrBuf::operator=(), StdBuf::Shrink(), and StdBuf::StdBuf().

234  {
235  Copy(iSize);
236  }
void Copy()
Definition: StdBuf.h:233
unsigned int iSize
Definition: StdBuf.h:92
Here is the caller graph for this function:

◆ Copy() [3/4]

void StdBuf::Copy ( const void *  pnData,
size_t  inSize 
)
inlineinherited

Definition at line 238 of file StdBuf.h.

References StdBuf::Copy(), and StdBuf::Ref().

239  {
240  Ref(pnData, inSize); Copy();
241  }
void Copy()
Definition: StdBuf.h:233
void Ref(const void *pnData, size_t inSize)
Definition: StdBuf.h:118
Here is the call graph for this function:

◆ Copy() [4/4]

void StdBuf::Copy ( const StdBuf Buf2)
inlineinherited

Definition at line 243 of file StdBuf.h.

References StdBuf::Copy(), StdBuf::getData(), and StdBuf::getSize().

244  {
245  Copy(Buf2.getData(), Buf2.getSize());
246  }
void Copy()
Definition: StdBuf.h:233
size_t getSize() const
Definition: StdBuf.h:101
const void * getData() const
Definition: StdBuf.h:99
Here is the call graph for this function:

◆ DeletePointer()

static void StdBuf::DeletePointer ( void *  data)
inlinestaticinherited

Definition at line 196 of file StdBuf.h.

Referenced by C4ID::CompileFunc(), C4Group::Open(), and C4GroupEntry::~C4GroupEntry().

197  {
198  free(data);
199  }
Here is the caller graph for this function:

◆ Duplicate()

C4NetIOPacket C4NetIOPacket::Duplicate ( ) const
inline

Definition at line 325 of file C4NetIO.h.

References StdBuf::Duplicate().

Referenced by C4NetIOUDP::Broadcast(), C4Network2IO::HandlePacket(), and C4NetIOUDP::Peer::Send().

325 { return C4NetIOPacket(StdBuf::Duplicate(), addr); }
StdBuf Duplicate() const
Definition: StdBuf.h:248
C4NetIO::addr_t addr
Definition: C4NetIO.h:312
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getAddr()

const C4NetIO::addr_t& C4NetIOPacket::getAddr ( ) const
inline

Definition at line 316 of file C4NetIO.h.

Referenced by C4PuncherServer::C4PuncherServer(), C4NetIOUDP::ClearStatistic(), C4NetIOUDP::DoCheck(), C4NetIOUDP::DoLoopbackTest(), C4NetIOUDP::Packet::GetFragment(), C4Network2IO::HandlePuncherPacket(), C4NetIOUDP::InitBroadcast(), C4Network2IODiscoverClient::OnPacket(), MyCBClass::OnPacket(), C4Network2IO::OnPacket(), C4NetIOTCP::Send(), C4NetIOSimpleUDP::Send(), and C4NetIOUDP::Send().

316 { return addr; }
C4NetIO::addr_t addr
Definition: C4NetIO.h:312
Here is the caller graph for this function:

◆ getData()

◆ GetHash()

int StdBuf::GetHash ( ) const
inlineinherited

Definition at line 322 of file StdBuf.h.

References StdBuf::CompileFunc(), StdBuf::getData(), StdBuf::getSize(), and StdBuf::isNull().

Referenced by StdStrBuf::GetHash().

323  {
324  if (isNull()) return 0;
325  return crc32(0, reinterpret_cast<const Bytef *>(getData()), getSize());
326  }
size_t getSize() const
Definition: StdBuf.h:101
bool isNull() const
Definition: StdBuf.h:98
const void * getData() const
Definition: StdBuf.h:99
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getMData()

void* StdBuf::getMData ( )
inlineinherited

Definition at line 100 of file StdBuf.h.

Referenced by C4Group::Add(), C4Playback::Check(), StdBuf::CompileFunc(), CStdVectorFont::CStdVectorFont(), getMBufPtr(), StdBuf::getMPtr(), StdBuf::GrabPointer(), C4TextureShape::Load(), C4SoundEffect::Load(), C4Group::LoadEntry(), StdBuf::LoadFromFile(), StdStrBuf::LoadFromFile(), C4SolidMask::LoadMaskFromFile(), and C4Playback::NextSequentialChunk().

100 { assert(!fRef); return pMData; }
bool fRef
Definition: StdBuf.h:82
Here is the caller graph for this function:

◆ getMPtr()

void* StdBuf::getMPtr ( size_t  i)
inlineinherited

Definition at line 105 of file StdBuf.h.

References StdBuf::getMData().

Referenced by StdStrBuf::AppendCharacter(), StdStrBuf::AppendChars(), StdStrBuf::AppendFormatV(), C4NetIOTCP::Peer::GetRecvBuf(), StdStrBuf::Grow(), StdStrBuf::InsertChar(), StdBuf::Move(), StdStrBuf::Replace(), StdStrBuf::ReplaceChar(), StdStrBuf::ReplaceEnd(), StdStrBuf::Shrink(), StdStrBuf::ToLowerCase(), StdStrBuf::TrimSpaces(), and StdBuf::Write().

105 { return reinterpret_cast<char*>(getMData()) + i; }
void * getMData()
Definition: StdBuf.h:100
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getPart()

StdBuf StdBuf::getPart ( size_t  iStart,
size_t  inSize 
) const
inlineinherited

Definition at line 107 of file StdBuf.h.

References StdBuf::getPtr(), and StdBuf::StdBuf().

Referenced by C4NetIOUDP::Packet::AddFragment(), C4NetIOUDP::Packet::GetFragment(), C4NetIOTCP::Peer::OnRecv(), C4Playback::ReadBinary(), and C4Network2HTTPClient::UnpackPacket().

108  {
109  assert(iStart + inSize <= iSize);
110  return StdBuf(getPtr(iStart), inSize);
111  }
const void * getPtr(size_t i) const
Definition: StdBuf.h:104
StdBuf()=default
unsigned int iSize
Definition: StdBuf.h:92
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getPBuf()

StdBuf C4NetIOPacket::getPBuf ( ) const
inline

Definition at line 321 of file C4NetIO.h.

Referenced by C4PacketBase::unpack().

321 { return getSize() ? getPart(1, getSize() - 1) : getRef(); }
StdBuf getPart(size_t iStart, size_t inSize) const
Definition: StdBuf.h:107
size_t getSize() const
Definition: StdBuf.h:101
C4NetIOPacket getRef() const
Definition: C4NetIO.h:324
Here is the caller graph for this function:

◆ getPData()

const char* C4NetIOPacket::getPData ( ) const
inline

Definition at line 319 of file C4NetIO.h.

Referenced by C4NetpuncherPacket::Construct().

319 { return getSize() ? getBufPtr<char>(*this, 1) : nullptr; }
size_t getSize() const
Definition: StdBuf.h:101
Here is the caller graph for this function:

◆ getPSize()

size_t C4NetIOPacket::getPSize ( ) const
inline

Definition at line 320 of file C4NetIO.h.

Referenced by C4NetpuncherPacketCReq::C4NetpuncherPacketCReq(), and C4NetpuncherPacketID< TYPE >::C4NetpuncherPacketID().

320 { return getSize() ? getSize() - 1 : 0; }
size_t getSize() const
Definition: StdBuf.h:101
Here is the caller graph for this function:

◆ getPtr()

const void* StdBuf::getPtr ( size_t  i) const
inlineinherited

Definition at line 104 of file StdBuf.h.

References StdBuf::getData().

Referenced by StdStrBuf::AppendBackslash(), StdBuf::Compare(), StdStrBuf::copyPart(), StdStrBuf::EnsureUnicode(), StdBuf::getPart(), StdStrBuf::InsertChar(), StdBuf::Move(), StdStrBuf::operator[](), and StdStrBuf::Replace().

104 { return reinterpret_cast<const char*>(getData()) + i; }
const void * getData() const
Definition: StdBuf.h:99
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getRef()

C4NetIOPacket C4NetIOPacket::getRef ( ) const
inline

Definition at line 324 of file C4NetIO.h.

References StdBuf::getRef().

Referenced by C4NetIOTCP::Broadcast(), C4NetIOSimpleUDP::Broadcast(), and C4PacketBase::unpack().

324 { return C4NetIOPacket(StdBuf::getRef(), addr); }
C4NetIO::addr_t addr
Definition: C4NetIO.h:312
StdBuf getRef() const
Definition: StdBuf.h:271
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getSize()

size_t StdBuf::getSize ( ) const
inlineinherited

Definition at line 101 of file StdBuf.h.

References StdBuf::iSize.

Referenced by C4Group::Add(), C4NetIOUDP::Packet::AddFragment(), StdBuf::Append(), C4ControlJoinPlayer::C4ControlJoinPlayer(), StdBuf::Compare(), StdBuf::CompileFunc(), StdBuf::Copy(), CStdVectorFont::CStdVectorFont(), C4NetIOUDP::DoCheck(), C4NetIOUDP::DoLoopbackTest(), C4Network2::DrawStatus(), StdStrBuf::EnsureUnicode(), C4NetIOUDP::Packet::FragmentCnt(), C4NetIOUDP::Packet::FragmentSize(), GetDbgRecPktData(), C4Group::GetFirstEntry(), C4NetIOUDP::Packet::GetFragment(), StdBuf::GetHash(), StdStrBuf::getLength(), C4Network2::getPendingStreamData(), C4NetIOTCP::Peer::GetRecvBuf(), StdBuf::getRef(), C4PktBuf::getSize(), StdStrBuf::getSize(), StdStrBuf::Grow(), C4Network2IO::HandlePacket(), C4AulDebug::Listen(), C4TextureShape::Load(), C4SoundEffect::Load(), StdBuf::LoadFromFile(), C4SolidMask::LoadMaskFromFile(), C4Network2IODiscover::OnPacket(), C4Network2IODiscoverClient::OnPacket(), C4Network2IO::OnPacket(), C4NetIOTCP::Peer::OnRecv(), C4NetIOUDP::Peer::OnRecv(), StdBuf::operator==(), C4NetIOTCP::PackPacket(), PropertyDlgProc(), C4Network2HTTPClient::Query(), StdCompilerINIRead::Raw(), C4Playback::ReadBinary(), C4Record::Rec(), StdBuf::Ref(), C4Playback::ReWriteBinary(), StdBuf::SaveToFile(), C4NetIOTCP::Peer::Send(), C4NetIOSimpleUDP::Send(), C4Network2::StreamIn(), C4Playback::StreamToRecord(), StdBuf::Take(), C4Network2RefServer::UnpackPacket(), C4Network2HTTPClient::UnpackPacket(), C4NetIOTCP::UnpackPacket(), StdBuf::Write(), and C4Network2IRCClient::~C4Network2IRCClient().

101 { return iSize; }
unsigned int iSize
Definition: StdBuf.h:92
Here is the caller graph for this function:

◆ getStatus()

uint8_t C4NetIOPacket::getStatus ( ) const
inline

Definition at line 318 of file C4NetIO.h.

Referenced by C4NetIOUDP::ClearStatistic(), C4Network2IO::HandlePacket(), C4NetIOUDP::Packet::Multicast(), C4Network2IODiscover::OnPacket(), C4Network2IODiscoverClient::OnPacket(), MyCBClass::OnPacket(), C4Network2IO::OnPacket(), C4Network2IOConnection::Send(), and C4PacketBase::unpack().

318 { return getSize() ? *getBufPtr<char>(*this) : 0; }
size_t getSize() const
Definition: StdBuf.h:101
Here is the caller graph for this function:

◆ GrabPointer()

void* StdBuf::GrabPointer ( )
inlineinherited

Definition at line 133 of file StdBuf.h.

References StdBuf::Copy(), StdBuf::getMData(), and StdBuf::isNull().

Referenced by C4Group::Add(), C4Group::GetFirstEntry(), StdStrBuf::GrabPointer(), StdCompilerINIRead::String(), and StdBuf::Take().

134  {
135  if (isNull()) return nullptr;
136  // Do not give out a buffer which someone else will free
137  if (fRef) Copy();
138  void *pMData = getMData();
139  pData = pMData; fRef = true;
140  return pMData;
141  }
void Copy()
Definition: StdBuf.h:233
bool isNull() const
Definition: StdBuf.h:98
bool fRef
Definition: StdBuf.h:82
void * getMData()
Definition: StdBuf.h:100
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Grow()

void StdBuf::Grow ( size_t  iGrow)
inlineinherited

Definition at line 171 of file StdBuf.h.

References StdBuf::Copy().

Referenced by StdBuf::Append(), StdStrBuf::Append(), StdStrBuf::AppendCharacter(), StdStrBuf::AppendChars(), StdStrBuf::AppendFormatV(), StdStrBuf::Grow(), StdStrBuf::InsertChar(), C4AulDebug::Listen(), C4NetIOTCP::PackPacket(), C4Playback::ReWriteBinary(), StdStrBuf::SetLength(), StdBuf::SetSize(), C4Playback::StreamToRecord(), and C4Network2IRCClient::~C4Network2IRCClient().

172  {
173  // Grow dereferences
174  if (fRef) { Copy(iSize + iGrow); return; }
175  if (!iGrow) return;
176  // Realloc
177  pMData = realloc(pMData, iSize += iGrow);
178  }
void Copy()
Definition: StdBuf.h:233
bool fRef
Definition: StdBuf.h:82
unsigned int iSize
Definition: StdBuf.h:92
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isNull()

bool StdBuf::isNull ( ) const
inlineinherited

Definition at line 98 of file StdBuf.h.

References StdBuf::getData().

Referenced by StdStrBuf::AppendFormatV(), StdBuf::Copy(), C4NetIOUDP::Packet::Empty(), StdBuf::GetHash(), StdBuf::GrabPointer(), C4NetIOTCP::Peer::hasWaitingData(), C4NetIOUDP::InitBroadcast(), StdStrBuf::isNull(), StdBuf::operator!(), StdStrBuf::operator!(), StdStrBuf::ReplaceChar(), C4NetIOTCP::Peer::Send(), StdStrBuf::SetLength(), and StdStrBuf::ToLowerCase().

98 { return ! getData(); }
const void * getData() const
Definition: StdBuf.h:99
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isRef()

bool StdBuf::isRef ( ) const
inlineinherited

Definition at line 102 of file StdBuf.h.

References StdBuf::fRef.

Referenced by StdStrBuf::isRef(), and StdBuf::StdBuf().

102 { return fRef; }
bool fRef
Definition: StdBuf.h:82
Here is the caller graph for this function:

◆ LoadFromFile()

bool StdBuf::LoadFromFile ( const char *  szFile)
inherited

Definition at line 32 of file StdBuf.cpp.

References FileSize(), StdBuf::getMData(), StdBuf::getSize(), GetWideChar(), StdBuf::New(), O_BINARY, O_CLOEXEC, and O_SEQUENTIAL.

Referenced by C4ControlJoinPlayer::C4ControlJoinPlayer(), EditorWindowState::CompileFunc(), StdStrBuf::Copy(), C4Record::StopStreaming(), C4Playback::StreamToRecord(), C4ControlJoinPlayer::Strip(), and StdBuf::Take().

33 {
34  // Open file
35 #ifdef _WIN32
36  int fh = _wopen(::GetWideChar(szFile), O_BINARY | O_RDONLY | O_SEQUENTIAL, S_IREAD | S_IWRITE);
37 #else
38  int fh = open(szFile, O_BINARY | O_CLOEXEC | O_RDONLY | O_SEQUENTIAL, S_IREAD | S_IWRITE);
39 #endif
40  if (fh < 0) return false;
41  // Create buf
42  New(FileSize(fh));
43  // Read
44  if (read(fh, getMData(), getSize()) != (signed int) getSize())
45  {
46  close(fh);
47  return false;
48  }
49  close(fh);
50  // Ok
51  return true;
52 }
StdStrBuf::wchar_t_holder GetWideChar(const char *utf8, bool double_null_terminate=false)
#define O_BINARY
Definition: StdBuf.cpp:25
#define O_CLOEXEC
size_t FileSize(const char *fname)
size_t getSize() const
Definition: StdBuf.h:101
void New(size_t inSize)
Definition: StdBuf.h:146
#define O_SEQUENTIAL
Definition: StdBuf.cpp:26
void * getMData()
Definition: StdBuf.h:100
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Move()

void StdBuf::Move ( size_t  iFrom,
size_t  inSize,
size_t  iTo = 0 
)
inlineinherited

Definition at line 159 of file StdBuf.h.

References StdBuf::getMPtr(), and StdBuf::getPtr().

Referenced by StdStrBuf::Move(), C4NetIOTCP::Peer::OnRecv(), and C4NetIOTCP::Peer::Send().

160  {
161  assert(iFrom + inSize <= iSize); assert(iTo + inSize <= iSize);
162  std::memmove(getMPtr(iTo), getPtr(iFrom), inSize);
163  }
const void * getPtr(size_t i) const
Definition: StdBuf.h:104
void * getMPtr(size_t i)
Definition: StdBuf.h:105
unsigned int iSize
Definition: StdBuf.h:92
Here is the call graph for this function:
Here is the caller graph for this function:

◆ New()

void StdBuf::New ( size_t  inSize)
inlineinherited

Definition at line 146 of file StdBuf.h.

References StdBuf::Clear().

Referenced by C4NetIOUDP::Packet::AddFragment(), C4NetIOPacket(), StdBuf::CompileFunc(), StdBuf::Copy(), C4NetIOUDP::Peer::DoCheck(), C4NetIOSimpleUDP::Execute(), C4NetIOUDP::Packet::GetFragment(), C4Group::LoadEntry(), StdBuf::LoadFromFile(), C4Playback::NextSequentialChunk(), C4NetpuncherPacket::PackTo(), StdCompilerINIRead::ReadString(), StdStrBuf::Replace(), and C4Playback::StreamToRecord().

147  {
148  Clear();
149  pMData = malloc(iSize = inSize);
150  fRef = false;
151  }
void Clear()
Definition: StdBuf.h:190
bool fRef
Definition: StdBuf.h:82
unsigned int iSize
Definition: StdBuf.h:92
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator!()

bool StdBuf::operator! ( ) const
inlineinherited

Definition at line 292 of file StdBuf.h.

References StdBuf::isNull().

292 { return isNull(); }
bool isNull() const
Definition: StdBuf.h:98
Here is the call graph for this function:

◆ operator!=()

bool StdBuf::operator!= ( const StdBuf Buf2) const
inlineinherited

Definition at line 312 of file StdBuf.h.

References StdBuf::operator==().

312 { return ! operator == (Buf2); }
bool operator==(const StdBuf &Buf2) const
Definition: StdBuf.h:308
Here is the call graph for this function:

◆ operator+()

StdBuf StdBuf::operator+ ( const StdBuf Buf2) const
inlineinherited

Definition at line 300 of file StdBuf.h.

References StdBuf::Append(), and StdBuf::getRef().

301  {
302  StdBuf Buf(getRef());
303  Buf.Append(Buf2);
304  return Buf;
305  }
Definition: StdBuf.h:29
StdBuf getRef() const
Definition: StdBuf.h:271
Here is the call graph for this function:

◆ operator+=()

StdBuf StdBuf::operator+= ( const StdBuf Buf2)
inlineinherited

Definition at line 295 of file StdBuf.h.

References StdBuf::Append().

296  {
297  Append(Buf2);
298  return *this;
299  }
void Append(const void *pnData, size_t inSize)
Definition: StdBuf.h:254
Here is the call graph for this function:

◆ operator==()

bool StdBuf::operator== ( const StdBuf Buf2) const
inlineinherited

Definition at line 308 of file StdBuf.h.

References StdBuf::Compare(), and StdBuf::getSize().

Referenced by StdBuf::operator!=(), and StdStrBuf::operator!=().

309  {
310  return getSize() == Buf2.getSize() && !Compare(Buf2);
311  }
size_t getSize() const
Definition: StdBuf.h:101
int Compare(const void *pCData, size_t iCSize, size_t iAt=0) const
Definition: StdBuf.h:165
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Ref() [1/2]

void StdBuf::Ref ( const void *  pnData,
size_t  inSize 
)
inlineinherited

Definition at line 118 of file StdBuf.h.

References StdBuf::Clear().

Referenced by StdBuf::Copy(), StdBuf::operator=(), StdStrBuf::operator=(), StdBuf::Ref(), StdStrBuf::Ref(), and StdBuf::StdBuf().

119  {
120  Clear();
121  fRef = true; pData = pnData; iSize = inSize;
122  }
void Clear()
Definition: StdBuf.h:190
bool fRef
Definition: StdBuf.h:82
unsigned int iSize
Definition: StdBuf.h:92
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Ref() [2/2]

void StdBuf::Ref ( const StdBuf Buf2)
inlineinherited

Definition at line 266 of file StdBuf.h.

References StdBuf::getData(), StdBuf::getSize(), and StdBuf::Ref().

267  {
268  Ref(Buf2.getData(), Buf2.getSize());
269  }
void Ref(const void *pnData, size_t inSize)
Definition: StdBuf.h:118
size_t getSize() const
Definition: StdBuf.h:101
const void * getData() const
Definition: StdBuf.h:99
Here is the call graph for this function:

◆ SaveToFile()

bool StdBuf::SaveToFile ( const char *  szFile) const
inherited

Definition at line 53 of file StdBuf.cpp.

References StdBuf::getData(), StdBuf::getSize(), GetWideChar(), O_BINARY, O_CLOEXEC, and O_SEQUENTIAL.

Referenced by C4ControlJoinPlayer::C4ControlJoinPlayer(), EditorWindowState::CompileFunc(), StdStrBuf::Copy(), C4DownloadDlg::ShowModal(), C4Playback::StreamToRecord(), C4ControlJoinPlayer::Strip(), and StdBuf::Take().

54 {
55  // Open file
56 #ifdef _WIN32
57  int fh = _wopen(::GetWideChar(szFile), O_BINARY | O_CREAT | O_WRONLY | O_SEQUENTIAL | O_TRUNC, S_IREAD | S_IWRITE);
58 #else
59  int fh = open(szFile, O_BINARY | O_CLOEXEC | O_CREAT | O_WRONLY | O_SEQUENTIAL | O_TRUNC, S_IREAD | S_IWRITE);
60 #endif
61  if (fh < 0) return false;
62  // Write data
63  if (write(fh, getData(), getSize()) != (signed int) getSize())
64  {
65  close(fh);
66  return false;
67  }
68  close(fh);
69  // Ok
70  return true;
71 }
StdStrBuf::wchar_t_holder GetWideChar(const char *utf8, bool double_null_terminate=false)
#define O_BINARY
Definition: StdBuf.cpp:25
#define O_CLOEXEC
size_t getSize() const
Definition: StdBuf.h:101
const void * getData() const
Definition: StdBuf.h:99
#define O_SEQUENTIAL
Definition: StdBuf.cpp:26
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetAddr()

void C4NetIOPacket::SetAddr ( const C4NetIO::addr_t naddr)
inline

Definition at line 327 of file C4NetIO.h.

References C4NetIO::HostAddress::Clear().

Referenced by C4NetIOUDP::Packet::AddFragment(), C4NetIOSimpleUDP::Execute(), C4NetpuncherPacket::PackTo(), C4Network2IOConnection::Send(), C4NetIOUDP::Peer::Send(), and C4NetIOUDP::SendDirect().

327 { addr = naddr; }
C4NetIO::addr_t addr
Definition: C4NetIO.h:312
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetSize()

void StdBuf::SetSize ( size_t  inSize)
inlineinherited

Definition at line 204 of file StdBuf.h.

References StdBuf::Grow(), and StdBuf::Shrink().

Referenced by StdStrBuf::AppendFormatV(), C4Playback::Check(), StdBuf::CompileFunc(), CStdVectorFont::CStdVectorFont(), C4NetIOSimpleUDP::Execute(), C4NetIOTCP::Peer::GetRecvBuf(), C4Playback::NextSequentialChunk(), C4NetIOTCP::Peer::OnRecv(), PropertyDlgProc(), C4Playback::ReWriteBinary(), and C4Playback::StreamToRecord().

205  {
206  if (inSize > iSize)
207  Grow(inSize - iSize);
208  else
209  Shrink(iSize - inSize);
210  }
void Grow(size_t iGrow)
Definition: StdBuf.h:171
void Shrink(size_t iShrink)
Definition: StdBuf.h:180
unsigned int iSize
Definition: StdBuf.h:92
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Shrink()

void StdBuf::Shrink ( size_t  iShrink)
inlineinherited

Definition at line 180 of file StdBuf.h.

References StdBuf::Copy().

Referenced by C4NetIOTCP::Peer::OnRecv(), StdCompilerINIRead::ReadString(), C4NetIOTCP::Peer::Send(), StdStrBuf::SetLength(), StdBuf::SetSize(), StdStrBuf::Shrink(), and StdStrBuf::SplitAtChar().

181  {
182  assert(iSize >= iShrink);
183  // Shrink dereferences
184  if (fRef) { Copy(iSize - iShrink); return; }
185  if (!iShrink) return;
186  // Realloc
187  pMData = realloc(pMData, iSize -= iShrink);
188  }
void Copy()
Definition: StdBuf.h:233
bool fRef
Definition: StdBuf.h:82
unsigned int iSize
Definition: StdBuf.h:92
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Take() [1/3]

void StdBuf::Take ( void *  pnData,
size_t  inSize 
)
inlineinherited

Definition at line 124 of file StdBuf.h.

References StdBuf::Clear().

Referenced by StdStrBuf::AppendFormatV(), StdStrBuf::CompileFunc(), StdStrBuf::EnsureUnicode(), C4Network2IO::HandlePacket(), StdBuf::operator=(), StdStrBuf::Replace(), StdBuf::StdBuf(), StdBuf::Take(), and StdStrBuf::Take().

125  {
126  Clear();
127  if (pnData)
128  {
129  fRef = false; pMData = pnData; iSize = inSize;
130  }
131  }
void Clear()
Definition: StdBuf.h:190
bool fRef
Definition: StdBuf.h:82
unsigned int iSize
Definition: StdBuf.h:92
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Take() [2/3]

void StdBuf::Take ( StdBuf Buf2)
inlineinherited

Definition at line 276 of file StdBuf.h.

References StdBuf::getSize(), StdBuf::GrabPointer(), and StdBuf::Take().

277  {
278  Take(Buf2.GrabPointer(), Buf2.getSize());
279  }
void Take(void *pnData, size_t inSize)
Definition: StdBuf.h:124
void * GrabPointer()
Definition: StdBuf.h:133
size_t getSize() const
Definition: StdBuf.h:101
Here is the call graph for this function:

◆ Take() [3/3]

void StdBuf::Take ( StdBuf &&  Buf2)
inlineinherited

Definition at line 280 of file StdBuf.h.

References StdBuf::LoadFromFile(), StdBuf::SaveToFile(), and StdBuf::Take().

281  {
282  Take(Buf2.GrabPointer(), Buf2.getSize());
283  }
void Take(void *pnData, size_t inSize)
Definition: StdBuf.h:124
void * GrabPointer()
Definition: StdBuf.h:133
size_t getSize() const
Definition: StdBuf.h:101
Here is the call graph for this function:

◆ Write() [1/2]

void StdBuf::Write ( const void *  pnData,
size_t  inSize,
size_t  iAt = 0 
)
inlineinherited

Definition at line 153 of file StdBuf.h.

References StdBuf::getMPtr().

Referenced by C4NetIOUDP::Packet::AddFragment(), StdBuf::Append(), StdStrBuf::Append(), C4NetIOPacket(), StdBuf::Copy(), C4NetIOUDP::Peer::DoCheck(), C4NetIOUDP::Packet::GetFragment(), C4AulDebug::Listen(), StdBuf::Write(), and C4Network2IRCClient::~C4Network2IRCClient().

154  {
155  assert(iAt + inSize <= iSize);
156  if (pnData && inSize) std::memcpy(getMPtr(iAt), pnData, inSize);
157  }
void * getMPtr(size_t i)
Definition: StdBuf.h:105
unsigned int iSize
Definition: StdBuf.h:92
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Write() [2/2]

void StdBuf::Write ( const StdBuf Buf2,
size_t  iAt = 0 
)
inlineinherited

Definition at line 213 of file StdBuf.h.

References StdBuf::getData(), StdBuf::getSize(), and StdBuf::Write().

214  {
215  Write(Buf2.getData(), Buf2.getSize(), iAt);
216  }
size_t getSize() const
Definition: StdBuf.h:101
const void * getData() const
Definition: StdBuf.h:99
void Write(const void *pnData, size_t inSize, size_t iAt=0)
Definition: StdBuf.h:153
Here is the call graph for this function:

Member Data Documentation

◆ @44

union { ... }

◆ addr

C4NetIO::addr_t C4NetIOPacket::addr
protected

Definition at line 312 of file C4NetIO.h.

Referenced by Clear().

◆ fRef

bool StdBuf::fRef = true
protectedinherited

Definition at line 82 of file StdBuf.h.

Referenced by StdBuf::isRef().

◆ iSize

unsigned int StdBuf::iSize = 0
protectedinherited

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