1 /*  basics.C  */
2 
3 #include "../IV.h"
4 
5 /*--------------------------------------------------------------------*/
6 /*
7    -----------------------
8    constructor method
9 
10    created -- 95oct06, cca
11    -----------------------
12 */
13 IV *
IV_new(void)14 IV_new (
15    void
16 ) {
17 IV   *iv ;
18 
19 ALLOCATE(iv, struct _IV, 1) ;
20 
21 IV_setDefaultFields(iv) ;
22 
23 return(iv) ; }
24 /*--------------------------------------------------------------------*/
25 /*
26    -----------------------
27    set the default fields
28 
29    created -- 95oct06, cca
30    -----------------------
31 */
32 void
IV_setDefaultFields(IV * iv)33 IV_setDefaultFields (
34    IV   *iv
35 ) {
36 if ( iv == NULL ) {
37    fprintf(stderr, "\n fatal error in IV_setDefaultFields(%p)"
38            "\n bad input\n", iv) ;
39    exit(-1) ;
40 }
41 iv->size    =   0  ;
42 iv->maxsize =   0  ;
43 iv->owned   =   0  ;
44 iv->vec     = NULL ;
45 
46 return ; }
47 
48 /*--------------------------------------------------------------------*/
49 /*
50    -----------------------
51    clear the data fields
52 
53    created -- 95oct06, cca
54    -----------------------
55 */
56 void
IV_clearData(IV * iv)57 IV_clearData (
58    IV   *iv
59 ) {
60 if ( iv == NULL ) {
61    fprintf(stderr, "\n fatal error in IV_clearData(%p)"
62            "\n bad input\n", iv) ;
63    exit(-1) ;
64 }
65 if ( iv->vec != NULL && iv->owned == 1 ) {
66    IVfree(iv->vec) ;
67 }
68 IV_setDefaultFields(iv) ;
69 
70 return ; }
71 
72 /*--------------------------------------------------------------------*/
73 /*
74    -----------------------
75    destructor
76 
77    created -- 95oct06, cca
78    -----------------------
79 */
80 void
IV_free(IV * iv)81 IV_free (
82    IV   *iv
83 ) {
84 if ( iv == NULL ) {
85    fprintf(stderr, "\n fatal error in IV_free(%p)"
86            "\n bad input\n", iv) ;
87    exit(-1) ;
88 }
89 IV_clearData(iv) ;
90 FREE(iv) ;
91 
92 return ; }
93 
94 /*--------------------------------------------------------------------*/
95