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

Python long integer. More...

#include "PyRep.h"

Inheritance diagram for PyLong:
Collaboration diagram for PyLong:

Public Member Functions

 PyLong (const int64 i)
 
 PyLong (const PyLong &oth)
 
 PyLong (PyLong &&oth)=delete
 
PyLongoperator= (const PyLong &oth)=delete
 
PyLongoperator= (PyLong &&oth)=delete
 
PyRepClone () const
 Clones object. More...
 
bool visit (PyVisitor &v) const
 Visits object. More...
 
int64 value () const
 
int32 hash () const
 virtual function to generate a hash value of a object. 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 ~PyLong ()
 
- 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 int64 mValue
 
- 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 long integer.

Class representing 64-bit signed integer.

Definition at line 261 of file PyRep.h.

Constructor & Destructor Documentation

PyLong::PyLong ( const int64  i)

Definition at line 179 of file PyRep.cpp.

Referenced by Clone().

179 : PyRep( PyRep::PyTypeLong ), mValue( i ) {}
const int64 mValue
Definition: PyRep.h:284
PyRep(PyType t)
Definition: PyRep.cpp:73

Here is the caller graph for this function:

PyLong::PyLong ( const PyLong oth)

Definition at line 180 of file PyRep.cpp.

180 : PyRep( PyRep::PyTypeLong ), mValue( oth.value() ) {}
const int64 mValue
Definition: PyRep.h:284
int64 value() const
Definition: PyRep.h:278
PyRep(PyType t)
Definition: PyRep.cpp:73
PyLong::PyLong ( PyLong &&  oth)
delete
virtual PyLong::~PyLong ( )
inlineprotectedvirtual

Definition at line 283 of file PyRep.h.

283 { /* do we need to do anything here? */ }

Member Function Documentation

PyRep * PyLong::Clone ( ) const
virtual

Clones object.

Returns
Indentical copy of object.

Implements PyRep.

Definition at line 182 of file PyRep.cpp.

References PyLong().

183 {
184  return new PyLong( *this );
185 }
PyLong(const int64 i)
Definition: PyRep.cpp:179

Here is the call graph for this function:

int32 PyLong::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 192 of file PyRep.cpp.

References LONG_BIT_PyLong_SHIFT, mValue, and PyLong_MASK.

193 {
194 #define PyLong_SHIFT 15
195 #define PyLong_BASE (1 << PyLong_SHIFT)
196 #define PyLong_MASK ((int)(PyLong_BASE - 1))
197 
198 #define LONG_BIT_PyLong_SHIFT (8*sizeof(long) - PyLong_SHIFT)
199 
200  long x=0;
201  int i=8, sign=1;
202 
203  /* This is designed so that Python ints and longs with the
204  same value hash to the same value, otherwise comparisons
205  of mapping keys will turn out weird */
206  if (i < 0 ) {
207  sign = -1;
208  i = -(i);
209  }
210  /* The following loop produces a C long x such that (unsigned long)x
211  is congruent to the absolute value of v modulo ULONG_MAX. The
212  resulting x is nonzero if and only if v is. */
213  while( --i >= 0 ) {
214  /* Force a native long #-bits (32 or 64) circular shift */
215  x = ((x << PyLong_SHIFT) & ~PyLong_MASK) | ((x >> LONG_BIT_PyLong_SHIFT) & PyLong_MASK);
216  x += ((uint8*)&mValue)[i];// v->ob_digit[i];
217  /* If the addition above overflowed (thinking of x as
218  unsigned), we compensate by incrementing. This preserves
219  the value modulo ULONG_MAX. */
220  if ((unsigned long)x < ((uint8*)&mValue)[i] )//v->ob_digit[i])
221  x++;
222  }
223  x = x * sign;
224  if (x == -1 )
225  x = -2;
226  return x;
227 
228 #undef PyLong_SHIFT
229 #undef PyLong_BASE
230 #undef PyLong_MASK
231 
232 #undef LONG_BIT_PyLong_SHIFT
233 }
unsigned __int8 uint8
Definition: eve-compat.h:46
#define LONG_BIT_PyLong_SHIFT
const int64 mValue
Definition: PyRep.h:284
#define PyLong_MASK
PyLong& PyLong::operator= ( const PyLong oth)
delete
PyLong& PyLong::operator= ( PyLong &&  oth)
delete
int64 PyLong::value ( ) const
inline

Definition at line 278 of file PyRep.h.

References mValue.

Referenced by PyRep::IntegerValue(), PyRep::IntegerValueU32(), MarshalStream::SaveVarInteger(), PyDumpVisitor::VisitLong(), and MarshalStream::VisitPackedRow().

278 { return mValue; }
const int64 mValue
Definition: PyRep.h:284

Here is the caller graph for this function:

bool PyLong::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 187 of file PyRep.cpp.

References PyVisitor::VisitLong().

188 {
189  return v.VisitLong( this );
190 }
virtual bool VisitLong(const PyLong *rep)
Definition: PyVisitor.h:56

Here is the call graph for this function:

Member Data Documentation

const int64 PyLong::mValue
protected

Definition at line 284 of file PyRep.h.

Referenced by hash(), and value().


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