~ubuntu-branches/ubuntu/trusty/silo-llnl/trusty

« back to all changes in this revision

Viewing changes to tools/python/pydbfile.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alastair McKinstry
  • Date: 2011-01-02 00:03:01 UTC
  • Revision ID: james.westby@ubuntu.com-20110102000301-9s2hfsjrkguz6h4r
Tags: upstream-4.8
ImportĀ upstreamĀ versionĀ 4.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) 1994 - 2010, Lawrence Livermore National Security, LLC.
 
2
// LLNL-CODE-425250.
 
3
// All rights reserved.
 
4
// 
 
5
// This file is part of Silo. For details, see silo.llnl.gov.
 
6
// 
 
7
// Redistribution and use in source and binary forms, with or without
 
8
// modification, are permitted provided that the following conditions
 
9
// are met:
 
10
// 
 
11
//    * Redistributions of source code must retain the above copyright
 
12
//      notice, this list of conditions and the disclaimer below.
 
13
//    * Redistributions in binary form must reproduce the above copyright
 
14
//      notice, this list of conditions and the disclaimer (as noted
 
15
//      below) in the documentation and/or other materials provided with
 
16
//      the distribution.
 
17
//    * Neither the name of the LLNS/LLNL nor the names of its
 
18
//      contributors may be used to endorse or promote products derived
 
19
//      from this software without specific prior written permission.
 
20
// 
 
21
// THIS SOFTWARE  IS PROVIDED BY  THE COPYRIGHT HOLDERS  AND CONTRIBUTORS
 
22
// "AS  IS" AND  ANY EXPRESS  OR IMPLIED  WARRANTIES, INCLUDING,  BUT NOT
 
23
// LIMITED TO, THE IMPLIED  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 
24
// A  PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN  NO  EVENT SHALL  LAWRENCE
 
25
// LIVERMORE  NATIONAL SECURITY, LLC,  THE U.S.  DEPARTMENT OF  ENERGY OR
 
26
// CONTRIBUTORS BE LIABLE FOR  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 
27
// EXEMPLARY, OR  CONSEQUENTIAL DAMAGES  (INCLUDING, BUT NOT  LIMITED TO,
 
28
// PROCUREMENT OF  SUBSTITUTE GOODS  OR SERVICES; LOSS  OF USE,  DATA, OR
 
29
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 
30
// LIABILITY, WHETHER  IN CONTRACT, STRICT LIABILITY,  OR TORT (INCLUDING
 
31
// NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT  OF THE USE  OF THIS
 
32
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
33
// 
 
34
// This work was produced at Lawrence Livermore National Laboratory under
 
35
// Contract  No.   DE-AC52-07NA27344 with  the  DOE.  Neither the  United
 
36
// States Government  nor Lawrence  Livermore National Security,  LLC nor
 
37
// any of  their employees,  makes any warranty,  express or  implied, or
 
38
// assumes   any   liability   or   responsibility  for   the   accuracy,
 
39
// completeness, or usefulness of any information, apparatus, product, or
 
40
// process  disclosed, or  represents  that its  use  would not  infringe
 
41
// privately-owned   rights.  Any  reference   herein  to   any  specific
 
42
// commercial products,  process, or  services by trade  name, trademark,
 
43
// manufacturer or otherwise does not necessarily constitute or imply its
 
44
// endorsement,  recommendation,   or  favoring  by   the  United  States
 
45
// Government or Lawrence Livermore National Security, LLC. The views and
 
46
// opinions  of authors  expressed  herein do  not  necessarily state  or
 
47
// reflect those  of the United  States Government or  Lawrence Livermore
 
48
// National  Security, LLC,  and shall  not  be used  for advertising  or
 
49
// product endorsement purposes.
 
50
 
 
51
#include "pydbfile.h"
 
52
#include "pydbtoc.h"
 
53
#include "pysilo.h"
 
54
 
 
55
// ****************************************************************************
 
56
//  Method:  DBfile_DBGetToc
 
57
//
 
