int main() { int num_shirts; cout << "How many articles are you going to purchase?"; cin >> num_shirts; Article tempArticle; tempArticle.display(num_shirts); double price_select = 10.00; cout << "What do you want to purchase?" << endl; cout << "Type 0 for shirt, 1 for pants, 2 for underwear: "; int type_select = 0; cin >> type_select; cout << endl << "You chose: " << type_select << endl; cout << "What size are you looking for?" << endl; int size_select = 0; cin >> size_select; cout << endl << "You chose: " << size_select; //cout << endl << "And is this for a man or a woman?" << endl; //cout << endl << "Type 0 for men's or 1 for women's: "; //int gender_select = 0; //cin >> gender_select; //cout << endl << "You chose: " << gender_select << endl; tempArticle.display(type_select, size_select, price_select, num_shirts); return 0; }
void GraphNode :: printPublications(){ printf("pubsList: \n"); for (int p =0; p< pubs.size(); p++){ Article * tmp = pubs.at(p); //printf(" %i 'th id is: \n", p); printf(" article %i: %s, %s \n", p+1, tmp->getId().c_str(), tmp->getTitle().c_str()); } }
void Feed::appendArticle(const Article& a) { if ( (a.keep() && Settings::doNotExpireImportantArticles()) || ( !usesExpiryByAge() || !isExpired(a) ) ) // if not expired { if (!d->articles.contains(a.guid())) { d->articles[a.guid()] = a; if (!a.isDeleted() && a.status() != Read) setUnread(unread()+1); } } }
/* * Reads a list of articles from the specified FILE. * This function always returns a valid List. * * This function is used to read datasheets in from * stdin during product registration. */ static List * read_articles(FILE *in) { List *result = _wsreg_list_create(); if (in != NULL) { /* * Set up a file reader to read the articles */ char *end_tokens[] = { "--", "\5", "\255", NULL}; Ds_article_input_stream *ais = NULL; File_reader *fr = _wsreg_freader_create(in, end_tokens); fr->set_echo_function(fr, input_text); /* * Set up the datasheet article input stream. */ ais = _wsreg_dsais_open(fr); if (ais != NULL) { /* * Read the articles into a list. */ while (ais->has_more_articles(ais)) { Article *a = ais->get_next_article(ais); if (a != NULL) { /* * Be sure the new Article has a valid * id. */ a->generate_id(a); log_message("DEBUG", " < adding article %s [id=%s]>\n", 2, a->get_mnemonic(a), a->get_id(a)); result->add_element(result, a); } } ais->close(ais); } fr->free(fr); } return (result); }
void View::addArticle(const Article &article) { Button *btn = new Button(article.draw(QRect(0, 0, 700 / 3, 700 / 3))); connect(btn, SIGNAL(pressed()), this, SLOT(articleClicked())); btn->resize(700 / 3, 700 / 3); btn->setPos((_cptArticles % 3) * (700 / 3), (_cptArticles / 3) * (700 / 3) + 30); scene()->addItem(btn); ++_cptArticles; }
void View::addArticle(const Article &article) { unsigned int w = size().width() / 3; unsigned int h = (size().height() - _topBar->size().height()) / 3; Button *btn = new Button(article.draw(QRect(0, 0, w, h))); connect(btn, SIGNAL(pressed()), this, SLOT(articleClicked())); btn->resize(w, h); btn->setPos((_cptArticles % 3) * (w), (_cptArticles / 3) * h + _topBar->size().height()); scene()->addItem(btn); ++_cptArticles; }
/* * AJJOUTEZ UN ARTICLE * */ int articledao::addArticle(Article &article) { QSqlDatabase db = QSqlDatabase::database(); if(db.open()){ QSqlQuery q; q.prepare(QLatin1String("insert into Article(name,description,page,magazine) values(?,?,?,?)")); q.addBindValue(article.getTitle()); q.addBindValue(article.getDescription()); q.addBindValue(article.getPage()); q.addBindValue(article.getmagID()); q.exec(); db.close(); return q.lastInsertId().toInt(); } //fail to connect return -1; }
void SqlBackendTest::collections() { Collection col( "Article" ); Article *article; CollectionIterator it( col.begin() ); CollectionIterator end( col.end() ); for ( ; it != end; ++it ) { article = static_cast<Article*>( *it ); // As long as we don't have a way to sort collections, we won't be // able to make this test nicer if ( article->label() != "Article One" && article->label() != "Article Two" ) { CHECK( true, false ); } } ObjectRef<Customer> c1 = Customer::create(); c1->setCustomerName( "foo" ); ObjectRef<Customer> c2 = Customer::create(); c2->setCustomerName( "bar" ); ObjectRef<Article> a1 = Article::create(); a1->setLabel( "foo" ); a1->setDescription( "liluli foo liluli" ); ObjectRef<CustomerOrder> o1 = CustomerOrder::create(); o1->setNumber( 3000 ); o1->setCustomer( c1 ); o1->articles()->add( a1 ); Manager::self()->commit(); Collection col2( "SELECT Customer.* WHERE Customer.Customer_CustomerOrder.Article_CustomerOrder.description like '%foo%'" ); Customer *customer; CollectionIterator it2( col2.begin() ); CollectionIterator end2( col2.end() ); CHECK( col2.begin() == col2.end(), false ); for ( ; it2 != end2; ++it2 ) { customer = static_cast<Customer*>( *it2 ); // As long as we don't have a way to sort collections, we won't be // able to make this test nicer CHECK( customer->customerName(), QString( "foo" ) ); } }
void testDataStructures(){ printf("number of unique authors: %d \n", (int)author_id_name.size()); printf("number of unique articles: %d \n", (int)article_id_art.size()); printf("created authors: %d \n", (int) authors.size()); Article * lastarticle = articles.back(); vector<string> lastauthors = lastarticle->authorsList(); for (int s=0; s < lastauthors.size(); s++) { printf("author %d is: %s \n", s+1, lastauthors.at(s).c_str()); } Author * lastauthor = authors.back(); vector<string> lastauthpubs = lastauthor->pubsList(); for (int p=0; p < lastauthpubs.size(); p++) { printf("pubs %d is: %s \n", p+1, lastauthpubs.at(p).c_str()); } }
void Feed::setArticleChanged(Article& a, int oldStatus) { if (oldStatus != -1) { int newStatus = a.status(); if (oldStatus == Read && newStatus != Read) setUnread(unread()+1); else if (oldStatus != Read && newStatus == Read) setUnread(unread()-1); } d->updatedArticlesNotify.append(a); articlesModified(); }
bool Feed::isExpired(const Article& a) const { QDateTime now = QDateTime::currentDateTime(); int expiryAge = -1; // check whether the feed uses the global default and the default is limitArticleAge if ( d->archiveMode == globalDefault && Settings::archiveMode() == Settings::EnumArchiveMode::limitArticleAge) expiryAge = Settings::maxArticleAge() *24*3600; else // otherwise check if this feed has limitArticleAge set if ( d->archiveMode == limitArticleAge) expiryAge = d->maxArticleAge *24*3600; return ( expiryAge != -1 && a.pubDate().secsTo(now) > expiryAge); }
bool Article::operator==(const Article &other) const { return d->title == other.title() && d->link == other.link() && d->description == other.description() && d->pubDate == other.pubDate() && d->guid == other.guid() && d->guidIsPermaLink == other.guidIsPermaLink(); }
Article * Article::create(const QString &title, const QString &description, const QUrl &link, const QDateTime ×tamp, const QString &image, QObject *parent) { Article * returned = new Article(parent); returned->d_func()->data.setTitle(title); returned->d_func()->data.setDescription(description); returned->d_func()->data.setLink(link); returned->d_func()->data.setTimestamp(timestamp); returned->d_func()->data.setImage(image); return returned; }
/* * UPDATE UN ARTICLE * */ int articledao::updateArticle(Article &article) { QSqlDatabase db = QSqlDatabase::database(); if(db.open()){ QSqlQuery q; q.prepare(QLatin1String("UPDATE Article SET name = ?, description = ?, page = ?,magazine = ? WHERE ID = ?")); q.addBindValue(article.getTitle()); q.addBindValue(article.getDescription()); q.addBindValue(article.getPage()); q.addBindValue(article.getmagID()); q.addBindValue(article.getID()); q.exec(); db.close(); return article.getID(); } //fail to connect return -1; }
bool Criterion::satisfiedBy(const Article &article) const { if (article.isNull()) { return false; } QVariant concreteSubject; switch (m_subject) { case Title: concreteSubject = QVariant(article.title()); break; case Description: concreteSubject = QVariant(article.description()); break; case Link: // ### Maybe use prettyUrl here? concreteSubject = QVariant(article.link().url()); break; case Status: concreteSubject = QVariant(article.status()); break; case KeepFlag: concreteSubject = QVariant(article.keep()); break; case Author: concreteSubject = QVariant(article.authorName()); default: break; } bool satisfied = false; const Predicate predicateType = static_cast<Predicate>(m_predicate & ~Negation); QString subjectType = QLatin1String(concreteSubject.typeName()); switch (predicateType) { case Contains: satisfied = concreteSubject.toString().indexOf(m_object.toString(), 0, Qt::CaseInsensitive) != -1; break; case Equals: if (subjectType == QLatin1String("int")) { satisfied = concreteSubject.toInt() == m_object.toInt(); } else { satisfied = concreteSubject.toString() == m_object.toString(); } break; case Matches: satisfied = QRegExp(m_object.toString()).indexIn(concreteSubject.toString()) != -1; break; default: qCDebug(AKREGATOR_LOG) << "Internal inconsistency; predicateType should never be Negation"; break; } if (m_predicate & Negation) { satisfied = !satisfied; } return satisfied; }
ArticleListBoxItem::ArticleListBoxItem( QListBox *listbox, const Article &article ) : QListBoxText( listbox ), m_article( article ) { setText( article.title() ); }
void Feed::appendArticles(const Syndication::FeedPtr feed) { d->setTotalCountDirty(); bool changed = false; const bool notify = useNotification() || Settings::useNotifications(); QList<ItemPtr> items = feed->items(); QList<ItemPtr>::ConstIterator it = items.constBegin(); QList<ItemPtr>::ConstIterator en = items.constEnd(); int nudge=0; QList<Article> deletedArticles = d->deletedArticles; for ( ; it != en; ++it) { if ( !d->articles.contains((*it)->id()) ) // article not in list { Article mya(*it, this); mya.offsetPubDate(nudge); nudge--; appendArticle(mya); d->addedArticlesNotify.append(mya); if (!mya.isDeleted() && !markImmediatelyAsRead()) mya.setStatus(New); else mya.setStatus(Read); if ( notify ) NotificationManager::self()->slotNotifyArticle( mya ); changed = true; } else // article is in list { // if the article's guid is no hash but an ID, we have to check if the article was updated. That's done by comparing the hash values. Article old = d->articles[(*it)->id()]; Article mya(*it, this); if (!mya.guidIsHash() && mya.hash() != old.hash() && !old.isDeleted()) { mya.setKeep(old.keep()); int oldstatus = old.status(); old.setStatus(Read); d->articles.remove(old.guid()); appendArticle(mya); mya.setStatus(oldstatus); d->updatedArticlesNotify.append(mya); changed = true; } else if (old.isDeleted()) deletedArticles.removeAll(mya); } } QList<Article>::ConstIterator dit = deletedArticles.constBegin(); QList<Article>::ConstIterator dtmp; QList<Article>::ConstIterator den = deletedArticles.constEnd(); // delete articles with delete flag set completely from archive, which aren't in the current feed source anymore while (dit != den) { dtmp = dit; ++dit; d->articles.remove((*dtmp).guid()); d->archive->deleteArticle((*dtmp).guid()); d->removedArticlesNotify.append( *dtmp ); changed = true; d->deletedArticles.removeAll(*dtmp); } if (changed) articlesModified(); }
Article * Article::create(const ArticleData &articleData, QObject *parent) { Article * returned = new Article(parent); returned->d_func()->data = articleData; return returned; }
/* * Registers articles. The arguments in the specified * list are (in order): * * install location * datasheet filename * parent mnemonic * parent id * * All of these arguments are optional. * * The install location refers to the directory in which the software * has been installed. * * The datasheet filename specifies the name of the file that contains * the data representing articles to be registered. If the datasheet * filename is not provided, the datasheet information will be read * from stdin. * * The parent mnemonic specifies the name of the article which is the * parent of the article(s) being registered with this call. * * The parent id specifies the instance of the article which is the * parent of the article(s) being registered with this call. * * This function returns the id of the article being registered. */ static char * register_articles(List *arg_list) { /* * The default datasheet file is stdin. */ FILE *in = stdin; char *result = NULL; char *location = NULL; char *parent_mnemonic = NULL; char *parent_id = NULL; Wsreg_component *parent_component = NULL; List *matches = NULL; List *article_list = NULL; Conversion *conversion; if (arg_list->size(arg_list) > 0) { /* * Install location, datasheet filename. */ char *path; location = (char *)arg_list->element_at(arg_list, 0); if (strcmp(location, "-") == 0) { location = NULL; } path = (char *)arg_list->element_at(arg_list, 1); in = NULL; if (path != NULL) { in = fopen(path, "r"); } if (in == NULL) { (void) fprintf(stderr, PRODREG_CANT_READ_FILE, path); (void) fprintf(stderr, "\n"); return (""); } if (arg_list->size(arg_list) > 2) { /* * Parent mnemonic, parent id. */ parent_mnemonic = (char *)arg_list->element_at(arg_list, 2); parent_id = (char *)arg_list->element_at(arg_list, 3); if (parent_mnemonic != NULL && parent_id != NULL) { matches = get_matching_components(parent_mnemonic, parent_id); if (matches != NULL && matches->size(matches) == 1) { parent_component = (Wsreg_component *) matches->element_at(matches, 0); } else { (void) fprintf(stderr, PRODREG_NO_SUCH_COMPONENT, parent_mnemonic, parent_id); (void) fprintf(stderr, "\n"); } } } } article_list = read_articles(in); conversion = _wsreg_conversion_create(NULL); /* * Creates associations between parent Article and * child Article. */ conversion->create_associations(article_list); /* * Convert the articles to Wsreg_component structures * and register. */ article_list->reset_iterator(article_list); while (article_list->has_more_elements(article_list)) { Article *a = (Article *)article_list->next_element(article_list); /* * The install location passed in overrides that in the * datasheet. I am not sure where this would be applicable. * Is it really that the datasheet is incorrect and the * user knows best here? */ if (location != NULL) { a->set_property(a, "installlocation", location); } conversion->add_article(conversion, a); result = a->get_id(a); } conversion->register_components(conversion, parent_component, TRUE); conversion->free(conversion); if (matches != NULL) { matches->free(matches, (Free)wsreg_free_component); } return (result); }
/*! \fn Generator::generateArticles(unsigned) generates all objects of article publications for specified year, including the basic attributes (added as related triples) @param year current year @param j_pool pointer to pool with available journals @return pool with generated triple objects */ RDFTriplePool Generator::generateArticles(unsigned year, RDFTriplePool *j_pool, unsigned & total_nr_articles) { RDFTriplePool ret; unsigned cnt = Functions::article(year); // adapt counts total_nr_articles+=cnt; if(! cnt) return ret; //to avoid non-necessary (but dangerous) calculations if(! j_pool->count() && cnt > 0) { /* that one is a bit complicated; articles without journals exist, but they're rare, so we don't expect the case of having articles but no journals in a year. to avoid any misdistribution in output, abort in case it should happen, though ;-) */ cout << "state with invalid constellation of journals/articles reached" << endl; exit(8); } vector <unsigned> journal_sizes; //expectation values for conference sizes GaussianDistribution g(1, cnt/j_pool->count(), .2 * cnt/j_pool->count()); //initializing expectation values for journal sizes... for(unsigned i = 0; i < j_pool->count(); i++) { journal_sizes.push_back(g.getRandomnizedValue()); } //for unsigned journal_num = 0; for(unsigned i = 0; i < cnt; i++) { //distributing papers over journal (exp. sizes); if sum of exp. vals is a bit //too small, just rotate equally from beginning for remaining talks... if(journal_sizes[journal_num]) journal_sizes[journal_num]--; else journal_num++; if(journal_num >= j_pool->count()) journal_num = 0; Article * e = new Article(i+1, year, journal_num+1); /*as it happens, this numeric id part is equal to pos of journal in pool + 1 however it is important to associate only those articles that really have a journal attribute */ if(e->requireJournal()) { j_pool->getAt(journal_num)->addRelated(e,false); RDFTriple *t = new PropertyJournal(e, j_pool->getAt(journal_num)); e->addRelated(t, true); } ret.add(e); } //for return ret; } //generateArticles()
void createGraphDataStructures(){ //create graph nodes map<string, string>::iterator auth; for(auth = author_id_name.begin(); auth != author_id_name.end(); auth++) { string idd = auth->first; string authorname = auth->second; int idpos = nodes.size(); GraphNode * anewnode = new GraphNode (idpos, idd, authorname); gnode_by_id[idd] = anewnode; nodes.push_back(anewnode); } //now create edges map<string, Article*>::iterator art; for(art = article_id_art.begin(); art != article_id_art.end(); art++) { string articleid = art->first; Article* thearticle = art->second; vector<string> auths = thearticle->authorsList(); //for each author in an article, create an edge connecting that to the rest for (int s= 0; s<auths.size(); s++) { string auth1 = auths.at(s); for (int rest=s+1; rest<auths.size(); rest++) { string auth2 = auths.at(rest); if (auth1 == auth2) { printf("ERROR: author duplicate %s \n", auth1.c_str()); } //create an edge between aut1 and aut2 //but... //need to prevent duplicates string edgekey1 = auth1+auth2; string edgekey2 = auth2+auth1; //whichever encountered before, we don't know if (edges_by_ids.count(edgekey1) > 0 || edges_by_ids.count(edgekey2) > 0 ) { //this edge exists } else{ int posid = edges.size(); GraphEdge * anewedge = new GraphEdge(posid, auth1, auth2); edges.push_back(anewedge); edges_by_ids[edgekey1] = anewedge; edges_by_ids[edgekey2] = anewedge; } } } } //now print all edges //printf("all number of edges created % d \n ", (int)edges.size()); //edges sanity check /* for (int e=0; e<edges.size(); e++) { GraphEdge * edg = edges.at(e); string efrom = edg->from; string eto = edg->to; for (int c=0; c<edges.size(); c++) { GraphEdge * compare = edges.at(c); if (compare->from == efrom && compare->to == eto) { if (e != c) { printf("duplicate at: %d, %d \n", e, c); } } } //printf("edge id: %d, from: %s, to: %s \n", edg->getEdgeid(), edg->from.c_str(), edg->to.c_str()); } */ }