コード例 #1
0
ファイル: p1_main.c プロジェクト: LIght918/EECS381_proj1
static void add_record( struct Ordered_container* lib_title, struct Ordered_container* lib_ID )
{
    char title [ TITLE_ARRAY_SIZE  ];
    char medium[ MEDIUM_ARRAY_SIZE ];
    struct Record* new_rec;
    
    /* read the record in from the command line */
    if ( !get_medium_and_title( medium, title ) )
    {
        print_error( "Could not read a title!\n" );
        return;
    }
    
    /* check if the Record already exists */
    if ( OC_find_item_arg( lib_title, title , comp_Record_to_title ) != NULL )
    {
        print_error( "Library already has a record with this title!\n" );
        return;
    }
    else
    {
        new_rec = create_Record(medium, title );
        OC_insert( lib_title, new_rec );
        OC_insert( lib_ID, new_rec );
        printf( "Record %d added\n", get_Record_ID( new_rec ) );
    }
}
コード例 #2
0
ファイル: p1_main.c プロジェクト: LIght918/EECS381_proj1
/* remove the node associated with the data_ptr
 * if there is not record found print the error err
 * requires a OC_find_item_arg_fp_t fafp that returns true for the data_ptr given
 * return 1 on success NULL if otherwise
 */
static int find_remove( struct Ordered_container* c_ptr, OC_find_item_arg_fp_t fafp, void* data_ptr )
{
    void* node = OC_find_item_arg( c_ptr, data_ptr, fafp );
    
    if ( node == NULL )
    {
        return 0 ;
    }
    
    OC_delete_item( c_ptr, node );
    return 1;
}
コード例 #3
0
ファイル: p1_main.c プロジェクト: LIght918/EECS381_proj1
/* reads in a name from stdin and returns the collection associated with it
   returns NULL and throws an error if there wasn't any collection by that name */