58
//  Purpose:
 
59
//    Encapsulates DBGetToc
 
60
//
 
61
//  Python Arguments:
 
62
//    none
 
63
//
 
64
//  Programmer:  Jeremy Meredith
 
65
//  Creation:    July 12, 2005
 
66
//
 
67
// ****************************************************************************
 
68
static PyObject *DBfile_DBGetToc(PyObject *self, PyObject *args)
 
69
{
 
70
    DBfileObject *obj = (DBfileObject*)self;
 
71
 
 
72
    if (!obj->db)
 
73
    {
 
74
        SiloErrorFunc("This file has been closed.");
 
75
        return NULL;
 
76
    }
 
77
 
 
78
    DBtoc *toc = DBGetToc(obj->db);
 
79
 
 
80
    DBtocObject *retval = PyObject_NEW(DBtocObject, &DBtocType);
 
81
    if (retval)
 
82
    {
 
83
        retval->toc = toc;
 
84
    }
 
85
    return (PyObject*)retval;
 
86
}
 
87
 
 
88
// ****************************************************************************
 
89
//  Method:  DBfile_DBGetVar
 
90
//
 
91
//  Purpose:
 
92
//    Encapsulates DBGetVar
 
93
//
 
94
//  Python Arguments:
 
95
//    form 1: varname
 
96
//
 
97
//  Programmer:  Jeremy Meredith
 
98
//  Creation:    July 12, 2005
 
99
//
 
100
//  Modifications:
 
101
//
 
102
//    Mark C. Miller, Tue Aug  5 11:04:14 PDT 2008
 
103
//    I modifed case where we're returning a string valued variable to strip
 
104
//    off the trailing null character. The PyString_FromStringAndSize method
 
105
//    was being given a length argument that included the trailing null and
 
106
//    the result was a bit if an odd string in python.
 
107
//
 
108
// ****************************************************************************
 
109
static PyObject *DBfile_DBGetVar(PyObject *self, PyObject *args)
 
110
{
 
111
    DBfile *db = ((DBfileObject*)self)->db;
 
112
 
 
113
    if (!db)
 
114
    {
 
115
        SiloErrorFunc("This file has been closed.");
 
116
        return NULL;
 
117
    }
 
118
 
 
119
    char *str;
 
120
    if(!PyArg_ParseTuple(args, "s", &str))
 
121
        return NULL;
 
122
 
 
123
    int vartype = DBInqVarType(db, str);
 
124
    if (vartype != DB_VARIABLE)
 
125
    {
 
126
        SiloErrorFunc("Only flat variables are supported.");
 
127
        return NULL;
 
128
    }
 
129
 
 
130
    int len = DBGetVarLength(db,str);
 
131
    int type = DBGetVarType(db,str);
 
132
    void *var = DBGetVar(db,str);
 
133
    if (len == 1 || type == DB_CHAR)
 
134
    {
 
135
        switch (type)
 
136
        {
 
137
          case DB_INT:
 
138
            return PyInt_FromLong(*((int*)var));
 
139
          case DB_SHORT:
 
140
            return PyInt_FromLong(*((short*)var));
 
141
          case DB_LONG:
 
142
            return PyInt_FromLong(*((long*)var));
 
143
          case DB_FLOAT:
 
144
            return PyFloat_FromDouble(*((float*)var));
 
145
          case DB_DOUBLE:
 
146
            return PyFloat_FromDouble(*((double*)var));
 
147
          case DB_CHAR:
 
148
            if (len == 1)
 
149
                return PyInt_FromLong(*((char*)var));
 
150
            else
 
151
            {
 
152
                // strip trailing null if one exists
 
153
                char *p = (char *) var;
 
154
                if (p[len-1] == '\0') len--;
 
155
                return PyString_FromStringAndSize((char*)var, len);
 
156
            }
 
157
          default:
 
158
            SiloErrorFunc("Unknown variable type.");
 
159
            return NULL;
 
160
        }
 
161
    }
 
162
    else
 
163
    {
 
164
        PyObject *retval = PyTuple_New(len);
 
165
        for (int i=0; i<len; i++)
 
166
        {    
 
167
            PyObject *tmp;
 
168
            switch (type)
 
169
            {
 
170
              case DB_INT:
 
171
                tmp = PyInt_FromLong(((int*)var)[i]);
 
172
                break;
 
173
              case DB_SHORT:
 
174
                tmp = PyInt_FromLong(((short*)var)[i]);
 
175
                break;
 
176
              case DB_LONG:
 
177
                tmp = PyInt_FromLong(((long*)var)[i]);
 
178
                break;
 
179
              case DB_FLOAT:
 
180
                tmp = PyFloat_FromDouble(((float*)var)[i]);
 
181
                break;
 
182
              case DB_DOUBLE:
 
183
                tmp = PyFloat_FromDouble(((double*)var)[i]);
 
184
                break;
 
185
              case DB_CHAR:
 
186
                tmp = PyInt_FromLong(((char*)var)[i]);
 
187
                break;
 
188
              default:
 
189
                SiloErrorFunc("Unknown variable type.");
 
190
                return NULL;
 
191
            }
 
192
            PyTuple_SET_ITEM(retval, i, tmp);
 
193
        }
 
194
        return retval;
 
195
    }
 
196
}
 
