resonance 1.0.1
Loading...
Searching...
No Matches
Py::SeqBase< T > Class Template Reference

Handle on any Python sequence, and the base of Py::List, Py::Tuple, and Py::String. More...

#include <seqbase.h>

Inheritance diagram for Py::SeqBase< T >:
Collaboration diagram for Py::SeqBase< T >:

Classes

class  iterator
 Position within a sequence, as PyCXX's SeqBase<T>::iterator is laid out. More...

Public Member Functions

 SeqBase (const Object &ob)
 Take a new reference to an existing object as a sequence.
virtual bool accepts (PyObject *pyob) const
 Accept any reference the sequence protocol supports.
virtual int max_size () const
 Longest sequence this handle could address.
virtual int capacity () const
 Elements this handle could address without reallocating, which is its length.
virtual void swap (SeqBase< T > &other)
 Exchange references with another handle of the same kind.
virtual int size () const
 Number of elements.
virtual T getItem (int i) const
 Read one element.
virtual void setItem (int i, const T &value)
 Write one element.
int length () const
 Number of elements, read without the table.
seqref< T > operator[] (int i)
 Address one element.
iterator begin ()
 Address the first element.
iterator end ()
 Address one past the last element.
Public Member Functions inherited from Py::Object
 Object (PyObject *pyob=Py_None)
 Take a borrowed reference and add a count of its own.
 Object (const Object &other)
 Copy another handle and add a count of its own.
virtual ~Object ()
 Release the reference.
Object & operator= (const Object &other)
 Replace the reference with another handle's.
Object getAttr (const HxStr &name) const
 Read one attribute.
String str () const
 Produce the text of str() applied to the object.
HxStr as_string () const
 Produce the text of str() applied to the object, as a game string.
Type type () const
 Produce the object's type.
bool isType (const Type &type) const
 Report whether the object's type is a given type.
bool isTuple () const
 Report whether the object is a tuple.
bool isList () const
 Report whether the object is a list.

Protected Member Functions

 SeqBase ()
 Produce a handle on None for a derived class that fills it in afterwards.
 SeqBase (PyObject *pyob)
 Take a borrowed reference on behalf of a derived class.
Protected Member Functions inherited from Py::Object
void release ()
 Release the reference and empty the handle.
void set (PyObject *pyob)
 Replace the reference with a borrowed one and add a count of its own.
void validate ()
 Enforce this type's accepts() test on the stored reference.

Additional Inherited Members

Public Attributes inherited from Py::Object
PyObject * mPtr
 Wrapped reference, null only between release() and the next assignment.

Detailed Description

template<typename T>
class Py::SeqBase< T >

Handle on any Python sequence, and the base of Py::List, Py::Tuple, and Py::String.

Two instantiations exist in the image. Py::SeqBase<Py::Object> has its descriptor at 0x00902990, and Py::SeqBase<Py::Char> has its descriptor at 0x00902000. Both derive from Py::Object at offset 0.

The vtable has nine entries, the three Py::Object slots plus six of its own. The six below are declared in table order, and that order is itself corroboration: released PyCXX declares max_size, capacity, swap, and size in exactly this sequence ahead of the element accessors.

Slot Member SeqBase<Object> SeqBase<Char>
0 compiler-generated type function 0x0012abd0 0x004c64e8
1 inherited destructor 0x0012ab58 0x004c6470
2 accepts 0x0012b328 0x004c7c30
3 max_size 0x0012ad48 0x004c7260
4 capacity 0x0012b378 0x004c7c80
5 swap 0x0012b3a0 0x004c7890
6 size 0x0012b358 0x004c73d0
7 getItem 0x0012ac48 0x004c7a48
8 setItem 0x0012b4d0 0x004c7bb8

The three vtables for SeqBase<Object> at 0x007d0ff0, 0x00821c68, and 0x00825878 are identical copies that the linker did not fold. SeqBase<Char> sits at 0x00821d08.

Constructor & Destructor Documentation

◆ SeqBase() [1/3]

template<typename T>
Py::SeqBase< T >::SeqBase ( )
inlineprotected

Produce a handle on None for a derived class that fills it in afterwards.

The body is empty, which is what the folded vptr write in a derived default constructor establishes. This compiler omits the intermediate vptr store when the intermediate constructor runs no code between the two stores.

◆ SeqBase() [2/3]

template<typename T>
Py::SeqBase< T >::SeqBase ( PyObject * pyob)
inlineexplicitprotected

Take a borrowed reference on behalf of a derived class.

Recovered from Py::Tuple's constructor at 0x004c5448, where the three vptr stores and the three validate() calls of the chain are all visible in one routine.

Parameters
pyobThe reference to wrap.

◆ SeqBase() [3/3]

template<typename T>
Py::SeqBase< T >::SeqBase ( const Object & ob)
inlineexplicit

Take a new reference to an existing object as a sequence.

Inline. The configuration queries at 0x00509b78 and 0x0050a1a0 expand it as Object's copy, Object's validate(), the store of this class's vptr, and this class's validate(). MetNullRenderer::OnRawController() at 0x0030e4c0 expands it the same way, with the 0x007d0ff0 vptr.

Parameters
obThe object to wrap.

Member Function Documentation

◆ accepts()

