Hurricane VLSI Database


Static Public Member Functions | List of all members
Isobar::PythonAttributes Class Reference

A Property to store Python objects (API). More...

Static Public Member Functions

static PyAttributesHolderget (const DBo *)
 
static int32_t delattr (DBo *, std::string)
 
static void enable (DBo *)
 
static void disable (DBo *)
 
static void disableAll ()
 
static void disableAll (std::string)
 

Detailed Description

A Property to store Python objects (API).

Introduction

The problem to solve here is how to decorate a DBo in Python code. In the C++ realm, Hurricane provides the Property mechanism. But a Property is a template that needs to be defined at compile time, whether a Python object is only known at run time.

So, instead of trying to create one property per Python attribute, we create one PyHolderProperty property, which has one PyAttributesHolder attribute (a basic derived class of PyObject with only a dictionnary). All the Python attributes of the DBo are then stored as attributes of PyAttributesHolder.

Finally, to make the Python syntax straigthforward, we modify the PyTypeEntity.tp_setatto and PyTypeEntity.tp_getattro so that when trying to access an attribute, we get redirected towards the PyAttributesHolder (which is another PyObject). So we can write the following code:

class MyAttribute ( object ):
count = 0
def __init__ ( self ):
self.value = MyAttribute.count
print( '{} has been created'.format(self) )
MyAttribute.count += 1
def __del__ ( self ):
print( '{} has been deleted'.format(self) )
def __str__ ( self ):
return '<MyAttribute {}>'.format(self.value)
def demoAttributes ( cell ):
PythonAttributes.enable( cell )
cell.myAttribute0 = MyAttribute()
cell.myAttribute1 = MyAttribute()
print( 'cell.myAttribute0 =', cell.myAttribute0 )
del cell.myAttribute0
PythonAttributes.disableAll()

Some interresting references concerning the Python/C API:

Member Function Documentation

◆ get()

PyAttributesHolder * Isobar::PythonAttributes::get ( const DBo )
static

Retrieve the Python attributes holder of the DBo. If there is none, return NULL.

\Remark This is the Python property holder (PyAttributesHolder), not the property itself which is returned.

◆ delattr()

int32_t Isobar::PythonAttributes::delattr ( DBo dbo,
std::string  attrName 
)
static

Remove the attribute named attrName from dbo.

◆ enable()

void Isobar::PythonAttributes::enable ( DBo dbo)
static

Create the PyHolderProperty on dbo. This operation is mandatory before one can add attributes on a DBo.

◆ disable()

void Isobar::PythonAttributes::disable ( DBo dbo)
static

Remove the PyHolderProperty from dbo. The refcount of all the Python attributes will be decremented. So if they are only referenced in the PyHolderProperty, that means they will be deleted.

◆ disableAll() [1/2]

void Isobar::PythonAttributes::disableAll ( )
static

Remove the PyHolderProperty from all the DBo.

◆ disableAll() [2/2]

void Isobar::PythonAttributes::disableAll ( std::string  attrName)
static

Remove the attribute named attrName on all the DBo, if, after deletion, no attributes remains the PyHolderProperty is removed.


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


Generated by doxygen 1.9.1 on Fri Oct 4 2024 Return to top of page
Hurricane VLSI Database Copyright © 2000-2020 Bull S.A. All rights reserved