197
 
 
198
// ****************************************************************************
 
199
//  Method:  DBfile_DBGetVar
 
200
//
 
201
//  Purpose:
 
202
//    Encapsulates DBGetVar
 
203
//
 
204
//  Python Arguments:
 
205
//    form 1: varname, integer
 
206
//    form 2: varname, real
 
207
//    form 3: varname, string
 
208
//    form 4: varname, tuple
 
209
//
 
210
//  Programmer:  Jeremy Meredith
 
211
//  Creation:    July 12, 2005
 
212
//
 
213
// ****************************************************************************
 
214
static PyObject *DBfile_DBWrite(PyObject *self, PyObject *args)
 
215
{
 
216
    DBfile *db = ((DBfileObject*)self)->db;
 
217
 
 
218
    if (!db)
 
219
    {
 
220
        SiloErrorFunc("This file has been closed.");
 
221
        return NULL;
 
222
    }
 
223
 
 
224
    int dims;
 
225
    int err;
 
226
    char *str;
 
227
 
 
228
    int ivar;
 
229
    double dvar;
 
230
    char *svar;
 
231
    PyObject *tuple;
 
232
    if (PyArg_ParseTuple(args, "si", &str, &ivar) &&
 
233
        PyArg_ParseTuple(args, "sd", &str, &dvar))
 
234
    {
 
235
        dims = 1;
 
236
        if (ivar == dvar)
 
237
        {
 
238
            err = DBWrite(db, str, &ivar, &dims,1, DB_INT);
 
239
        }
 
240
        else
 
241
        {
 
242
            err = DBWrite(db, str, &dvar, &dims,1, DB_DOUBLE);
 
243
        }
 
244
    }
 
245
    else if (PyArg_ParseTuple(args, "si", &str, &ivar))
 
246
    {
 
247
        dims = 1;
 
248
        err = DBWrite(db, str, &ivar, &dims,1, DB_INT);
 
249
    }
 
250
    else if (PyArg_ParseTuple(args, "sd", &str, &dvar))
 
251
    {
 
252
        dims = 1;
 
253
        err = DBWrite(db, str, &dvar, &dims,1, DB_DOUBLE);
 
254
    }
 
255
    else if (PyArg_ParseTuple(args, "ss", &str, &svar))
 
256
    {
 
257
        dims = strlen(svar);
 
258
        err = DBWrite(db, str, svar, &dims,1, DB_CHAR);
 
259
    }
 
260
    else if (PyArg_ParseTuple(args, "sO", &str, &tuple))
 
261
    {
 
262
        if(!PyTuple_Check(tuple))
 
263
            return NULL;
 
264
 
 
265
        int len = PyTuple_Size(tuple);
 
266
        if (len < 1)
 
267
        {
 
268
            PyErr_SetString(PyExc_TypeError, "Tuple must be of size > 0");
 
269
            return NULL;
 
270
        }
 
271
 
 
272
        PyObject *item = PyTuple_GET_ITEM(tuple, 0);
 
273
        if (PyInt_Check(item))
 
274
        {
 
275
            int *values = new int[len];
 
276
            for (int i=0; i<len; i++)
 
277
            {
 
278
                item = PyTuple_GET_ITEM(tuple, i);
 
279
                if (PyInt_Check(item))
 
280
                    values[i] = int(PyInt_AS_LONG(PyTuple_GET_ITEM(tuple, i)));
 
281
                else if (PyFloat_Check(item))
 
282
                    values[i] = int(PyFloat_AS_DOUBLE(PyTuple_GET_ITEM(tuple, i)));
 
283
                else
 
284
                {
 
285
                    PyErr_SetString(PyExc_TypeError,
 
286
                                    "Only int or float tuples are supported");
 
287
                    return NULL;
 
288
                }
 
289
            }
 
290
 
 
291
            dims = len;
 
292
            err = DBWrite(db, str, values, &len,1, DB_INT);
 
293
        }
 
294
        else if (PyFloat_Check(item))
 
295
        {
 
296
            double *values = new double[len];
 
297
            for (int i=0; i<len; i++)
 
298
            {
 
299
                item = PyTuple_GET_ITEM(tuple, i);
 
300
                if (PyInt_Check(item))
 
301
                    values[i] = double(PyInt_AS_LONG(PyTuple_GET_ITEM(tuple, i)));
 
302
                else if (PyFloat_Check(item))
 
303
                    values[i] = double(PyFloat_AS_DOUBLE(PyTuple_GET_ITEM(tuple, i)));
 
304
                else
 
305
                {
 
306
                    PyErr_SetString(PyExc_TypeError,
 
307
                                    "Only int or float tuples are supported");
 
308
                    return NULL;
 
309
                }
 
310
            }
 
311
 
 
312
            dims = len;
 
313
            err = DBWrite(db, str, values, &len,1, DB_DOUBLE);
 
314
        }
 
315
        else
 
316
        {
 
317
            PyErr_SetString(PyExc_TypeError,
 
318
                            "Only int or float tuples are supported");
 
319
            return NULL;
 
320
        }
 
321
    }
 
322
    else
 
323
    {
 
324
        PyErr_SetString(PyExc_TypeError, "Function takes 2 arguments");
 
325
        return NULL;
 
326
    }
 
327
 
 
328
    if (err != 0)
 
329
    {
 
330
        PyErr_SetString(PyExc_TypeError, "DBWrite failed");
 
331
        return NULL;
 
332
    }
 
333
    
 
334
    PyErr_Clear();
 
335
    Py_INCREF(Py_None);
 
336
    return Py_None;
 
337
}
 
