Skip to content

Commit 5942ac7

Browse files
committed
add Field based classes for future write support
1 parent 452e236 commit 5942ac7

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

pxpy.pyx

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -328,16 +328,30 @@ cdef class Table(PXDoc):
328328

329329
return self.record.read(recno)
330330

331-
cdef class Field:
331+
cdef class ParadoxField:
332+
cdef readonly fname
333+
cdef readonly ftype
334+
cdef readonly flen
335+
336+
def __cinit__(self, *args):
337+
print 'ParadoxField cinit', args
338+
339+
def _init_fields(self, fname, int ftype, int flen):
340+
print 'ParadoxField _init_fields', fname, ftype, flen
341+
self.fname = fname
342+
self.ftype = ftype
343+
self.flen = flen
344+
345+
def __init__(self, fname, int ftype, int flen):
346+
self._init_fields(fname, ftype, flen)
347+
348+
cdef class RecordField(ParadoxField):
332349
"""
333350
Represent a single field of a Record associated to some Table.
334351
"""
335352

336353
cdef void *data
337354
cdef Record record
338-
cdef readonly fname
339-
cdef readonly ftype
340-
cdef readonly flen
341355

342356
def __init__(self, Record record, int index, int offset):
343357
"""
@@ -347,10 +361,11 @@ cdef class Field:
347361
"""
348362

349363
self.record = record
350-
self.fname = record.table.doc.px_head.px_fields[index].px_fname
351-
self.ftype = record.table.doc.px_head.px_fields[index].px_ftype
352364
self.data = record.data+offset
353-
self.flen = record.table.doc.px_head.px_fields[index].px_flen
365+
ParadoxField.__init__(self,
366+
record.table.doc.px_head.px_fields[index].px_fname,
367+
record.table.doc.px_head.px_fields[index].px_ftype,
368+
record.table.doc.px_head.px_fields[index].px_flen)
354369

355370
def getValue(self):
356371
"""
@@ -493,7 +508,7 @@ cdef class Record:
493508
self.fields = []
494509
offset = 0
495510
for i in range(self.getFieldsCount()):
496-
field = Field(self, i, offset)
511+
field = RecordField(self, i, offset)
497512
self.fields.append(field)
498513
offset = offset + table.doc.px_head.px_fields[i].px_flen
499514

0 commit comments

Comments
 (0)