void IndexClient() { /// .Index and client types /// In order to store elements to `Index`, they type must be `Moveable`, have deep copy and /// defined the `operator==` and a `GetHashValue` function or method to compute the hash /// code. It is recommended to use `CombineHash` to combine hash values of types that /// already provide `GetHashValue`: struct Person : Moveable<Person> { String name; String surname; unsigned GetHashValue() const { return CombineHash(name, surname); } bool operator==(const Person& b) const { return name == b.name && surname == b.surname; } Person(String name, String surname) : name(name), surname(surname) {} Person() {} }; Index<Person> p; p.Add(Person("John", "Smith")); p.Add(Person("Paul", "Carpenter")); p.Add(Person("Carl", "Engles")); DUMP(p.Find(Person("Paul", "Carpenter"))); /// }
int main() { std::map<Person,int> people; people[Person("Sue", 30)] = 30; people[Person("Raj", 20)] = 20; people[Person("Mike", 40)] = 40; //this will update the value in the map people[Person("Mike", 40)] = 30; //because of how we overloaded the < operator, only the name is taken into //account when making the comparison. This means, that even though the age //is different, the map still thinks the key is the same so it simply updates //the value associated with the origional "Mike" key. In order to also compare //the age, we need to add that to the operator overload we created. people[Person("Mike", 444)] = 123; //iterators are returned as const to prevent from being modified and chaning //where they are in the map. Because of this, the function print() must be //marked const in order for us to be able to use it. for (auto it = people.begin();it != people.end();++it) { std::cout << it->second << ": " << std::flush; it->first.print(); std::cout << std::endl; } return 0; }
int main(){ pthread_attr_t attr; pthread_t personId[MAX_PEOPLE]; Person person_input[MAX_PEOPLE]; /* set global thread attributes */ pthread_attr_init(&attr); pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); // sem_init(&bathroom, 0, BATHROOM_LIMIT); sem_init( &x, 0, 1 ); // for sem_init, initial value is 3rd argument sem_init( &y, 0, 1 ); sem_init( &z, 0, 1 ); sem_init( &men_in_bathroom, 0, 1 ); sem_init( &women_in_bathroom, 0, 1 ); sem_init( &bathroom_cap, 0, BATHROOM_LIMIT); // eg. bathroom_cap initialized to 4 mcount = 0; wcount = 0; srand(time(NULL)); int nrOfPeople = NR_OF_MALE+ NR_OF_FEMALE; if(nrOfPeople > MAX_PEOPLE){ printf("Too many people readjust values"); return 1; } if(DEBUG) printf("Starting Male threads\n"); long l = 0; // Create male threads for(; l < NR_OF_MALE; ++l){ Person p = Person(l,'m'); if(DEBUG) printf("%ld ", l); person_input[l] = p; if(DEBUG) printf("%s %ld created\n",person_input[l].getGender().c_str(), person_input[l].myid); pthread_create(&personId[l], &attr, man_t, (void *) &person_input[l]); } if(DEBUG) printf("Starting Female threads\n"); // Create female threads for(; l < nrOfPeople; ++l){ Person p = Person(l ,'f'); if(DEBUG) printf("%ld ", l); person_input[l] = p; if(DEBUG) printf("%s %ld created\n",person_input[l].getGender().c_str(), person_input[l].myid); pthread_create(&personId[l+NR_OF_MALE], &attr, woman_t, (void *) &person_input[l]); } for(long l = 0 ; l < nrOfPeople; ++l){ pthread_join(personId[l], NULL); } return 0; }
void testPerson() { Person p = Person("Hello", "World"); Person last = Person("X", "X"); if (p < last) cout << "p is before last in an alphanumeric order" << endl; }
//Default Constructor for OvernightPackage OvernightPackage::OvernightPackage() { sender = Person(); recver = Person(); weight = 0.0 ; ozRate = 0.00; costUp = 0.00; //onPkgToDate = 0; //onPkgToDate++; }
int main() { Building b(3); b.addWaitingPerson(0, Person(2)); // person in floor 0 wants to floor 2 b.addWaitingPerson(1, Person(0)); // person in floor 1 wants to floor 0 b.addWaitingPerson(2, Person(0)); // person in floor 2 wants to floor 0 for (int i = 0; i < 9; i++) { b.moveElevatorToFloor(i % 3); b.removeArrivedPeople(); b.letPeopleIn(); } }
void Sorting::testCountPerson() { vector<Person> people; string name("a"); for (int i=0; i<10; i++) { people.emplace_back(Person(i, name)); } people.emplace_back(Person(5,name)); people.emplace_back(Person(5,name)); count_sort_person_with_key2(people); for (auto &x : people) cout << x.key << endl; }
int printPersonTableINT(QSqlQuery& query, vector<Person>& vect) { int width1 = 24; int width2 = 13; int width3 = 6; char sep = ' '; cout << " " << left << setw(width1) << setfill(sep) << "Name" << " | " << left << setw(width3) << setfill(sep) << "Sex" << " | " << left << setw(width2) << setfill(sep) << "Year of Birth" << " | " << left << setw(width2) << setfill(sep) << "Year of Death" << endl; cout << left << setw(width1 + width2 + width2 + width3 + 10) << setfill('-') << "" << endl; int i = 0; while(query.next()) { vect.push_back(Person(query.value("name").toString().toStdString(), query.value("sex").toString().toStdString(), query.value("year_birth").toInt(), query.value("year_death").toInt())); cout << " " << left << setw(width1) << setfill(sep) << vect.back().getnm() << " | " << right << setw(width3) << setfill(sep) << vect.back().getsx() << " | " << right << setw(width2) << setfill(sep) << vect.back().getbrth() << " | "; if(vect.back().getdth() == 0) cout << right << setw(width2) << setfill(sep) << "" << endl; else cout << right << setw(width2) << setfill(sep) << vect.back().getdth() << endl; i++; } return i; }
Person PersonsTreeModel::person(const QModelIndex &index) const { if (!index.isValid() || index.parent().isValid()) return Person(); PersonTreeItem* item = static_cast<PersonTreeItem*>(index.internalPointer()); return item->person(); }
int candy(vector<int> &ratings) { int n = ratings.size(); if (n <= 1) { return n; } priority_queue<Person> heap; for (int i = 0; i < n; ++ i) { heap.push(Person(i, ratings[i])); } int *candies = new int [n]; for (int i = 0; i < n; ++ i) { candies[i] = 0; } int answer = 0; for (int i = 0; i < n; ++ i) { Person now = heap.top(); heap.pop(); int pos = now.position; int needs = 1; if (pos > 0 && candies[pos - 1] && ratings[pos - 1] < ratings[pos]) { needs = max(needs, candies[pos - 1] + 1); } if (pos != n - 1 && candies[pos + 1] && ratings[pos + 1] < ratings[pos]) { needs = max(needs, candies[pos + 1] + 1); } candies[pos] = needs; answer += needs; } return answer; }
//------------------------------------------------------------------------------ // setData // sets data from istream file // sets movie data first from movie class // actor, release date is filled in if successful bool Classic::setData(istream &infile) { if (setMovieData(infile)) { // actor string first, last; infile >> first >> last; _actor = Person(first, last); // date int month, year; infile >> month >> year; if (year >= MOVIE_EARLIEST_DATE && year <= CURRENT_YEAR) { if (month != 0) { _releaseDate = Date(month, year); return true; } else { cerr << "Invalid Movie Month: " << month << endl; return false; } } else { // deletes movie if it is not within possible dates cerr << "Invalid Movie Year: " << year << endl; return false; } } else { return false;
std::vector<Person> PersonRepository::getPeople(const PersonSortTypes st, const Order o, std::string sq) { std::vector<Person> peepz = std::vector<Person>(); if(!Database::getCurrent()->prepare()) return peepz; QString search = QString("%") + QString::fromStdString(sq) + QString("%"); QSqlQuery query; std::ostringstream str; str << st; QString sts = QString::fromStdString(str.str()); query.prepare("SELECT * FROM persons WHERE FirstName LIKE :search" " OR SurName LIKE :search OR Description LIKE :search" " ORDER BY " + sts + " " + (o==ASCENDING?"ASC":"DESC")); query.bindValue(":search", search); query.exec(); while(query.next()) { Person p = Person(); p.id = query.value("ID").toInt(); p.firstname = query.value("FirstName").toString().toStdString(); p.surname = query.value("SurName").toString().toStdString(); p.gender = query.value("Gender").toString() == "M" ? MALE : FEMALE; p.dob = Date::fromString(query.value("DoB").toDate().toString("dd/MM/yyyy")); bool temp = query.value("DoD").isNull(); p.dod = temp ? Date() : Date::fromString(query.value("DoD").toDate().toString("dd/MM/yyyy")); p.description = query.value("Description").toString().toStdString(); peepz.push_back(p); } return peepz; }
int main() { Person p = Person(); //Student s = Student();//can't instantiate return 0; }
Person CardReader::read() { errorCode = 10000; if (connected) { wchar_t path[256]; personImagePath().toWCharArray(path); PERSONINFOW p; errorCode = ::GetPersonMsgW(&p, path); errorString = readError(); return Person(p); } return Person(); }
std::vector<Person> PersonRepository::getAllDisconnected(int cid) { std::vector<Person> peepz = std::vector<Person>(); if(!Database::getCurrent()->prepare()) return peepz; QSqlQuery query; query.prepare("SELECT * FROM Persons WHERE NOT EXISTS (SELECT * FROM Connections WHERE p_id = id AND c_id = :cid)"); query.bindValue(":cid", cid); query.exec(); while(query.next()) { Person p = Person(); p.id = query.value("ID").toInt(); p.firstname = query.value("FirstName").toString().toStdString(); p.surname = query.value("SurName").toString().toStdString(); p.gender = query.value("Gender").toString() == "M" ? MALE : FEMALE; p.dob = Date::fromString(query.value("DoB").toDate().toString("dd/MM/yyyy")); bool temp = query.value("DoD").isNull(); p.dod = temp ? Date() : Date::fromString(query.value("DoD").toDate().toString("dd/MM/yyyy")); p.description = query.value("Description").toString().toStdString(); peepz.push_back(p); } return peepz; }
Person setPerson() { string name, sex; int brth, dth; legalPerson(name, sex, brth, dth); return Person(name, sex, brth, dth); }
Person Menu::findPersonById(int id, vector<Person> people) { vector<Skill> skills; for(int i = 0; i < people.size(); i++) if(people[i].getID() == id) return people[i]; return Person(-1, "invalid", skills); }
void mousePressed(int x, int y, int b) { if(!selected) { selected = true; selectedIndex = people.size(); people.push_back(Person(x - ofGetWidth() / 2, y - ofGetHeight() / 2, people.size())); if(people.size() > 1) { pulses.push_back(Pulse(people.back().getAngle(), selectedIndex)); } } }
// Helper function to read a person from cin Person getPerson() { string first; string second; cout << "Enter a first name: " ; getline(cin, first); cout << "Enter a second name: " ; getline(cin, second); return Person(first, second); }
void VectorMyJosephus::init(int N,int M) { mSize=N; mM=M; circ.clear(); for (int i=0; i<N; i++) circ.push_back(Person(i)); iter=circ.begin(); }
void GameCanvas::add_person(QPoint pos, QString gfx) { Person person = Person(); person.x = pos.x(); person.y = pos.y(); person.gfx = gfx; people.append(person); // reset cache this->reset_cache(); }
void Menu::addPerson() { const std::string& personName = textbox->getText(); if (!personName.empty() && !persons.contains(personName)) { persons.add(Person(personName)); listbox[ALL_PLAYER_LIST]->addItem(personName); rebuildTable(); textbox->flush(); } }
bool PersonsTableModel::insertRows(int row, int count, const QModelIndex &parent) { Q_UNUSED(parent) Q_D(PersonsTableModel); beginInsertRows(parent, row, row+count-1); QList<Person>::Iterator iterBefore = d->persons.begin()+row; for (int i = 0; i < count; ++i) { iterBefore = d->persons.insert(iterBefore, Person())+1; } endInsertRows(); return true; }
std::vector<Person> buildPeople() { std::vector<Person> people; people.push_back(Person("Jeff", "Scaparra", 32)); people.push_back(Person("Aaron", "Bray", 28)); people.push_back(Person("Chet", "Wall", 35)); people.push_back(Person("Charles", "Heaton", 30)); people.push_back(Person("Agent", "Smith", 007)); people.push_back(Person("Cleaning", "Lady", 23)); people.push_back(Person("Mail", "Mann", 57)); return people; }
/** * @brief FacialModule::onListRequest * Listing de toutes les personnes contenues dans le fichier csv * @param p */ void FacialModule::onListRequest(Packet *p) { map<int, string>::iterator iter; PeopleVector *vp = new PeopleVector(); map<int, string> names = FacialUtils::reloadFromCSVFile(FICHIER); for(iter = names.begin(); iter != names.end(); ++iter) { vp->push_back(Person(iter->second)); } ListResultPacket pReturn(p); pReturn.setPeopleVector(vp)->doSend(); }
int main() { Person p = Person("Karim", 1986); Person* p2 = new Person("Karim+1", 1987); p.info(); p2->info(); int nbr = Person::population(); std::cout << "The number of persons: " << nbr << "\n"; delete p2; //delete the pointer nbr = Person::population(); std::cout << "The number of persons: " << nbr << "\n"; }
Person::container_t getAllPersons() { Person::container_t persons; database_t db = db_acquire(); sqlite3pp::query q(*db, "SELECT id, fname, lname FROM Person"); for (sqlite3pp::query::iterator i = q.begin(), end(q.end()); i != end; ++i) { Person::identifier_t identifier = 0; char const* fname = NULL, *lname = NULL; boost::tie(identifier, fname, lname) = i->get_columns<int, char const*, char const*>(0,1,2); persons.push_back(Person(identifier, Person::string_t(fname), Person::string_t(lname))); } return persons; }
//------------------------------------------------------------------------------ // setMovieData // sets movie director and title bool Movie::setMovieData(istream &infile) { // sets director string first, last; infile >> first; infile.get(); getline(infile, last, ','); _director = Person(first, last); // sets title infile.get(); getline(infile, _title, ','); infile.get(); return true; }
List Person::people(){ std::vector<Person> people; people.push_back(Person("Robert","Male","Single")); people.push_back(Person("John","Male","Married")); people.push_back(Person("Laura","Female","Married")); people.push_back(Person("Diana","Female","Single")); people.push_back(Person("Mike","Male","Single")); people.push_back(Person("Bobby","Male","Single")); return people; }
bool KOTodoEditor::processInput() { if(!validateInput()) return false; if(mTodo) { bool rc = true; Todo *oldTodo = mTodo->clone(); Todo *todo = mTodo->clone(); kdDebug(5850) << "KOTodoEditor::processInput() write event." << endl; writeTodo(todo); kdDebug(5850) << "KOTodoEditor::processInput() event written." << endl; if(*mTodo == *todo) // Don't do anything kdDebug(5850) << "Todo not changed\n"; else { kdDebug(5850) << "Todo changed\n"; //IncidenceChanger::assignIncidence( mTodo, todo ); writeTodo(mTodo); mChanger->changeIncidence(oldTodo, mTodo); } delete todo; delete oldTodo; return rc; } else { mTodo = new Todo; mTodo->setOrganizer(Person(KOPrefs::instance()->fullName(), KOPrefs::instance()->email())); writeTodo(mTodo); if(!mChanger->addIncidence(mTodo, this)) { delete mTodo; mTodo = 0; return false; } } return true; }