Commits

Johannes Kolb committed 3ee9aeb

first experiments with a readonly subclass of Node

Comments (0)

Files changed (3)

osmium/_osm_helper.hpp

+#ifndef OSMIUM_OSM_HELPER_HPP
+#define OSMIUM_OSM_HELPER_HPP
+
+#define TP_ALLOC(t) (*t->tp_alloc)(t, 0)
+
+#endif

osmium/_osm_helper.pxd

+# This is some of cython black magic:
+# 
+# Give access to the tp_alloc method of PyTypeObject. 
+# It is needed to create an object without calling the __cinit__ method
+
+from cpython cimport PyTypeObject, PyObject
+cdef extern from "_osm_helper.hpp":
+    cdef object tp_alloc "TP_ALLOC" (PyTypeObject*)
 from c_osmium.osm cimport ConstObjectPtr, ConstRelationPtr, Object as c_Object, Node as c_Node, TagList as c_TagList, TagListIterator as c_TagListIterator, Way as c_Way, Relation as c_Relation, WayNodeList as c_WayNodeList, WayNodeListIterator as c_WayNodeListIterator, RelationMemberList as c_RelationMemberList, RelationMemberListIterator as c_RelationMemberListIterator, castWayPtr, castRelationPtr
 from cpython.ref cimport PyObject
 
+from cpython cimport PyTypeObject    
+from _osm_helper cimport tp_alloc
 
 # include helper code for working with pointers
 include "osm_ptr.pxi"
 include "osm_meta.pxi"
 
 
+cdef class _RONode(Node):
+    def __init__(self):
+        raise TypeError("Class _RONode is not instanceable from Python")
+
+    def __setattr__(self, name, value):
+        raise AttributeError("attribute '"+name+"' of 'osmium.osm._RONode' objects is not writeable")
+
+cpdef _create_ro_node():
+    cdef _RONode data
+    data = <_RONode>tp_alloc(<PyTypeObject*>_RONode)
+    data.c_object = new ObjectPtr()
+    return data
+
 # keep an object of each type ready
 _cache_node = Node()
 _cache_way = Way()