Ejemplo n.º 1
0
void BookCollection::addDescription(BookDescriptionPtr description) {
  if (description.isNull()) {
    return;
  }

  AuthorPtr author = description->author();
  const std::string &displayName = author->displayName();
  const std::string &sortKey = author->sortKey();

  std::map<AuthorPtr,Books>::iterator it = myCollection.begin();
  for (; it != myCollection.end(); ++it) {
    AuthorPtr author1 = (*it).first;
    if ((author1->sortKey() == sortKey) && (author1->displayName() == displayName)) {
      break;
    }
  }
  if (it != myCollection.end()) {
    (*it).second.push_back(description);
  } else {
    Books books;
    books.push_back(description);
    myCollection.insert(std::pair<AuthorPtr,Books>(author, books));
    myAuthors.push_back(author);
  }
}