resonance 1.0.1
Loading...
Searching...
No Matches
Py::String Class Reference

Handle on a Python string. More...

#include <string.h>

Inheritance diagram for Py::String:
Collaboration diagram for Py::String:

Public Member Functions

 String (PyObject *pyob)
 Take a borrowed reference to an existing string.
 String (const HxStr &text)
 Build a Python string from a game string.
 String (const char *pszText)
 Build a Python string from a C string.
 String (const Object &ob)
 Take another handle's reference as a string.
virtual bool accepts (PyObject *pyob) const
 Accept only a string.
virtual int capacity () const
 Report the sentinel rather than the length.
 operator HxStr () const
 Copy the text out of the Python string.
Public Member Functions inherited from Py::SeqBase< Char >
virtual int max_size () const
 Longest sequence this handle could address.
virtual void swap (SeqBase< Char > &other)
 Exchange references with another handle of the same kind.
virtual int size () const
 Number of elements.
virtual Char getItem (int i) const
 Read one element.
virtual void setItem (int i, const Char &value)
 Write one element.
int length () const
 Number of elements, read without the table.
seqref< Char > 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.

Additional Inherited Members

Public Attributes inherited from Py::Object
PyObject * mPtr
 Wrapped reference, null only between release() and the next assignment.
Protected Member Functions inherited from Py::SeqBase< Char >
 SeqBase ()
 Produce a handle on None for a derived class that fills it in afterwards.
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.

Detailed Description

Handle on a Python string.

Its RTTI descriptor is at 0x008f0990. It has Py::SeqBase<Py::Char> at offset 0 as its one base. Its accessor is at 0x004c65d8.

The vtable at 0x00821cb8 has nine entries, and the type function, the destructor, accepts(), and slot 4 differ from the base table.

Slot Member Address
0 compiler-generated type function 0x004c65d8
1 compiler-generated destructor 0x004c6560
2 accepts 0x004c73a8
3 inherited max_size 0x004c7260
4 capacity 0x004c7270
5 inherited swap 0x004c7890
6 inherited size 0x004c73d0
7 inherited getItem 0x004c7a48
8 inherited setItem 0x004c7bb8

The conversion to HxStr below is one half of the port's substitution of HxStr for std::string. Released PyCXX has the same member returning a std::string.

Constructor & Destructor Documentation

◆ String() [1/4]

Py::String::String ( PyObject * pyob)
inlineexplicit

Take a borrowed reference to an existing string.

Parameters
pyobThe string to wrap.
Ghidra address:
NTSC-U/C: 0x004c4b40
Ghidra address:
PAL: 0x00502dc8

◆ String() [2/4]

Py::String::String ( const HxStr & text)
explicit

Build a Python string from a game string.

The base wraps the result of PyString_FromString() at 0x0059d6b8, stored in a Py::FromAPI temporary, and the body runs validate(). A null game string converts as the empty string. PyShell::ReportError() passes the error context to hxutl.traceback_str this way.

Parameters
textThe text to copy.
Ghidra address:
NTSC-U/C: 0x004c4d88
Ghidra address:
PAL: 0x00503010

◆ String() [3/4]

Py::String::String ( const char * pszText)
explicit

Build a Python string from a C string.

The base wraps the result of PyString_FromString() at 0x0059d6b8, stored in a Py::FromAPI temporary, and the body runs validate(). The pointer arrives at the interpreter unchanged.

Parameters
pszTextThe text to copy.
Ghidra address:
NTSC-U/C: 0x004c5138
Ghidra address:
PAL: 0x005033c0

◆ String() [4/4]

Py::String::String ( const Object & ob)
explicit

Take another handle's reference as a string.

The out-of-line body copies the reference with a count of its own and runs validate() under the Py::Object, SeqBase<Char>, and Py::String vptrs in turn. It belongs to the vendored binding and is not reconstructed.

Parameters
obThe handle to copy.
Ghidra address:
NTSC-U/C: 0x004c4c60
Ghidra address:
PAL: 0x00502ee8

Member Function Documentation

◆ accepts()

virtual bool Py::String::accepts ( PyObject * pyob) const
inlinevirtual

Accept only a string.

Parameters
pyobThe reference to test.
Returns
True when the reference is a string.
Ghidra address:
NTSC-U/C: 0x004c73a8
Ghidra address:
PAL: 0x005055d0

Reimplemented from Py::SeqBase< Char >.

◆ capacity()

virtual int Py::String::capacity ( ) const
inlinevirtual

Report the sentinel rather than the length.

The base returns size(), and this override tail-calls slot 3 instead, so the capacity of a Python string reads as the not-found sentinel. A Python string is immutable, so a capacity equal to its length would invite a caller to write into it.

Returns
The value max_size() reports.
Ghidra address:
NTSC-U/C: 0x004c7270
Ghidra address:
PAL: 0x00505498

Reimplemented from Py::SeqBase< Char >.

◆ operator HxStr()

Py::String::operator HxStr ( ) const
inline

Copy the text out of the Python string.

Returns
The text.
Ghidra address:
NTSC-U/C: 0x004c73f0
Ghidra address:
PAL: 0x00505618

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