Ejemplo n.º 1
0
static void clear_library( struct Ordered_container* lib_title, struct Ordered_container* lib_ID, struct Ordered_container* catalog, char* output )
{
    if ( strlen( output ) > 0 && OC_apply_if( catalog, is_Collection_not_empty ) )
    {
        print_error( "Cannot clear all records unless all collections are empty!\n" );
    }
    else
    {
        reset_Record_ID_counter();
        
        /* clear lib_ID instead of calling clear_container b/c
         it points to the same data as lib_title */
        OC_clear( lib_ID );
        
        /* clear the container and destroy the records */
        clear_container(lib_title, ( void(*)(void*) )destroy_Record, output );
    }
}
Ejemplo n.º 2
0
static void fetch_contents_by_category (GtkComboBox *widget, gpointer to_fill)
{
    GtkWidget *contents;
    GtkTreeIter iter;
    OGDCategory *category;
    OGDIterator *iterator;

    contents = (GtkWidget*) to_fill;
    clear_container (contents);

    if (gtk_combo_box_get_active_iter (widget, &iter))
        gtk_tree_model_get (gtk_combo_box_get_model (widget), &iter, 1, &category, -1);
    else
        return;

    iterator = ogd_category_get_contents (category, OGD_CATEGORY_SORT_NEWEST);
    ogd_iterator_fetch_async (iterator, fit_contents_list, contents);

    gtk_statusbar_push (GTK_STATUSBAR (mainStatus), 2, "Fetching contents...");
}
Ejemplo n.º 3
0
Archivo: uno.c Proyecto: tmacwill/uno
/**
 * Play the given card
 *
 * @param card Card to play
 * @return False if card cannot be played, true otherwise
 *
 */
int play(struct card_t* card) {
    // if either value or color matches, then move is valid
    if (card->value == up_card.value || card->color == up_card.color) {
        // change the up card
        up_card.type = card->type;
        up_card.color = card->color;
        up_card.value = card->value;

        // clear game so we can remove the card that was played
        clear_container(container);
        remove_card(card);

        // draw the new game state
        draw_hand();

        return 1;
    }

    // illegal move
    return 0;
}
void task5_4::instantiation_test()
{
	std::vector< int > v1;
	clear_container( v1 );

	std::vector< int* > v2;
	clear_container( v2 );

// uncomment to see compilation problem
//		std::vector< int > v3;
//		clear_container< false, true >( v3 );

	std::map< int, int > m1;
	clear_container( m1 );

	std::map< int, int* > m2;
	clear_container( m2 );

	std::map< int*, int > m3;
	clear_container( m3 );

	std::map< int*, int* > m4;
	clear_container( m4 );
}	
Ejemplo n.º 5
0
static void clear_all( struct Ordered_container* lib_title, struct Ordered_container* lib_ID, struct Ordered_container* catalog, char* message )
{
    clear_container( catalog, ( void(*)(void*) )destroy_Collection, "" );
    /*clear_container(lib_ID, ( void(*)(void*) )destroy_Record, "") ;*/
    clear_library(lib_title, lib_ID, catalog, message );
}
Ejemplo n.º 6
0
int main( void )
{
    int i;
    
    /* holds both command characters */
    char command[ 2 ];
    
    /* set up the three libraries */
    struct Ordered_container* lib_title = OC_create_container( comp_Record_by_title );
    struct Ordered_container* lib_ID    = OC_create_container( comp_Record_by_ID );
    struct Ordered_container* catalog   = OC_create_container( comp_Collection_by_name );
    
    for ( ; ; )
    {
        printf( "\nEnter command: " );
        
        /* load the command chars */
        for ( i = 0 ; i < 2; ++i)
        {
            command[ i ] = get_command_char();
        }
        
        switch ( command[ 0 ] )
        {
            case 'f' :/* find (records only)*/
                switch ( command[ 1 ] )
                {
                    case 'r' :
                        find_record_print( lib_title );
                        break;
                    default:
                        print_error_clear( "Unrecognized command!\n");
                        break;
                }
                break;
            case 'p' : /* print */
                switch ( command[ 1 ] )
                {
                    case 'r' :
                        print_record( lib_ID );
                        break;
                    case 'L':
                        print_containter( lib_title, "Library", "records", (void (*)(void*))print_Record );
                        break;
                    case 'C':
                        /* print_catalog( catalog ); */
                        print_containter( catalog, "Catalog", "collections", (void (*)(void*))print_Collection );
                        break;
                    case 'a': /* allocation */
                        print_allocation( lib_title, lib_ID, catalog );
                        break;
                    case 'c':
                        print_collection_main( catalog );
                        break;
                    default:
                        print_error_clear( "Unrecognized command!\n");
                        break;
                }
                break;
            case 'm': /* modify (rating only) */
                switch ( command[ 1 ] )
                {
                    case 'r':
                        modify_rating( lib_ID );
                        break;
                    default:
                        print_error_clear( "Unrecognized command!\n");
                        break;
                }
                break;
            case 'a' : /* add */
                switch ( command[ 1 ] )
                {
                    case 'r' :
                        add_record( lib_title, lib_ID );
                        break;
                    case 'c':
                        add_coll( catalog );
                        break;
                    case 'm':
                        add_member( lib_ID , catalog );
                        break;
                    case 'a': /* allocation */
                        /* throw error */
                        print_error_clear( "Unrecognized command!\n");
                        break;
                    default:
                        break;
                }
                break;
            case 'd': /* delete */
                switch ( command[ 1 ] )
                {
                    case 'r' :
                        delete_record( lib_title, lib_ID, catalog );
                        break;
                    case 'c':
                        delete_collection( catalog );
                        break;
                    case 'm':
                         remove_member( lib_ID , catalog );
                        break;
                    case 'a': /* allocation */
                        /* throw error */
                        break;
                    default:
                        print_error_clear( "Unrecognized command!\n");
                        break;
                }
                break;
            case 'c': /* clear */
                switch ( command[ 1 ] )
                {
                    case 'L':
                        clear_library( lib_title, lib_ID, catalog, "All records deleted\n" );
                        break;
                    case 'C':
                        clear_container( catalog, ( void(*)(void*) )destroy_Collection, "All collections deleted\n" );
                        break;
                    case 'A':
                        clear_all(lib_title, lib_ID, catalog, "All data deleted\n" );
                        break;
                    default:
                        print_error_clear( "Unrecognized command!\n");
                        break;
                }
                break;
            case 's': /* save */
                switch ( command[ 1 ] ) {
                    case 'A':
                        save_all_to_file( lib_title, catalog );
                        break;
                    default:
                        print_error_clear( "Unrecognized command!\n");
                        break;
                }
                break;
            case 'r': /* restore */
                switch ( command[ 1 ] ) {
                    case 'A':
                        load_from_file( lib_title, lib_ID, catalog );
                        break;
                    default:
                        print_error_clear( "Unrecognized command!\n");
                        break;
                }
                break;
            case 'q':
                switch ( command[ 1 ] )
                {
                    case 'q':
                        /* clean up memory */
                        quit( lib_title, lib_ID, catalog );
                        break;
                    default:
                        print_error_clear( "Unrecognized command!\n");
                        break;
                }
            default:
                /* throw error for bad input */
                print_error_clear( "Unrecognized command!\n");
                break;
        }
    }
	return 0;
}