1 /* basics.c */
2
3 #include "../Perm.h"
4
5 #define MYDEBUG 0
6
7 /*--------------------------------------------------------------------*/
8 /*
9 -----------------------
10 simplest constructor
11
12 created -- 96jan05, cca
13 -----------------------
14 */
15 Perm *
Perm_new(void)16 Perm_new (
17 void
18 ) {
19 Perm *perm ;
20 ALLOCATE(perm, struct _Perm, 1) ;
21 Perm_setDefaultFields(perm) ;
22
23 return(perm) ; }
24
25 /*--------------------------------------------------------------------*/
26 /*
27 -----------------------
28 set the default fields
29
30 created -- 96jan05, cca
31 -----------------------
32 */
33 void
Perm_setDefaultFields(Perm * perm)34 Perm_setDefaultFields (
35 Perm *perm
36 ) {
37 if ( perm == NULL ) {
38 fprintf(stderr, "\n fatal error in Perm_setDefaultFields(%p)"
39 "\n bad input", perm) ;
40 exit(-1) ;
41 }
42 perm->isPresent = 0 ;
43 perm->size = 0 ;
44 perm->newToOld = NULL ;
45 perm->oldToNew = NULL ;
46
47 return ; }
48
49 /*--------------------------------------------------------------------*/
50 /*
51 --------------------------------------------------
52 clear the data fields, releasing allocated storage
53
54 created -- 96jan05, cca
55 --------------------------------------------------
56 */
57 void
Perm_clearData(Perm * perm)58 Perm_clearData (
59 Perm *perm
60 ) {
61 /*
62 ---------------
63 check the input
64 ---------------
65 */
66 if ( perm == NULL ) {
67 fprintf(stderr, "\n fatal error in Perm_clearData(%p)"
68 "\n bad input\n", perm) ;
69 exit(-1) ;
70 }
71 if ( perm->newToOld != NULL ) {
72 IVfree(perm->newToOld) ;
73 }
74 if ( perm->oldToNew != NULL ) {
75 IVfree(perm->oldToNew) ;
76 }
77 /*
78 ----------------------
79 set the default fields
80 ----------------------
81 */
82 Perm_setDefaultFields(perm) ;
83
84 return ; }
85
86 /*--------------------------------------------------------------------*/
87 /*
88 ------------------------------------------
89 destructor, free's the object and its data
90
91 created -- 96jan05, cca
92 ------------------------------------------
93 */
94 Perm *
Perm_free(Perm * perm)95 Perm_free (
96 Perm *perm
97 ) {
98 if ( perm == NULL ) {
99 fprintf(stderr, "\n fatal error in Perm_free(%p)"
100 "\n bad input\n", perm) ;
101 exit(-1) ;
102 }
103 Perm_clearData(perm) ;
104 FREE(perm) ;
105
106 return(NULL) ; }
107
108 /*--------------------------------------------------------------------*/
109