338
 
 
339
// ****************************************************************************
 
340
//  Method:  DBfile_DBMkDir
 
341
//
 
342
//  Purpose:
 
343
//    Encapsulates DBMkDir
 
344
//
 
345
//  Python Arguments:
 
346
//    form 1: dirname
 
347
//
 
348
//  Programmer:  Jeremy Meredith
 
349
//  Creation:    July 12, 2005
 
350
//
 
351
// ****************************************************************************
 
352
static PyObject *DBfile_DBMkDir(PyObject *self, PyObject *args)
 
353
{
 
354
    DBfile *db = ((DBfileObject*)self)->db;
 
355
 
 
356
    if (!db)
 
357
    {
 
358
        SiloErrorFunc("This file has been closed.");
 
359
        return NULL;
 
360
    }
 
361
 
 
362
    char *str;
 
363
    if(!PyArg_ParseTuple(args, "s", &str))
 
364
        return NULL;
 
365
 
 
366
    if (DBMkDir(db, str))
 
367
    {
 
368
        SiloErrorFunc("Could not make the directory.");
 
369
        return NULL;
 
370
    }
 
371
    else
 
372
    {
 
373
        Py_INCREF(Py_None);
 
374
        return Py_None;
 
375
    }
 
376
}
 
377
 
 
378
// ****************************************************************************
 
