1 /* basics.c */
2
3 #include "../ChvList.h"
4
5 #define MYDEBUG 0
6
7 /*--------------------------------------------------------------------*/
8 /*
9 -----------------------
10 simplest constructor
11
12 created -- 98may02, cca
13 -----------------------
14 */
15 ChvList *
ChvList_new(void)16 ChvList_new (
17 void
18 ) {
19 ChvList *chvlist ;
20
21 ALLOCATE(chvlist, struct _ChvList, 1) ;
22 ChvList_setDefaultFields(chvlist) ;
23
24 return(chvlist) ; }
25
26 /*--------------------------------------------------------------------*/
27 /*
28 -----------------------
29 set the default fields
30
31 created -- 98may02, cca
32 -----------------------
33 */
34 void
ChvList_setDefaultFields(ChvList * chvlist)35 ChvList_setDefaultFields (
36 ChvList *chvlist
37 ) {
38 if ( chvlist == NULL ) {
39 fprintf(stderr, "\n fatal error in ChvList_setDefaultFields(%p)"
40 "\n bad input", chvlist) ;
41 exit(-1) ;
42 }
43 chvlist->nlist = 0 ;
44 chvlist->heads = NULL ;
45 chvlist->counts = NULL ;
46 chvlist->lock = NULL ;
47 chvlist->flags = NULL ;
48 chvlist->nlocks = 0 ;
49
50 return ; }
51
52 /*--------------------------------------------------------------------*/
53 /*
54 --------------------------------------------------
55 clear the data fields, releasing allocated storage
56
57 created -- 98may02, cca
58 --------------------------------------------------
59 */
60 void
ChvList_clearData(ChvList * chvlist)61 ChvList_clearData (
62 ChvList *chvlist
63 ) {
64 /*
65 ---------------
66 check the input
67 ---------------
68 */
69 if ( chvlist == NULL ) {
70 fprintf(stderr, "\n fatal error in ChvList_clearData(%p)"
71 "\n bad input\n", chvlist) ;
72 exit(-1) ;
73 }
74 /*
75 -------------
76 free the data
77 -------------
78 */
79 if ( chvlist->heads != NULL ) {
80 FREE(chvlist->heads) ;
81 }
82 if ( chvlist->counts != NULL ) {
83 IVfree(chvlist->counts) ;
84 }
85 if ( chvlist->flags != NULL ) {
86 CVfree(chvlist->flags) ;
87 }
88 if ( chvlist->lock != NULL ) {
89 /*
90 -------------------------
91 destroy and free the lock
92 -------------------------
93 */
94 Lock_free(chvlist->lock) ;
95 }
96 /*
97 ----------------------
98 set the default fields
99 ----------------------
100 */
101 ChvList_setDefaultFields(chvlist) ;
102
103 return ; }
104
105 /*--------------------------------------------------------------------*/
106 /*
107 ------------------------------------------
108 destructor, free's the object and its data
109
110 created -- 98may02, cca
111 ------------------------------------------
112 */
113 void
ChvList_free(ChvList * chvlist)114 ChvList_free (
115 ChvList *chvlist
116 ) {
117 if ( chvlist == NULL ) {
118 fprintf(stderr, "\n fatal error in ChvList_free(%p)"
119 "\n bad input\n", chvlist) ;
120 exit(-1) ;
121 }
122 ChvList_clearData(chvlist) ;
123 FREE(chvlist) ;
124
125 return ; }
126
127 /*--------------------------------------------------------------------*/
128