cPersistence.h 4.16 KB
Newer Older
Jim Fulton's avatar
Jim Fulton committed
1 2
/*

Jim Fulton's avatar
Jim Fulton committed
3
  $Id: cPersistence.h,v 1.8 1997/12/10 22:19:24 jim Exp $
Jim Fulton's avatar
Jim Fulton committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58

  Definitions to facilitate making cPersistent subclasses in C.

     Copyright 

       Copyright 1996 Digital Creations, L.C., 910 Princess Anne
       Street, Suite 300, Fredericksburg, Virginia 22401 U.S.A. All
       rights reserved.  Copyright in this software is owned by DCLC,
       unless otherwise indicated. Permission to use, copy and
       distribute this software is hereby granted, provided that the
       above copyright notice appear in all copies and that both that
       copyright notice and this permission notice appear. Note that
       any product, process or technology described in this software
       may be the subject of other Intellectual Property rights
       reserved by Digital Creations, L.C. and are not licensed
       hereunder.

     Trademarks 

       Digital Creations & DCLC, are trademarks of Digital Creations, L.C..
       All other trademarks are owned by their respective companies. 

     No Warranty 

       The software is provided "as is" without warranty of any kind,
       either express or implied, including, but not limited to, the
       implied warranties of merchantability, fitness for a particular
       purpose, or non-infringement. This software could include
       technical inaccuracies or typographical errors. Changes are
       periodically made to the software; these changes will be
       incorporated in new editions of the software. DCLC may make
       improvements and/or changes in this software at any time
       without notice.

     Limitation Of Liability 

       In no event will DCLC be liable for direct, indirect, special,
       incidental, economic, cover, or consequential damages arising
       out of the use of or inability to use this software even if
       advised of the possibility of such damages. Some states do not
       allow the exclusion or limitation of implied warranties or
       limitation of liability for incidental or consequential
       damages, so the above limitation or exclusion may not apply to
       you.
   
    If you have questions regarding this software,
    contact:
   
      Digital Creations L.C.  
      info@digicool.com
   
      (540) 371-6909


  $Log: cPersistence.h,v $
Jim Fulton's avatar
Jim Fulton committed
59 60 61
  Revision 1.8  1997/12/10 22:19:24  jim
  Added PER_USE macro.

62 63 64
  Revision 1.7  1997/07/18 14:15:39  jim
  Added PER_DEL so that subclasses can handle deallocation correctly.

65 66 67
  Revision 1.6  1997/06/06 19:13:32  jim
  Changed/fixed convenience macros.

68 69 70
  Revision 1.5  1997/05/19 17:51:20  jim
  Added macros to simplify C PO implementation.

Jim Fulton's avatar
Jim Fulton committed
71 72 73
  Revision 1.4  1997/05/19 13:49:36  jim
  Added include of time.h.

74 75 76 77
  Revision 1.3  1997/04/27 09:18:23  jim
  Added to the CAPI to support subtypes (like Record) that want to
  extend attr functions.

Jim Fulton's avatar
Jim Fulton committed
78 79 80
  Revision 1.2  1997/04/22 02:40:28  jim
  Changed object header layout.

Jim Fulton's avatar
Jim Fulton committed
81 82 83 84 85 86 87 88 89 90
  Revision 1.1  1997/04/01 17:15:48  jim
  *** empty log message ***


*/

#ifndef CPERSISTENCE_H
#define CPERSISTENCE_H

#include "ExtensionClass.h"
Jim Fulton's avatar
Jim Fulton committed
91
#include <time.h>
Jim Fulton's avatar
Jim Fulton committed
92 93 94

#define cPersistent_HEAD   PyObject_HEAD \
  PyObject *jar; \
Jim Fulton's avatar
Jim Fulton committed
95 96 97 98
  int oid; \
  int state; \
  time_t atime; \

Jim Fulton's avatar
Jim Fulton committed
99 100 101 102 103 104 105 106 107

#define cPersistent_GHOST_STATE -1
#define cPersistent_UPTODATE_STATE 0
#define cPersistent_CHANGED_STATE 1

typedef struct {
  cPersistent_HEAD
} cPersistentObject;

Jim Fulton's avatar
Jim Fulton committed
108 109 110 111 112
typedef struct {
  PyObject_HEAD
  cPersistentObject *object;
} PATimeobject;

113 114
typedef int (*persetattr)(PyObject *, PyObject*, PyObject *, setattrofunc);
typedef PyObject *(*pergetattr)(PyObject *, PyObject*, char *, getattrofunc);
Jim Fulton's avatar
Jim Fulton committed
115 116 117 118 119 120 121

typedef struct {
  PyMethodChain *methods;
  getattrofunc getattro;
  setattrofunc setattro;
  int (*changed)(PyObject*);
  int (*setstate)(PyObject*);
122 123
  pergetattr pergetattro;
  persetattr persetattro;
Jim Fulton's avatar
Jim Fulton committed
124 125 126 127
} cPersistenceCAPIstruct;

static cPersistenceCAPIstruct *cPersistenceCAPI;

Jim Fulton's avatar
Jim Fulton committed
128

129 130 131
#define PER_USE_OR_RETURN(O,R) \
  if(cPersistenceCAPI->setstate((PyObject*)(O)) < 0) return (R)

Jim Fulton's avatar
Jim Fulton committed
132 133
#define PER_USE(O) (cPersistenceCAPI->setstate((PyObject*)(O)))

134 135 136 137
#define PER_CHANGED(O) (cPersistenceCAPI->changed((PyObject*)(O)))

#define PER_PREVENT_DEACTIVATION(O) ((O)->atime=(time_t)1);
#define PER_ALLOW_DEACTIVATION(O) ((O)->atime=time(NULL));
138
#define PER_DEL(O) Py_XDECREF((O)->jar)
139

Jim Fulton's avatar
Jim Fulton committed
140 141 142
#endif