379
//  Method:  DBfile_DBSetDir
 
380
//
 
381
//  Purpose:
 
382
//    Encapsulates DBSetDir
 
383
//
 
384
//  Python Arguments:
 
385
//    form 1: dirname
 
386
//
 
387
//  Programmer:  Jeremy Meredith
 
388
//  Creation:    July 12, 2005
 
389
//
 
390
// ****************************************************************************
 
391
static PyObject *DBfile_DBSetDir(PyObject *self, PyObject *args)
 
392
{
 
393
    DBfile *db = ((DBfileObject*)self)->db;
 
394
 
 
395
    if (!db)
 
396
    {
 
397
        SiloErrorFunc("This file has been closed.");
 
398
        return NULL;
 
399
    }
 
400
 
 
401
    char *str;
 
402
    if(!PyArg_ParseTuple(args, "s", &str))
 
403
        return NULL;
 
404
 
 
405
    if (DBSetDir(db, str))
 
406
    {
 
407
        SiloErrorFunc("Could not change directories.");
 
408
        return NULL;
 
409
    }
 
410
    else
 
411
    {
 
412
        Py_INCREF(Py_None);
 
413
        return Py_None;
 
414
    }
 
415
}
 
416
 
 
417
// ****************************************************************************
 
418
//  Method:  DBfile_DBClose
 
419
//
 
420
//  Purpose:
 
421
//    Encapsulates DBClose
 
422
//
 
423
//  Python Arguments:
 
424
//    none
 
425
//
 
426
//  Programmer:  Jeremy Meredith
 
427
//  Creation:    July 12, 2005
 
428
//
 
429
// ****************************************************************************
 
430
static PyObject *DBfile_DBClose(PyObject *self, PyObject *args)
 
431
{
 
432
    DBfile *db = ((DBfileObject*)self)->db;
 
433
 
 
434
    if (!db)
 
435
    {
 
436
        SiloErrorFunc("This file has been closed.");
 
437
        return NULL;
 
438
    }
 
439
 
 
440
    if(!PyArg_ParseTuple(args, ""))
 
441
        return NULL;
 
442
 
 
443
    if (DBClose(db))
 
444
    {
 
445
        SiloErrorFunc("Could not close the file.");
 
446
        return NULL;
 
447
    }
 
448
    else
 
449
    {
 
450
        ((DBfileObject*)self)->db = NULL;
 
451
        Py_INCREF(Py_None);
 
452
        return Py_None;
 
453
    }
 
454
}
 
455
 
 
456
// ****************************************************************************
 
457
//  DBfile method definitions  
 
458
//
 
459
//  Programmer:  Jeremy Meredith
 
460
//  Creation:    July 12, 2005
 
461
//
 
462
// ****************************************************************************
 
463
static struct PyMethodDef DBfile_methods[] = {
 
464
    {"GetToc", DBfile_DBGetToc, METH_VARARGS},
 
465
    {"GetVar", DBfile_DBGetVar, METH_VARARGS},
 
466
    {"Write", DBfile_DBWrite, METH_VARARGS},
 
467
    {"MkDir", DBfile_DBMkDir, METH_VARARGS},
 
468
    {"SetDir", DBfile_DBSetDir, METH_VARARGS},
 
469
    {"Close", DBfile_DBClose, METH_VARARGS},
 
470
    {NULL, NULL}
 
471
};
 
472
 
 
473
// ****************************************************************************
 
474
//  Method:  DBfile_dealloc
 
475
//
 
476
//  Purpose:
 
477
//    Deallocate the object.
 
478
//
 
479
//  Arguments:
 
480
//    none
 
481
//
 
482
//  Programmer:  Jeremy Meredith
 
483
//  Creation:    July 12, 2005
 
484
//
 
485
// ****************************************************************************
 
