#11 Py::LongLong new class to support: uint64 - int64

closed
nobody
None
5
2007-01-06
2006-05-27
Anonymous
No

Enclosed is the file for newly created class
Py::LongLong.

This clas will support data types:

- long long
- unsigned long long

Tested and works fully.

Shall be added into Objects.HXX after-before Py::Long
class declaration.

Regards, Dmitry K. (Kosuha)
--------------------------------------------

// ===============================================
// class LongLong
class LongLong: public Object
{
public:
// Constructor
explicit LongLong (PyObject *pyob,
bool owned = false): Object (pyob, owned)
{
validate();
}

LongLong (const LongLong& ob): Object
(ob.ptr())
{
validate();
}
// create from long long
explicit LongLong (long long v = 0L)
: Object(PyLong_FromLongLong
(v), true)
{
validate();
}
// create from unsigned long long
explicit LongLong (unsigned long long
v)
: Object
(PyLong_FromUnsignedLongLong(v), true)
{
validate();
}
// create from long
explicit LongLong (long v)
: Object(PyLong_FromLongLong
(v), true)
{
validate();
}
// create from unsigned long
explicit LongLong (unsigned long v)
: Object
(PyLong_FromUnsignedLongLong(v), true)
{
validate();
}
// create from int
explicit LongLong (int v)
: Object(PyLong_FromLongLong
(static_cast<long long>(v)), true)
{
validate();
}

// try to create from any object
LongLong (const Object& ob)
: Object(PyNumber_Long(*ob),
true)
{
validate();
}

// Assignment acquires new ownership
of pointer

LongLong& operator= (const Object&
rhs)
{
return (*this = *rhs);
}

LongLong& operator= (PyObject* rhsp)
{
if(ptr() == rhsp) return
*this;
set (PyNumber_Long(rhsp),
true);
return *this;
}
// Membership
virtual bool accepts (PyObject *pyob)
const
{
return pyob &&
Py::_Long_Check (pyob);
}
// convert to long long
operator long long() const
{
return PyLong_AsLongLong (ptr
());
}
// convert to unsigned long
operator unsigned long long() const
{
return
PyLong_AsUnsignedLongLong (ptr());
}
// convert to long
operator long() const
{
return PyLong_AsLong (ptr());
}
// convert to unsigned
operator unsigned long() const
{
return PyLong_AsUnsignedLong
(ptr());
}
operator double() const
{
return PyLong_AsDouble (ptr
());
}
// assign from an int
LongLong& operator= (int v)
{
set(PyLong_FromLongLong (long
(v)), true);
return *this;
}
// assign from long long
LongLong& operator= (long long v)
{
set(PyLong_FromLongLong (v),
true);
return *this;
}
// assign from unsigned long long
LongLong& operator= (unsigned long
long v)
{
set
(PyLong_FromUnsignedLongLong (v), true);
return *this;
}
// assign from long
LongLong& operator= (long v)
{
set(PyLong_FromLongLong (v),
true);
return *this;
}
// assign from unsigned long
LongLong& operator= (unsigned long v)
{
set
(PyLong_FromUnsignedLongLong (v), true);
return *this;
}
};

Discussion

  • Py::LongLong new class to support: uint64 - int64

     
    Attachments
    • status: open --> closed
     
  • Logged In: YES
    user_id=28665
    Originator: NO

    later patch applied.