My Project
Loading...
Searching...
No Matches
PythonCastDynamic Class Reference

This class does conversion of Singular objects to python objects on runtime. More...

Public Member Functions

 PythonCastDynamic (leftv value)
Public Member Functions inherited from PythonObject
 PythonObject ()
 PythonObject (ptr_type ptr)
ptr_type check_context (ptr_type ptr) const
self operator() (int op) const
 Unary operations.
self operator() (int op, const self &arg) const
 Binary and n-ary operations.
self operator() (int op, const self &arg1, const self &arg2) const
 Ternary operations.
self operator[] (const self &idx) const
 Get item.
self operator[] (long idx) const
 operator const ptr_type () const
 Get actual PyObject*.
char * repr () const
 Get representative as C-style string.
char * str () const
 Extract C-style string.
Py_ssize_t size () const
BOOLEAN assign_to (leftv result)
void import_as (const char *name) const
int compare (int op, const self &arg) const
self attr (const self &arg) const
self del_attr (const self &arg) const

Private Types

typedef PythonCastDynamic self

Private Member Functions

PythonObject get (leftv value, int typeId)

Additional Inherited Members

Public Types inherited from PythonObject
typedef PyObject * ptr_type
Protected Member Functions inherited from PythonObject
self args2list (const self &args) const
BOOLEAN handle_exception () const
void append_iter (self iterator)
int py_opid (int op) const

Detailed Description

This class does conversion of Singular objects to python objects on runtime.

Definition at line 339 of file pyobject.cc.

Member Typedef Documentation

◆ self

Definition at line 341 of file pyobject.cc.

Constructor & Destructor Documentation

◆ PythonCastDynamic()

PythonCastDynamic::PythonCastDynamic ( leftv value)
inline

Definition at line 344 of file pyobject.cc.

344: PythonObject(get(value, value->Typ())) {}
PythonObject get(leftv value, int typeId)
Definition pyobject.cc:347
int Typ()
Definition subexpr.cc:1048

Member Function Documentation

◆ get()

PythonObject PythonCastDynamic::get ( leftv value,
int typeId )
inlineprivate

Definition at line 347 of file pyobject.cc.

348 {
349 if (typeId == PythonInterpreter::id()) return PythonCastStatic<>(value);
350
351 switch (typeId)
352 {
353 case INT_CMD: return PythonCastStatic<long>(value);
354 case STRING_CMD: return PythonCastStatic<const char*>(value);
355 case LIST_CMD: return PythonCastStatic<lists>(value);
356 case INTVEC_CMD: return PythonCastStatic<intvec*>(value);
357 }
358
359 sleftv tmp;
360 BOOLEAN newstruct_Assign_user(int, leftv, leftv); // declaring overloaded '='
361 if (!newstruct_Assign_user(PythonInterpreter::id(), &tmp, value))
362 return PythonCastStatic<>(&tmp);
363
364 if (typeId > MAX_TOK) // custom types
365 {
366 blackbox *bbx = getBlackboxStuff(typeId);
367 assume(bbx != NULL);
368 if (! bbx->blackbox_Op1(PythonInterpreter::id(), &tmp, value))
369 return PythonCastStatic<>(&tmp);
370 }
371
372 Werror("type '%s` incompatible with 'pyobject`", iiTwoOps(typeId));
373 return PythonObject();
374 }
int BOOLEAN
Definition auxiliary.h:88
blackbox * getBlackboxStuff(const int t)
return the structure to the type given by t
Definition blackbox.cc:17
static id_type id()
Get Singular type identitfier.
Definition pyobject.cc:56
const char * iiTwoOps(int t)
Definition gentable.cc:258
#define assume(x)
Definition mod2.h:389
BOOLEAN newstruct_Assign_user(int op, leftv l, leftv r)
Definition newstruct.cc:182
#define NULL
Definition omList.c:12
void Werror(const char *fmt,...)
Definition reporter.cc:189
sleftv * leftv
Definition structs.h:53
@ LIST_CMD
Definition tok.h:118
@ INTVEC_CMD
Definition tok.h:101
@ STRING_CMD
Definition tok.h:187
@ INT_CMD
Definition tok.h:96
@ MAX_TOK
Definition tok.h:220

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