486
static void DBfile_dealloc(PyObject *self)
 
487
{
 
488
    PyObject_Del(self);
 
489
}
 
490
 
 
491
// ****************************************************************************
 
492
//  Method:  DBfile_as_string
 
493
//
 
494
//  Purpose:
 
495
//    Convert the DBfileObject to a string representation.
 
496
//
 
497
//  Arguments:
 
498
//    s          the target string, with space already allocated
 
499
//
 
500
//  Programmer:  Jeremy Meredith
 
501
//  Creation:    July 12, 2005
 
502
//
 
503
// ****************************************************************************
 
504
static void DBfile_as_string(PyObject *self, char *s)
 
505
{
 
506
    DBfileObject *obj = (DBfileObject*)self;
 
507
    if (obj->db)
 
508
        sprintf(s, "<DBfile object, filename='%s'>", obj->db->pub.name);
 
509
    else
 
510
        sprintf(s, "<closed DBfile object>");
 
511
}
 
512
 
 
513
// ****************************************************************************
 
514
//  Method:  DBfile_str
 
515
//
 
516
//  Purpose:
 
517
//    Convert the DBfileObject to a PyString
 
518
//
 
519
//  Arguments:
 
520
//    none
 
521
//
 
522
//  Programmer:  Jeremy Meredith
 
523
//  Creation:    July 12, 2005
 
524
//
 
525
// ****************************************************************************
 
526
static PyObject *DBfile_str(PyObject *self)
 
527
{
 
528
    char str[1000];
 
529
    DBfile_as_string(self, str);
 
530
    return PyString_FromString(str);
 
531
}
 
532
 
 
533
// ****************************************************************************
 
534
//  Method:  DBfile_print
 
535
//
 
536
//  Purpose:
 
537
//    Print the DBfileObject into a file as text
 
538
//
 
539
//  Arguments:
 
540
//    fp         the file pointer
 
541
//    flags      (unused)
 
542
//
 
543
//  Programmer:  Jeremy Meredith
 
544
//  Creation:    July 12, 2005
 
545
//
 
546
// ****************************************************************************
 
547
static int DBfile_print(PyObject *self, FILE *fp, int flags)
 
548
{
 
549
    char str[1000];
 
550
    DBfile_as_string(self, str);
 
551
    fprintf(fp, str);
 
552
    return 0;
 
553
}
 
554
 
 
555
// ****************************************************************************
 
556
//  Method: DBfile_getattr 
 
557
//
 
558
//  Purpose:
 
559
//    Return an attribute by name.  There is only one attribute of a
 
560
//    DBfile, which is its filename.
 
561
//
 
562
//  Arguments:
 
563
//    name       the name of the attribute to return
 
564
//
 
565
//  Programmer:  Jeremy Meredith
 
566
//  Creation:    July 12, 2005
 
567
//
 
568
// ****************************************************************************
 
569
static PyObject *DBfile_getattr(PyObject *self, char *name)
 
570
{
 
571
    DBfileObject *obj = (DBfileObject*)self;
 
572
 
 
573
    if (!obj->db)
 
574
    {
 
575
        SiloErrorFunc("This file has been closed.");
 
576
        return NULL;
 
577
    }
 
578
 
 
579
    if (!strcmp(name, "filename"))
 
580
    {
 
581
        if (obj->db)
 
582
        {
 
583
            return PyString_FromString(obj->db->pub.name);
 
584
        }
 
585
        else
 
586
        {
 
587
            return PyString_FromString("<closed file>");
 
588
        }
 
589
    }
 
590
 
 
591
    return Py_FindMethod(DBfile_methods, self, name);
 
592
}
 
593
 
 
594
// ****************************************************************************
 
595
//  Method:  DBfile_compare
 
596
//
 
597
//  Purpose:
 
598
//    Compare two DBfileObjects.
 
599
//
 
600
//  Arguments:
 
601
//    u, v       the objects to compare
 
602
//
 
603
//  Programmer:  Jeremy Meredith
 