template<typename T>
virtual bool Py::SeqBase< T >::accepts ( PyObject * pyob) const
inlinevirtual

Accept any reference the sequence protocol supports.

Parameters
pyobThe reference to test.
Returns
True when the reference is a sequence.
Ghidra address:
NTSC-U/C: 0x0012b328
Ghidra address:
PAL: 0x0012ba60
Ghidra address:
NTSC-U/C: 0x004c7c30
Ghidra address:
PAL: 0x00505e58

Reimplemented from Py::Object.

Reimplemented in Py::List, Py::String, and Py::Tuple.

◆ max_size()

template<typename T>
virtual int Py::SeqBase< T >::max_size ( ) const
virtual

Longest sequence this handle could address.

The routine is three instructions and loads one word, the shared not-found sentinel at 0x008211bc, which is 0xffffffff. That word sits in HxStr's own literal pool, one word past the empty string the string class returns for a null buffer, and four routines outside the binding read it as well, among them RndText::BuildGlyphMesh(). It is HxStr's npos, and released PyCXX returns std::string::npos from the same member, which is what settles the reading.

The bodies are explicit specialisations that read the sentinel from os/hxstr.h.

Returns
The sentinel.
Ghidra address:
NTSC-U/C: 0x0012ad48
Ghidra address:
PAL: 0x0012b480
Ghidra address:
NTSC-U/C: 0x004c7260
Ghidra address:
PAL: 0x00505488

◆ capacity()

template<typename T>
virtual int Py::SeqBase< T >::capacity ( ) const
inlinevirtual

Elements this handle could address without reallocating, which is its length.

The routine tail-calls slot 6 through the table, so the value tracks size() in a derived class that narrows either one. Py::String overrides it to return max_size() instead.

Returns
The length.
Ghidra address:
NTSC-U/C: 0x0012b378
Ghidra address:
PAL: 0x0012bab0
Ghidra address:
NTSC-U/C: 0x004c7c80
Ghidra address:
PAL: 0x00505ea8

Reimplemented in Py::List, and Py::String.

◆ swap()

template<typename T>
virtual void Py::SeqBase< T >::swap ( SeqBase< T > & other)
virtual

Exchange references with another handle of the same kind.

Copies the argument into a temporary handle, gives the argument this handle's reference unless the two already match, and then takes the temporary's reference through set(). Each set() runs validate(). A reference the receiving type rejects throws.

Parameters
otherThe handle to exchange with.
Ghidra address:
NTSC-U/C: 0x0012b3a0
Ghidra address:
PAL: 0x0012bad8
Ghidra address:
NTSC-U/C: 0x004c7890
Ghidra address:
PAL: 0x00505ab8

◆ size()

template<typename T>
virtual int Py::SeqBase< T >::size ( ) const
virtual

Number of elements.

The two instantiations do not share a body, and that is the one finding here worth pausing on. SeqBase<Object> calls PySequence_Length() at 0x004a53f0 and SeqBase<Char> calls PyString_Size() at 0x005a1ca0, so a single template body cannot produce both. Whether the port wrote an explicit specialisation or routed the call through the element type is not recovered. The bodies are explicit specialisations.

Returns
The length.
Ghidra address:
NTSC-U/C: 0x0012b358
Ghidra address:
PAL: 0x0012ba90
Ghidra address:
NTSC-U/C: 0x004c73d0
Ghidra address:
PAL: 0x005055f8

◆ getItem()

template<typename T>
virtual T Py::SeqBase< T >::getItem ( int i) const
inlinevirtual

Read one element.

The new reference from the interpreter is adopted through a Py::FromAPI temporary, so the returned handle owns exactly one count.

Parameters
iThe index.
Returns
A handle on the element.
Ghidra address:
NTSC-U/C: 0x0012ac48
Ghidra address:
PAL: 0x0012b380
Ghidra address:
NTSC-U/C: 0x004c7a48
Ghidra address:
PAL: 0x00505c70

◆ setItem()

template<typename T>
virtual void Py::SeqBase< T >::setItem ( int i,
const T & value )
inlinevirtual

Write one element.

Parameters
iThe index.
valueThe element to store.
Ghidra address:
NTSC-U/C: 0x0012b4d0
Ghidra address:
PAL: 0x0012bc08
Ghidra address:
NTSC-U/C: 0x004c7bb8
Ghidra address:
PAL: 0x00505de0

Reimplemented in Py::Tuple.

◆ length()

template<typename T>
int Py::SeqBase< T >::length ( ) const
inline

Number of elements, read without the table.

Inline. Unlike size(), the call goes straight to PySequence_Length() at 0x004a53f0, which is how MetHelpScreen::FillTexts() at 0x00313208 expands it.

Returns
The length.

◆ operator[]()

template<typename T>
seqref< T > Py::SeqBase< T >::operator[] ( int i)
inline

Address one element.

Inline. The proxy fetches the element through getItem() as it is built.

Parameters
iThe index.
Returns
A proxy for the element.

◆ begin()

template<typename T>
iterator Py::SeqBase< T >::begin ( )
inline

Address the first element.

Returns
An iterator at index 0.

◆ end()

template<typename T>
iterator Py::SeqBase< T >::end ( )
inline

Address one past the last element.

Returns
An iterator at length().

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