EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
PyBuffer Class Reference

Python buffer. More...

#include "PyRep.h"

Inheritance diagram for PyBuffer:
Collaboration diagram for PyBuffer:

Public Member Functions

 PyBuffer (size_t len, const uint8 &value)
 
template<typename Iter >
 PyBuffer (Iter first, Iter last)
 
 PyBuffer (const Buffer &buffer)
 
 PyBuffer (Buffer **buffer)
 
 PyBuffer (const PyString &str)
 
 PyBuffer (const PyBuffer &oth)
 
PyRepClone () const
 Clones object. More...
 
bool visit (PyVisitor &v) const
 Visits object. More...
 
const Buffercontent () const
 Get the const PyBuffer content. More...
 
int32 hash () const
 virtual function to generate a hash value of a object. More...
 
size_t size () const
 Obtains length of the buffer. More...
 
- Public Member Functions inherited from PyRep
PyType GetType () const
 
bool IsInt () const
 
bool IsLong () const
 
bool IsFloat () const
 
bool IsBool () const
 
bool IsBuffer () const
 
bool IsString () const
 
bool IsWString () const
 
bool IsToken () const
 
bool IsTuple () const
 
bool IsList () const
 
bool IsDict () const
 
bool IsNone () const
 
bool IsSubStruct () const
 
bool IsSubStream () const
 
bool IsChecksumedStream () const
 
bool IsObject () const
 
bool IsObjectEx () const
 
bool IsPackedRow () const
 
const char * TypeString () const
 
PyIntAsInt ()
 
const PyIntAsInt () const
 
PyLongAsLong ()
 
const PyLongAsLong () const
 
PyFloatAsFloat ()
 
const PyFloatAsFloat () const
 
PyBoolAsBool ()
 
const PyBoolAsBool () const
 
PyBufferAsBuffer ()
 
const PyBufferAsBuffer () const
 
PyStringAsString ()
 
const PyStringAsString () const
 
PyWStringAsWString ()
 
const PyWStringAsWString () const
 
PyTokenAsToken ()
 
const PyTokenAsToken () const
 
PyTupleAsTuple ()
 
const PyTupleAsTuple () const
 
PyListAsList ()
 
const PyListAsList () const
 
PyDictAsDict ()
 
const PyDictAsDict () const
 
PyNoneAsNone ()
 
const PyNoneAsNone () const
 
PySubStructAsSubStruct ()
 
const PySubStructAsSubStruct () const
 
PySubStreamAsSubStream ()
 
const PySubStreamAsSubStream () const
 
PyChecksumedStreamAsChecksumedStream ()
 
const PyChecksumedStreamAsChecksumedStream () const
 
PyObjectAsObject ()
 
const PyObjectAsObject () const
 
PyObjectExAsObjectEx ()
 
const PyObjectExAsObjectEx () const
 
PyPackedRowAsPackedRow ()
 
const PyPackedRowAsPackedRow () const
 
void Dump (FILE *into, const char *pfx) const
 Dumps object to file. More...
 
void Dump (LogType type, const char *pfx) const
 Dumps object to console. More...
 
- Public Member Functions inherited from RefObject
 RefObject (size_t initRefCount)
 Initializes reference count. More...
 
virtual ~RefObject ()
 Destructor; must be virtual. More...
 
size_t GetCount ()
 

Protected Member Functions

virtual ~PyBuffer ()
 
- Protected Member Functions inherited from PyRep
 PyRep (PyType t)
 
 PyRep (const PyRep &oth)
 
 PyRep (PyRep &&oth)=delete
 
PyRepoperator= (const PyRep &oth)=default
 
PyRepoperator= (PyRep &&oth)=default
 
virtual ~PyRep ()
 
- Protected Member Functions inherited from RefObject
void IncRef () const
 Increments reference count of object by one. More...
 
void DecRef () const
 Decrements reference count of object by one. More...
 

Protected Attributes

const Buffer *const mValue
 
int32 mHashCache
 
- Protected Attributes inherited from PyRep
const PyType mType
 
- Protected Attributes inherited from RefObject
size_t mRefCount
 Reference count of instance. More...
 
bool mDeleted
 

Additional Inherited Members

