// Operation.pp // // Created by Cristina Videira Lopes on 12/20/94. // // This file contains the set of propagation patterns whose source vertex // is the Operation class; the operations defined here apply to objects // of this class. These are the current propagation patterns: // // *operation* void execute (IN LibrarySystem* ls) // // // *operation* void execute (LibrarySystem* ls) // // Execute the operation correspondent to a given operation-object within // a LibrarySystem. The LibrarySystem-object is given as input for possible // calls to it. // *operation* void execute (LibrarySystem* ls) *traverse* *from* Operation *to* {Exit, ShowBooks, SearchBook, ShowUsers, SearchUser, CheckOut, CheckIn, Invalid} *carry* *in* User *u = (@ NULL @), CheckedOut_List* col = (@ NULL @), Book_List *bl = (@ new Book_List @), Copy_List *cl = (@ new Copy_List @) *along* *from* CheckBook *to* {CheckOut, CheckIn} *wrapper* ShowBooks *prefix* (@ ls->show_books(); @) *wrapper* SearchBook *prefix* (@ char keyword[256]; Book_List *bl = new Book_List; cout << " Enter keyword: "; cin >> keyword; ls->search_book (keyword, bl); bl->print(); @) *wrapper* ShowUsers *prefix* (@ ls->show_users(); @) *wrapper* SearchUser *prefix* (@ char key[256]; User_List *ul = new User_List; cout << " Enter part of name or address: "; cin >> key; ls->search_user (key, ul); ul->print(); @) *wrapper* CheckBook *prefix* (@ char uid[30], isbn[30], copy[30]; // ATTENTION! set user u cout << " Checking books.\n Enter user id: "; cin >> uid; u = ls->get_users()->search_user(atoi(uid)); if (u == NULL) { cout << " Invalid user id.\n"; return; } // ATTENTION! set checked out list col col = u->get_checkedoutlist(); for (;;) { cout << " Enter book isbn (or 0 to terminate): "; cin >> isbn; if (atoi (isbn) <= 0) break; Book *b = ls->get_books()->search_book (atoi (isbn)); if (b == NULL) { cout << " Invalid isbn.\n"; continue; } cout << " Enter copy #: "; cin >> copy; Copy *c = b->search_copy (atoi(copy)); if (c == NULL) { cout << " Invalid copy for this book.\n"; continue; } // ATTENTION! update booklist bl and copylist cl bl->append (b); cl->append (c); } @) *wrapper* CheckOut *prefix* (@ // Here we have all the necessary information: // User (u), list of books checked out by user (col), list of books to be // checked out (bl) and their copies (cl). Book_list_iterator next_book (*bl); Copy_list_iterator next_copy (*cl); Book *b; Copy *c; CheckedOut *co; int i = 0; while (b = next_book()) { c = next_copy(); // Check the status if (u->quota() == col->list_length ()) { cout << " Quota exceeded by this user. " << "Can't check out the last " << (bl->list_length() - i) << " books:\n"; break; } c->set_borrower (u); co = new CheckedOut; co->set_book (b); co->set_copy (c); col->append (co); i++; } @) *wrapper* CheckIn *prefix* (@ // Here we have all the necessary information: // User (u), list of books checked in by user (col), list of books to be // checked in (bl) and their copies (cl). Book_list_iterator next_book (*bl); Copy_list_iterator next_copy (*cl); Book *b; Copy *c; CheckedOut *co; CheckedOut_List *new_col = NULL; int found; while (b = next_book()) { c = next_copy(); new_col = new CheckedOut_List; found = 0; CheckedOut_list_iterator next_co (*col); while (co = next_co()) { if ((co->get_book() == b) && (co->get_copy() == c)) { /* found */ c->set_borrower (NULL); delete co; found = 1; } else new_col->append (co); } col = new_col; if (!found) { cout << " Book " << *b->get_isbn()->get_n() << " not borrowed by user " << *u->get_uid() << "\n"; } else col = new_col; } u->set_checkedoutlist (new_col); @) *wrapper* Invalid *prefix* (@ cout << " Invalid operation. Please try again.\n"; @)