604
//  Creation:    July 12, 2005
 
605
//
 
606
// ****************************************************************************
 
607
static int DBfile_compare(PyObject *v, PyObject *w)
 
608
{
 
609
    DBfile *a = ((DBfileObject *)v)->db;
 
610
    DBfile *b = ((DBfileObject *)w)->db;
 
611
    return (a<b) ? -1 : ((a==b) ? 0 : +1);
 
612
}
 
613
 
 
614
 
 
615
// ****************************************************************************
 
616
//  DBfile Python Type Object
 
617
//
 
618
//  Programmer:  Jeremy Meredith
 
619
//  Creation:    July 12, 2005
 
620
//
 
621
// ****************************************************************************
 
622
static char *DBfile_Purpose = "This class wraps a Silo DBfile object.";
 
623
PyTypeObject DBfileType =
 
624
{
 
625
    //
 
626
    // Type header
 
627
    //
 
628
    PyObject_HEAD_INIT(&PyType_Type)
 
629
    0,                                   // ob_size
 
630
    "DBfile",                    // tp_name
 
631
    sizeof(DBfileObject),        // tp_basicsize
 
632
    0,                                   // tp_itemsize
 
633
    //
 
634
    // Standard methods
 
635
    //
 
636
    (destructor)DBfile_dealloc,  // tp_dealloc
 
637
    (printfunc)DBfile_print,     // tp_print
 
638
    (getattrfunc)DBfile_getattr, // tp_getattr
 
639
    0,//(setattrfunc)DBfile_setattr, // tp_setattr -- this object is read-only
 
640
    (cmpfunc)DBfile_compare,     // tp_compare
 
641
    (reprfunc)0,                         // tp_repr
 
642
    //
 
643
    // Type categories
 
644
    //
 
645
    0,                                   // tp_as_number
 
646
    0,                                   // tp_as_sequence
 
647
    0,                                   // tp_as_mapping
 
648
    //
 
649
    // More methods
 
650
    //
 
651
    0,                                   // tp_hash
 
652
    0,                                   // tp_call
 
653
    (reprfunc)DBfile_str,        // tp_str
 
654
    0,                                   // tp_getattro
 
655
    0,                                   // tp_setattro
 
656
    0,                                   // tp_as_buffer
 
657
    Py_TPFLAGS_CHECKTYPES,               // tp_flags
 
658
    DBfile_Purpose,              // tp_doc
 
659
    0,                                   // tp_traverse
 
660
    0,                                   // tp_clear
 
661
    0,                                   // tp_richcompare
 
662
    0                                    // tp_weaklistoffset
 
663
};
 
664
 
 
665
// ****************************************************************************
 
666
//  Method:  DBfile_NEW
 
667
//
 
668
//  Purpose:
 
669
//    Allocate and initialize a DBfileObject.
 
670
//
 
671
//  Arguments:
 
672
//    init       the initial value
 
673
//
 
674
//  Programmer:  Jeremy Meredith
 
675
//  Creation:    July 12, 2005
 
676
//
 
677
// ****************************************************************************
 
678
PyObject *DBfile_NEW(DBfile *init)
 
679
{
 
680
    DBfileObject *obj = PyObject_NEW(DBfileObject, &DBfileType);
 
681
    if (obj)
 
682
    {
 
683
        obj->db = init;
 
684
    }
 
685
    return (PyObject*)obj;
 
686
}
 
687
 
 
688
// ****************************************************************************
 
689
//  Method:  DBfile_NEW
 
690
//
 
691
//  Purpose:
 
692
//    Allocate and initialize a DBfileObject with default values.
 
693
//
 
694
//  Python Arguments:
 
695
//    none
 
696
//
 
697
//  Programmer:  Jeremy Meredith
 
698
//  Creation:    July 12, 2005
 
699
//
 
700
// ****************************************************************************
 
701
PyObject *DBfile_new(PyObject *self, PyObject *args)
 
702
{
 
703
    return DBfile_NEW(NULL);
 
704
}
 
705