- Public Types inherited from PyRep
enum  PyType {
  PyTypeMin = 0, PyTypeInt = 1, PyTypeLong = 2, PyTypeFloat = 3,
  PyTypeBool = 4, PyTypeBuffer = 5, PyTypeString = 6, PyTypeWString = 7,
  PyTypeToken = 8, PyTypeTuple = 9, PyTypeList = 10, PyTypeDict = 11,
  PyTypeNone = 12, PyTypeSubStruct = 13, PyTypeSubStream = 14, PyTypeChecksumedStream = 15,
  PyTypeObject = 16, PyTypeObjectEx = 17, PyTypePackedRow = 18, PyTypeError = 19
}
 Python wire object types. More...
 
- Static Public Member Functions inherited from PyRep
static std::string StringContent (PyRep *pRep)
 
static int64 IntegerValue (PyRep *pRep)
 
static uint32 IntegerValueU32 (PyRep *pRep)
 

Detailed Description

Python buffer.

Usual binary buffer. This buffer has immutable content; once allocated, it cannot be changed.

Definition at line 382 of file PyRep.h.

Constructor & Destructor Documentation

PyBuffer::PyBuffer ( size_t  len,
const uint8 value 
)

Calls Buffer::Buffer( size_t, const uint8& ).

Definition at line 359 of file PyRep.cpp.

Referenced by Clone().

360 : PyRep( PyRep::PyTypeBuffer ), mValue( new Buffer( len, value ) ), mHashCache( -1 ) {}
Generic class for buffers.
Definition: Buffer.h:40
const Buffer *const mValue
Definition: PyRep.h:421
PyRep(PyType t)
Definition: PyRep.cpp:73
int32 mHashCache
Definition: PyRep.h:422

Here is the caller graph for this function:

template<typename Iter >
PyBuffer::PyBuffer ( Iter  first,
Iter  last 
)
inline

Calls Buffer::Buffer( Iter, Iter ).

Definition at line 1097 of file PyRep.h.

1097 : PyRep( PyRep::PyTypeBuffer ), mValue( new Buffer( first, last ) ), mHashCache( -1 ) {}
Generic class for buffers.
Definition: Buffer.h:40
const Buffer *const mValue
Definition: PyRep.h:421
PyRep(PyType t)
Definition: PyRep.cpp:73
int32 mHashCache
Definition: PyRep.h:422
PyBuffer::PyBuffer ( const Buffer buffer)

Calls Buffer::Buffer( const Buffer& ).

Definition at line 361 of file PyRep.cpp.

362 : PyRep( PyRep::PyTypeBuffer ), mValue( new Buffer( buffer ) ), mHashCache( -1 ) {}
Generic class for buffers.
Definition: Buffer.h:40
const Buffer *const mValue
Definition: PyRep.h:421
PyRep(PyType t)
Definition: PyRep.cpp:73
int32 mHashCache
Definition: PyRep.h:422
PyBuffer::PyBuffer ( Buffer **  buffer)

Takes ownership of a passed Buffer.

Definition at line 364 of file PyRep.cpp.

365 : PyRep( PyRep::PyTypeBuffer ), mValue( *buffer ), mHashCache( -1 ) { *buffer = nullptr; }
const Buffer *const mValue
Definition: PyRep.h:421
PyRep(PyType t)
Definition: PyRep.cpp:73
int32 mHashCache
Definition: PyRep.h:422
PyBuffer::PyBuffer ( const PyString str)

Copy constructor.

Definition at line 366 of file PyRep.cpp.

367 : PyRep( PyRep::PyTypeBuffer ), mValue( new Buffer( str.content().begin(), str.content().end() ) ), mHashCache( -1 ) {}
Generic class for buffers.
Definition: Buffer.h:40
const Buffer *const mValue
Definition: PyRep.h:421
PyRep(PyType t)
Definition: PyRep.cpp:73
const std::string & content() const
Get the PyString content.
Definition: PyRep.h:458
int32 mHashCache
Definition: PyRep.h:422
PyBuffer::PyBuffer ( const PyBuffer oth)

Copy constructor.

Definition at line 368 of file PyRep.cpp.

369 : PyRep( PyRep::PyTypeBuffer ), mValue( new Buffer( buffer.content() ) ), mHashCache( buffer.mHashCache ) {}
Generic class for buffers.
Definition: Buffer.h:40
const Buffer *const mValue
Definition: PyRep.h:421
PyRep(PyType t)
Definition: PyRep.cpp:73
int32 mHashCache
Definition: PyRep.h:422
PyBuffer::~PyBuffer ( )
protectedvirtual