static void* find_collection_by_name( struct Ordered_container* catalog )
{
    char name[ NAME_ARRAY_SIZE ];
    void* node;
    
    read_name( name );
    
    node = OC_find_item_arg( catalog, name, comp_Collection_to_name );
    
    if ( node == NULL )
    {
        print_error( "No collection with that name!\n" );
    }
    
    return node;
}
コード例 #4
0
ファイル: array_test.cpp プロジェクト: roudy16/enfant
int main(void)
{
    //OC_comp_fp_t f_ptr;
    struct Ordered_container* container_ptr = OC_create_container(&thing_comp_f);

    OC_insert(container_ptr, make_thing(5));
    OC_insert(container_ptr, make_thing(3));
    OC_insert(container_ptr, make_thing(4));
    OC_insert(container_ptr, make_thing(1));
    OC_insert(container_ptr, make_thing(2));
    OC_insert(container_ptr, make_thing(99));
    OC_insert(container_ptr, make_thing(-2));

    for (int i = 0; i < 7; ++i)
    {
        printf("Element %d: %d\n", i, *(int*)(*(container_ptr->array + i)));
    }

    printf("size = %d\n", OC_get_size(container_ptr));
    printf("Empty = %d\n", OC_empty(container_ptr));

    int search_num = 5;
    int* data_ptr = OC_find_item(container_ptr, &search_num);
    printf("Found data: %d\n", *(int*)OC_get_data_ptr(data_ptr));
    search_num = 99;
    printf("Apply_if_arg returned: %d\n", 
           OC_apply_if_arg(container_ptr, (OC_apply_if_arg_fp_t)apply_if_arg_tester, &search_num));
    data_ptr = OC_find_item_arg(container_ptr, &search_num, alt_thing_comp_f);
    printf("Found data: %d\n", *(int*)OC_get_data_ptr(data_ptr));

    printf("Things: %d\n", g_num_things);
    OC_apply(container_ptr, &delete_thing);
    OC_clear(container_ptr);
    printf("Things: %d\n", g_num_things);
    printf("size = %d\n", OC_get_size(container_ptr));
    printf("Empty = %d\n", OC_empty(container_ptr));

    OC_destroy_container(container_ptr);

    void* test = malloc(8);

    printf("Old way %p   New Way %p\n", *(void**)test, test);

    return 0;
}
コード例 #5
0
ファイル: p1_main.c プロジェクト: LIght918/EECS381_proj1
static void add_coll( struct Ordered_container* catalog )
{
    struct Collection* new_coll;
    char name[ NAME_ARRAY_SIZE ];
    
    read_name( name );
    
    if ( OC_find_item_arg( catalog, name, comp_Collection_to_name ) != NULL )
    {
        print_error( "Catalog already has a collection with this name!\n" );
        return;
    }
    
    new_coll = create_Collection( name );
    
    OC_insert( catalog, new_coll );
    printf("Collection %s added\n", name );
}
コード例 #6
0
ファイル: linked_list_test.c プロジェクト: roudy16/enfant
int main(void)
{
    //OC_comp_fp_t f_ptr;
    struct Ordered_container* container_ptr = OC_create_container(&thing_comp_f);

    OC_insert(container_ptr, make_thing(5));
    OC_insert(container_ptr, make_thing(3));
    OC_insert(container_ptr, make_thing(4));
    OC_insert(container_ptr, make_thing(1));
    OC_insert(container_ptr, make_thing(2));
    OC_insert(container_ptr, make_thing(99));
    OC_insert(container_ptr, make_thing(-2));

    printf("size = %d\n", OC_get_size(container_ptr));
    printf("Empty = %d\n", OC_empty(container_ptr));
    Print_container(container_ptr, sizeof(int));

    int search_num = 5;
    int* data_ptr = OC_find_item(container_ptr, &search_num);
    printf("Found data: %d\n", *(int*)OC_get_data_ptr(data_ptr));
    search_num = 99;
    printf("Apply_if_arg returned: %d\n", 
           OC_apply_if_arg(container_ptr, (OC_apply_if_arg_fp_t)apply_if_arg_tester, &search_num));
    data_ptr = OC_find_item_arg(container_ptr, &search_num, alt_thing_comp_f);
    printf("Found data: %d\n", *(int*)OC_get_data_ptr(data_ptr));

    printf("Things: %d\n", g_num_things);
    OC_apply(container_ptr, &delete_thing);
    OC_clear(container_ptr);
    printf("Things: %d\n", g_num_things);
    printf("size = %d\n", OC_get_size(container_ptr));
    printf("Empty = %d\n", OC_empty(container_ptr));
    Print_container(container_ptr, sizeof(int));

    OC_destroy_container(container_ptr);

    return 0;
}
コード例 #7
0
ファイル: Ordered_container_array.c プロジェクト: syzhou/p1
/* Return a pointer to an item that points to data equal to the data object pointed to by data_ptr,
using the ordering function to do the comparison with data_ptr as the first argument.
The data_ptr object is assumed to be of the same type as the data objects pointed to by container items.
NULL is returned if no matching item is found. If more than one matching item is present, it is
unspecified which one is returned. */
void* OC_find_item(const struct Ordered_container* c_ptr, const void* data_ptr){
	/*Just call OC_find_item_arg with the default compare function in OC*/
	return OC_find_item_arg(c_ptr, data_ptr, (OC_find_item_arg_fp_t)c_ptr->comp_fun);
}
コード例 #8
0
ファイル: Ordered_container_array.c プロジェクト: syzhou/p1
/* Return a pointer to an item that points to data equal to the data object pointed to by data_ptr,
using the ordering function to do the comparison with data_ptr as the first argument.
The data_ptr object is assumed to be of the same type as the data objects pointed to by container items.
NULL is returned if no matching item is found. If more than one matching item is present, it is
unspecified which one is returned. */
void* OC_find_item(const struct Ordered_container* c_ptr, const void* data_ptr){
	return OC_find_item_arg(c_ptr, data_ptr, (OC_find_item_arg_fp_t)c_ptr->comp_fun);
}
コード例 #9
0
ファイル: p1_main.c プロジェクト: syzhou/p1
struct Meeting* findMeetingByTime(const struct Ordered_container* meetings, int* time) {
	void *itemPtr = OC_find_item_arg(meetings, time,
			(OC_find_item_arg_fp_t)compareTimeAndMeeting);
	return OC_get_data_ptr(itemPtr);
}
コード例 #10
0
ファイル: p1_main.c プロジェクト: syzhou/p1
/*Find a room by room number and returns a pointer to the room structure.
 * Returns NULL if not found.
 * The function takes the pointer to the ordered containter and the room number
 * as parameters.
 */
struct Room* findRoomByNum(struct Ordered_container* rooms, int* roomNum) {
	void *itemPtr = OC_find_item_arg(rooms, roomNum,
			(OC_find_item_arg_fp_t)compareNumAndRoom);
	return OC_get_data_ptr(itemPtr);
}