Example #1
0
//Puts a book on the hold shelf, unless it is already requested.
//If checked out, note that it should go to the hold shelf
void Library::requestBook(std::string patronID, std::string bookID)
{
    Book* book = GetBook(bookID);
    Patron* patron = GetPatron(patronID);

    if(book == NULL || patron == NULL)
    {
        if(book == NULL)
        {
            std::cout << std::endl << "No such book in holdings." << std::endl;
        }
        if(patron == NULL)
        {
            std::cout << std::endl << "No such patron in records." << std::endl;
        }
        return;
    }

    if(book->getRequestedBy() == NULL)
    {
        book->setRequestedBy(patron);
        if(book->getLocation() == ON_SHELF)
        {
            book->setLocation(ON_HOLD);
        }
    }
    else
    {
        std::cout << "This book is already requested!";
    }
}
Example #2
0
/* Function to remove a book from book DB */
void RemoveBook(char *id, book_db *db_head){
	book *removedBook;
	int removeResult;

	/* Find the book that we want to remove */
	removedBook=GetBook(id, db_head);

	/* If book not found print an error and stop function */
	if (removedBook==NULL){
		printf("The book %s was not found in the library inventory\n",id);
		return;
	}

	/* Make sure that no customer has the book out on loan */
	if (removedBook->customers->first==NULL){
		/* Use generic RemoveNode command to remove the book from the DB */
		removeResult=DeleteNode(id,db_head->books);
		if (removeResult==FAIL)
			printf("Error - Could not delete book\n");
		return;
	}

	printf("Can not delete book from inventory, %d copies are still out on loan.\n",removedBook->loans);
	return;
}
Example #3
0
void Library::addBook()
{
    std::string idCode;
    std::string title;
    std::string author;

    std::cin.ignore(1000, '\n');

    std::cout << "Please enter the idCode of the book: ";
    std::getline(std::cin, idCode);
    std::cout << "Please enter the title of the book: ";
    std::getline(std::cin, title);
    std::cout << "Please enter the author of the book: ";
    std::getline(std::cin, author);

    if(GetBook(idCode) != NULL)
    {
        std::cout << "That book ID already exists!" << std::endl;
        std::cout << "Returning to menu." << std::endl << std::endl;
        return;
    }

    Book tmpBook(idCode, title, author);
    holdings.push_back(tmpBook);

}
Example #4
0
// Determines the type of set and calls the appropriately instantiated
// s_GetLabel
bool CPub_set::GetLabel(string* label, TLabelFlags flags,
                        ELabelVersion version) const
{
    // Ensure label exists
    if (!label) {
        return false;
    }
    
    switch (Which()) {
    case e_Pub:
        return s_GetLabel<CPub>(label, GetPub(), flags, version);
    case e_Medline:
        return s_GetLabel<CMedline_entry>(label, GetMedline(), flags, version);
    case e_Article:
        return s_GetLabel<CCit_art>(label, GetArticle(), flags, version);
    case e_Journal:
        return s_GetLabel<CCit_jour>(label, GetJournal(), flags, version);
    case e_Book:
        return s_GetLabel<CCit_book>(label, GetBook(), flags, version);
    case e_Proc:
        return s_GetLabel<CCit_proc>(label, GetProc(), flags, version);
    case e_Patent:
        return s_GetLabel<CCit_pat>(label, GetPatent(), flags, version);
    default:
        return false;
    }
}
Example #5
0
BOOL BookModel::DeleteBook(CString strBookName)
{
	CString strFile = GetBook(strBookName);
	if (PathIsDirectory(strFile)) {
		DeleteDirectory(strFile);
	} else {
		DeleteFile(strFile);
	}
	return TRUE;
}
Example #6
0
//Takes a patron and book ID
//Checks to make sure that the patron and book exist, returns if they dont
//If book is on hold, only check out to that patron
//If the book is on the shelf, it's fair game, set proper values.
void Library::checkOutBook(std::string patronID, std::string bookID)
{
    Book* book = GetBook(bookID);
    Patron* patron = GetPatron(patronID);

    if(book == NULL || patron == NULL)
    {
        if(book == NULL)
        {
            std::cout << std::endl << "No such book in holdings." << std::endl;
        }
        if(patron == NULL)
        {
            std::cout << std::endl << "No such patron in records." << std::endl;
        }

        return;
    }

    if(book->getLocation() == CHECKED_OUT)
    {
        std::cout << "This book is already checked out." << std::endl << std::endl;
    }
    else if(book->getLocation() == ON_HOLD)
    {
        if(book->getRequestedBy()->getIdNum() == patron->getIdNum())
        {
            book->setLocation(CHECKED_OUT);
            book->setCheckedOutBy(GetPatron(patronID));
            book->setDateCheckedOut(currentDate);
            book->setRequestedBy(NULL);
            patron->addBook(book);
        }
        else
        {
            std::cout << "This book is on hold and can only be checked out to requestee." << std::endl <<std::endl;
        }
    }
    else
    {
        book->setLocation(CHECKED_OUT);
        book->setCheckedOutBy(patron);
        book->setDateCheckedOut(currentDate);
        patron->addBook(book);
    }
}
Example #7
0
/* Function to return the list of customers that have loaned the book (and not returned their copy yet) */
linked_list *GetCustomerList(char *id, book_db *db_head)
{
	book *myBook;

	/* First get the requested book */
	myBook=GetBook(id,db_head);
	/* If book is not found */
	if (myBook == NULL) {
		printf("\nError: Non-existent books can't be loaned\n");
		return NULL;
	}
	/* If book was found but was not loaned to anyone */
	if (myBook->loans == 0) {
		printf("\nBook with ID %s has not been loaned to anyone.\n",id);
		return NULL;
	}
	/* return customer list */
	return myBook->customers;
}
Example #8
0
//Goes through the public properties of a book and prints them out.
//This will print out if a book is checked out AND who requested it, if that situation is true
void Library::viewBookInfo(std::string bookID)
{
    Book* book = GetBook(bookID);

    if(book == NULL)
    {
        std::cout << "No such holding exists." << std::endl;
    }
    else
    {
        std::cout << std::endl << "ID: " << book->getIdCode() << std::endl;
        std::cout << "Title: " << book->getTitle() << std::endl;
        std::cout << "Author: " << book->getAuthor() << std::endl;

        if(book->getLocation() == ON_SHELF)
        {
            std::cout << "Location: ON SHELF" << std::endl;
        }
        else if(book->getLocation() == ON_HOLD)
        {
            std::cout << "Location: ON HOLD" << std::endl;
            std::cout << "Requested By: " << book->getRequestedBy()->getName() << std::endl;
            std::cout << "Requested By ID: " << book->getRequestedBy()->getIdNum() << std::endl;
        }
        else
        {
            std::cout << "Location: CHECKED OUT" << std::endl;
            std::cout << "Checked out by: " << book->getCheckedOutBy()->getName() << std::endl;
            std::cout << "Checked out by ID: " << book->getCheckedOutBy()->getIdNum() << std::endl;
            std::cout << "Due date: " << book->getDateCheckedOut() + 21 << std::endl;

            if(book->getRequestedBy() != NULL)
            {
                std::cout << "This book is also requested by patron: " << book->getRequestedBy()->getIdNum()
                        << std::endl;

                std::cout << "It should be put on the hold shelf when checked back in." << std::endl;
            }
        }
    }
}
Example #9
0
const CAuth_list& CPub::GetAuthors (void) const
{
  switch (Which()) {
    case CPub::e_Gen :
        return (GetGen().GetAuthors());
    case CPub::e_Sub :
        return (GetSub().GetAuthors());
    case CPub::e_Article :
        return (GetArticle().GetAuthors());
    case CPub::e_Book :
        return (GetBook().GetAuthors());
    case CPub::e_Proc :
        return (GetProc().GetBook().GetAuthors());
    case CPub::e_Patent :
        return (GetPatent().GetAuthors());
    case CPub::e_Man :
        return (GetMan().GetCit().GetAuthors());
    default :
        NCBI_THROW(CSerialException, eNotImplemented,
                   "CPub::GetAuthors: unsupported entry type "
                   + SelectionName(Which()));
  }
}
Example #10
0
bool CPub::IsSetAuthors(void) const
{
    switch (Which()) {
    case CPub::e_Gen :
        return (GetGen().IsSetAuthors());
    case CPub::e_Sub :
        return (GetSub().IsSetAuthors());
    case CPub::e_Article :
        return (GetArticle().IsSetAuthors());
    case CPub::e_Book :
        return (GetBook().IsSetAuthors());
    case CPub::e_Proc :
        return (GetProc().IsSetBook() && GetProc().GetBook().IsSetAuthors());
    case CPub::e_Patent :
        return (GetPatent().IsSetAuthors());
    case CPub::e_Man :
        return (GetMan().IsSetCit() && GetMan().GetCit().IsSetAuthors());
    default :
      break;
  }
  
  return false;
}
Example #11
0
//Return a book, if it is not already on the shelf.
void Library::returnBook(std::string bookID)
{
    Book* book = GetBook(bookID);
    
    if(book == NULL)
    {
        std::cout << std::endl << "No such book in holdings." << std::endl << std::endl;
        return;
    }
    if(book->getLocation() == ON_SHELF)
    {
        std::cout << "This book is already on the shelf." << std::endl;
    }
    else if(book->getLocation() == ON_HOLD)
    {
        std::cout << "This book is on the hold shelf and cannot be returned." << std::endl;
    }
    else
    {
        Patron* patron = book->getCheckedOutBy();

        if(book->getRequestedBy() == NULL)
        {
            book->setLocation(ON_SHELF);
            book->setCheckedOutBy(NULL);
            book->setDateCheckedOut(-1);
            patron->removeBook(book);
        }
        else
        {
            book->setLocation(ON_HOLD);
            book->setCheckedOutBy(NULL);
            book->setDateCheckedOut(-1);
            patron->removeBook(book);
        }
    }
}
Example #12
0
// Appends a label to "label"
bool CPub::GetLabel(string*        label,
                    ELabelType     type,
                    TLabelFlags    flags,
                    ELabelVersion  version) const
{
    static const char* s_PubTypes[14] = {
        "Unknown",
        "Generic",
        "Submit",
        "Medline",
        "MUID",
        "Article",
        "Journal",
        "Book",
        "Proceedings",
        "Patent",
        "PatID",
        "Manuscript",
        "Equiv",
        "PMID" };

    // Check that label exists
    if (!label) {
        return false;
    }

    // Get the index into the s_PubTypes array corresponding to pub type
    int idx = static_cast<int>(Which());
    idx = idx >= 0 && idx < 14 ? idx : 0;

    if (type == eType) {
        // Append pub type to label and return
        *label += s_PubTypes[idx];
        return true;
    }

    if (type == eBoth) {
        // Append pub type to label
        *label += string(s_PubTypes[idx]) + ": ";
    }

    switch (Which()) {
    case e_Muid:
        *label += "NLM" + NStr::IntToString(GetMuid());
        return true;
    case e_Pmid:
        *label += "PM" + NStr::IntToString(GetPmid().Get());
        return true;
    case e_Equiv:
        return GetEquiv().GetLabel(label, flags, version);
    case e_Medline:
        return GetMedline().GetLabel(label, flags, version);
    case e_Article:
        return GetArticle().GetLabel(label, flags, version);
    case e_Journal:
        return GetJournal().GetLabel(label, flags, version);
    case e_Book:
        return GetBook().GetLabel(label, flags, version);
    case e_Proc:
        return GetProc().GetLabel(label, flags, version);
    case e_Man:
        return GetMan().GetLabel(label, flags, version);
    case e_Sub:
        return GetSub().GetLabel(label, flags, version);
    case e_Patent:
        return GetPatent().GetLabel(label, flags, version);
    case e_Pat_id:
        return GetPat_id().GetLabel(label, flags, version);
    case e_Gen:
        return GetGen().GetLabel(label, flags, version);
    default:
        return false;
    }
}
Example #13
0
void CPub::GetTitles(
    TOneTitleRefVec & out_title,
    size_t iMaxToGet ) const
{
    // this "if" lets us assume below this point that 
    // we have room for at least one 
    if( iMaxToGet <= 0 ) {
        return;
    }

    switch( Which() ) {
    case CPub::e_not_set:
    case CPub::e_Medline:
    case CPub::e_Pmid:
    case CPub::e_Pat_id:
        // these types don't have titles, so nothing to do
        break;
    case CPub::e_Gen:
        if( GetGen().IsSetTitle() ) {
            out_title.push_back( 
                xs_GetTitleFromPlainString(
                GetGen().GetTitle()) );
        }
        break;
    case CPub::e_Sub:
        if( GetSub().IsSetDescr() ) {
            out_title.push_back( 
                xs_GetTitleFromPlainString(
                GetSub().GetDescr()) );
        }
        break;
    case CPub::e_Article:
        if( GetArticle().IsSetTitle() && GetArticle().GetTitle().IsSet() ) {
            xs_AppendTitles( out_title, iMaxToGet, GetArticle().GetTitle() );
        }
        break;
    case CPub::e_Journal:
        if( GetJournal().IsSetTitle() ) {
            xs_AppendTitles( out_title, iMaxToGet, GetJournal().GetTitle() );
        }
        break;
    case CPub::e_Book:
        if( GetBook().IsSetTitle() ) {
            xs_AppendTitles( out_title, iMaxToGet, GetBook().GetTitle() );
        }
        break;
    case CPub::e_Proc:
        // what to do here?  It has a book and meeting
        // It's not entirely clear if this is the best course of action
        if( FIELD_CHAIN_OF_2_IS_SET(GetProc(), Book, Title) ) {
            xs_AppendTitles( out_title, iMaxToGet, 
                GetProc().GetBook().GetTitle() );
        }
        break;
    case CPub::e_Patent:
        if( GetPatent().IsSetTitle() ) {
            out_title.push_back( 
                xs_GetTitleFromPlainString(
                GetPatent().GetTitle()) );
        }
        break;
    case CPub::e_Man:
        if( FIELD_CHAIN_OF_2_IS_SET(GetMan(), Cit, Title) ) {
            xs_AppendTitles( out_title, iMaxToGet, 
                GetMan().GetCit().GetTitle() );
        }
        break;
    case CPub::e_Equiv:
        {
            size_t iMaxTitleSizeAllowed = ( out_title.size() + iMaxToGet );
            if( iMaxTitleSizeAllowed < out_title.size() ) {
                // integer overflowed
                iMaxTitleSizeAllowed = 
                    std::numeric_limits<std::size_t>::max();
            }
            FOR_EACH_PUB_ON_PUBEQUIV(pub_it, GetEquiv()) {
                if( out_title.size() >= iMaxTitleSizeAllowed ) {
                    break;
                }

                // dig down recursively
                (*pub_it)->GetTitles(out_title, 
                    (iMaxTitleSizeAllowed - out_title.size()) );
            }
        }
        break;
    default:
        NCBI_THROW(CException, eUnknown, "unhandled pub type");
    }
}