-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy_vector.h
47 lines (38 loc) · 1.6 KB
/
my_vector.h
1
2
3
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
/*
Vector object header file
*/
#ifndef MY_VECTOR_H
#define MY_VECTOR_H
#include <stdlib.h>
#include <stdio.h>
#include "status.h"
struct my_vector_public;
typedef struct my_vector_public* MY_VECTOR;
struct my_vector_public
{
/*****PUBLIC********/
//Precondition: hMy_vector holds the address of an opaque
// object of type MY_VECTOR ready to be destroyed.
//Postcondition: All memory for the vector indicated by hMy_vector
// has been released.
void(*destroy)(MY_VECTOR* phMy_vector);
Status(*push_back)(MY_VECTOR hMy_vector, Item_ptr item);
Status(*pop_back)(MY_VECTOR hMy_vector);
Item_ptr(*at)(MY_VECTOR hMy_vector, int index); //checks array bounds
int(*get_size)(MY_VECTOR hMy_vector); //Accessor function
int(*get_capacity)(MY_VECTOR hMy_vector); //Accessor function
};
//Precondition: NONE
//Postcondition: An opaque object for MY_VECTOR has been created that can hold 1 item and
// currently holds none.
//Precondition:
//Postcondition: item_handle is set to NULL and item is destroy properly
//void (*item_destroy)(Item_ptr* item_handle);
//Precondition:
//Postcondition:if item_handle is not NULL then we try to use the space
//already allocated to item referred to by item_handle for a copy of item. If
//assign fails then item_handle will be NULL, otherwise item_handle will be
//the address of an item that has a complete and independent copy of item.
//Status (*item_assign)(Item_ptr* item_handle, Item_ptr item);
MY_VECTOR my_vector_init_default(void(*item_destroy)(Item_ptr* item_handle), Status (*item_assign)(Item_ptr* item_handle, Item_ptr item));
#endif