Definition at line 371 of file PyRep.cpp.

References mValue.

372 {
373  delete mValue;
374 }
const Buffer *const mValue
Definition: PyRep.h:421

Member Function Documentation

PyRep * PyBuffer::Clone ( ) const
virtual

Clones object.

Returns
Indentical copy of object.

Implements PyRep.

Definition at line 376 of file PyRep.cpp.

References PyBuffer().

377 {
378  return new PyBuffer( *this );
379 }
PyBuffer(size_t len, const uint8 &value)
Definition: PyRep.cpp:359

Here is the call graph for this function:

const Buffer& PyBuffer::content ( ) const
inline

Get the const PyBuffer content.

Returns
const PyBuffer content

Definition at line 407 of file PyRep.h.

References mValue.

Referenced by PyService::_BuildCachedReturn(), PyTraceLog::_logInternBufferMessage(), CachedObjectMgr::_UpdateCache(), PySubStream::DecodeData(), hash(), size(), PyDumpVisitor::VisitBuffer(), MarshalStream::VisitBuffer(), and MarshalStream::VisitSubStream().

407 { return *mValue; }
const Buffer *const mValue
Definition: PyRep.h:421

Here is the caller graph for this function:

int32 PyBuffer::hash ( ) const
virtual

virtual function to generate a hash value of a object.

virtual function to generate a hash value of a object to facilitate the various maps and checks.

Returns
returns a uint32 containing a hash function that represents the object.

Reimplemented from PyRep.

Definition at line 386 of file PyRep.cpp.

References content(), mHashCache, and Buffer::size().

387 {
388  if (mHashCache != -1 )
389  return mHashCache;
390 
391  int32 len=0, x=0;
392  unsigned char* p(nullptr);
393 
394  /* XXX potential bugs here, a readonly buffer does not imply that the
395  * underlying memory is immutable. b_readonly is a necessary but not
396  * sufficient condition for a buffer to be hashable. Perhaps it would
397  * be better to only allow hashing if the underlying object is known to
398  * be immutable (e.g. PyString_Check() is true). Another idea would
399  * be to call tp_hash on the underlying object and see if it raises
400  * an error. */
401  //if ( !self->b_readonly )
402  //{
403  // PyErr_SetString(PyExc_TypeError,
404  // "writable buffers are not hashable");
405  // return -1;
406  //}
407 
408  //if (!get_buf(self, &ptr, &size, ANY_BUFFER))
409  // return -1;
410  p = (unsigned char *) &content()[0];
411  len = (int32)content().size();
412  x = *p << 7;
413  while( --len >= 0 )
414  x = (1000003*x) ^ *p++;
415  x ^= content().size();
416  if (x == -1)
417  x = -2;
418  mHashCache = x;
419  return x;
420 }
const Buffer & content() const
Get the const PyBuffer content.
Definition: PyRep.h:407
signed __int32 int32
Definition: eve-compat.h:49
size_type size() const
Definition: Buffer.h:610
int32 mHashCache
Definition: PyRep.h:422

Here is the call graph for this function:

size_t PyBuffer::size ( ) const

Obtains length of the buffer.

Returns
Length of buffer.

Definition at line 422 of file PyRep.cpp.

References content(), and Buffer::size().

Referenced by PyTraceLog::_logInternBufferMessage().

423 {
424  return content().size();
425 }
const Buffer & content() const
Get the const PyBuffer content.
Definition: PyRep.h:407
size_type size() const
Definition: Buffer.h:610

Here is the call graph for this function:

Here is the caller graph for this function:

bool PyBuffer::visit ( PyVisitor v) const
virtual

Visits object.

Parameters
[in]vVisitor to be used for visiting.
Return values
trueVisit successful.
falseError during visit.

Implements PyRep.

Definition at line 381 of file PyRep.cpp.

References PyVisitor::VisitBuffer().

382 {
383  return v.VisitBuffer( this );
384 }
virtual bool VisitBuffer(const PyBuffer *rep)
Definition: PyVisitor.h:60

Here is the call graph for this function:

Member Data Documentation

int32 PyBuffer::mHashCache
mutableprotected

Definition at line 422 of file PyRep.h.

Referenced by hash().

const Buffer* const PyBuffer::mValue
protected

Definition at line 421 of file PyRep.h.

Referenced by content(), and ~PyBuffer().


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