int main() { PhoneBook phoneBook; Contacts contact; bool ProgramOn = true; int option; while (ProgramOn) { Intro(); cin >> option; cout << endl; switch (option) { case 1: cout << "Insert contact data : \n "; contact.getData(phoneBook); phoneBook.contacts.push_back(contact); break; case 2: { string contactName; cout << "Insert contact name : "; cin >> contactName; if (checkIfExist(phoneBook, contactName) != -1) { phoneBook.contacts[checkIfExist(phoneBook, contactName)].showContact(); } else { cout << "Contact " << contactName << " doesn't exist !\n"; } } break; case 3: { string contactName; cout << "\n Contacts in phoneBook : "<< phoneBook.getContactNumbers() <<"\n"; for (int i = 0; i < phoneBook.contacts.size(); i++) { cout << phoneBook.contacts[i].getContactName(); cout << "\n\n"; } } break; case 4: ProgramOn = false; break; default: cout << "Wrong option ! "; break; } } system("PAUSE"); }
int main(){ // PH // Tests classes Record and Contacts int status=0; cout << "Testing classes Record and Contacts \n\n"; Contacts list; //constructs Contacts list object including memory allocation status = list.readContacts(); cout << "\nStatus from list.readContacts is: " << status << " Expecting 97.\n"; status = list.enterNew(); cout << "\nStatus from list.enterNew is: " << status << " Expecting 95.\n"; status = list.findRecord(0,"Paul"); cout << "\nStatus from list.findRecord is: " << status << " Expecting 94.\n"; status = list.printFind("Paul"); cout << "\nStatus from list.printFind is: " << status << " Expecting 92.\n"; list.swapRecords(0,1); list.printContacts(); status = list.closeContacts(); cout << "\nStatus from list.closeContacts is: " << status << " Expecting 96.\n"; return 0; }
int main() { Contacts contacts; size_t n; cin >> n; while (n--) { std::string command, parameter; cin >> command >> parameter; if (command == "add") { contacts.insert(parameter); } else if (command == "find") { cout << contacts.lookup(parameter) << '\n'; } } return 0; }
void* doTask(void* q){ while (true) { int sock = taskList.pop(); while(true){ cout << "message recieved from socket " << sock << endl << endl << endl; vector<char>recvMsg; int sizeRecvMessage = 1024; long len = sizeRecvMessage; while(len == 1024){ char recvMessage[sizeRecvMessage]; len = recv(sock, recvMessage, sizeRecvMessage, 0); recvMsg.insert(recvMsg.end(), recvMessage, recvMessage+len); if(len == -1){ cerr << "ERROR: failed on receiving" << endl; exit(1); } } if (recvMsg.empty()) { break; } cout << &(recvMsg[0]) << endl; handleMessage(sock, recvMsg); } cout << "socket closed: " << sock << endl; conts.logoutOfEveryUserWithSock(sock); close(sock); } return NULL; }
void login1(int sock, string nickName, string pass){ cout << "login with: " << &(nickName[0]) << " password:"******"lin:" + conts.change(sock, nickName, pass); if (send(sock, &(response[0]), response.length(), 0)) perror("send"); cout << &(response[0]) << endl; }
void friends(int sock, string msg){ string allusers = "frd:"; vector<string> nickNames = conts.getAllUsers(); for (int i = 0; i < nickNames.size(); i++){ allusers = allusers + "\n" + nickNames[i]; } if (send(sock, &(allusers[0]), allusers.length(), 0)) perror("send"); }
void logout(int sock, string msg){ string nickNamePass (msg.begin() + 4, msg.end()); cout << "log out of nickname: " << &(nickNamePass[0]) << endl; conts.logout(nickNamePass); string whatToSend = "done"; if (send(sock, &(whatToSend[0]), whatToSend.length(), 0)) perror("send"); cout << &(whatToSend[0]) << endl; }
Contacts PhoneBookI::findContacts(const string& name, const Ice::Current& c) const { try { vector<Ice::Identity> identities = _index->find(name); Contacts contacts; contacts.reserve(identities.size()); transform(identities.begin(), identities.end(), back_inserter(contacts), IdentityToContact(c.adapter)); return contacts; } catch(const Freeze::DatabaseException& ex) { DatabaseException e; e.message = ex.message; throw e; } }
void ParticipantList::populate( const Contacts& rContacts, IMChatSession& imChatSession ) { Participant participant; IMContact* imContact = NULL; bool bAlreadyInChat = false; for ( Contacts::const_iterator it = rContacts.begin(); it != rContacts.end(); it++ ) { if ( includeInCandidateList( (*it).second, imChatSession, bAlreadyInChat ) ) { Contact c = (*it).second; imContact = c.getPreferredIMContact(); participant.setIMContact ( *imContact ); participant.setDisplayName ( c.getDisplayName() ); participant.setIsAlreadyInChat( bAlreadyInChat ); participant.setPixmap ( determineStatus( c ) ); Add( &participant ); } } }
int Read::run(int, char*[]) { ConnectionPtr connection = createConnection(communicator(), "db"); const Contacts contacts(connection, "contacts", false); Contacts::const_iterator p; cout << "All contacts (default order)" << endl; for(p = contacts.begin(); p != contacts.end(); ++p) { cout << p->first << ":\t\t" << p->second.phoneNumber << endl; } cout << endl << "All contacts (ordered by phone number)" << endl; for(p = contacts.beginForPhoneNumber(); p != contacts.endForPhoneNumber(); ++p) { cout << p->first << ":\t\t" << p->second.phoneNumber << endl; } return 0; }
void exist(int sock, string msg){ string nickName (msg.begin() + 4, msg.end()); cout << nickName << endl; string response; if (conts.getSocketID(nickName) != -2){ response = "exs:true"; }else{ response = "exs:false"; } cout << response << endl; long sent = send(sock, &(response[0]), response.length(), 0); if (sent == -1) { perror("send"); } cout << "sent = " << sent << endl; }
void sendMessage(int sock, string msg){ char* pch = strtok(&(msg[0]), "\n"); string first (pch); pch = strtok(NULL, "\n"); if (pch == NULL) sendErrorMessage(sock,"snd has to have at least 3 lines"); string toWhom (pch); pch = strtok(NULL, ""); if (pch == NULL) sendErrorMessage(sock,"snd has to have at least 3 lines"); string message (pch); string fromWhom (first.begin()+4, first.end()); int socketToWhom = conts.getSocketID(toWhom); if (socketToWhom != -1) { cout << "sending message: " << toWhom << " " << fromWhom << " " << socketToWhom << " " << sock << endl; string parsedMessage = "snd:" + fromWhom + "\n" + message; if (send(socketToWhom, &(parsedMessage[0]), parsedMessage.length(), 0)) perror("send"); } }
void EPAHandle(const Collider &collider_a, const Collider &collider_b, const Simplex &simplex, Contacts &contacts) { std::vector<Simplex::Vert> epa_simplex = { simplex.vertices[0], simplex.vertices[1], simplex.vertices[2] }; // 100 is for security purposes, preventing an infinite loop for (int i = 0; i < 100; ++i) { // find the edge closest to the origin in the simplex SimplexEdge edge = EPAFindClosestEdge(epa_simplex); // find the furthest minkowski difference point in the direction of the normal Vector2 support, support_A, support_B; Support(collider_a, collider_b, edge.normal, support, support_A, support_B); // find the distance between the point and the edge float dist = Vector2::Dot(support, edge.normal); // if we've hit the border of the minkowski difference if (dist - edge.distance < 0.01f) { contacts.push_back(Contact()); auto &contact = contacts.back(); contact.normal = edge.normal; contact.pen_depth = dist; // For contact points // Find the repeating point, if there is no repeating point, // project onto the edge, and use the homogenous coords to find the contact point. Simplex::Vert &vert_0 = epa_simplex[edge.index_0], &vert_1 = epa_simplex[edge.index_1]; // if there are no repitions, we project the origin onto the edge // to find the contact point float t; // get the interval from the x coordinates if (vert_0.vert.x > 0 && vert_1.vert.x < 0 || vert_0.vert.x < 0 && vert_1.vert.x > 0) { t = (-vert_0.vert.x) / (vert_1.vert.x - vert_0.vert.x); } // get the interval from the y coordinates else { t = (-vert_0.vert.y) / (vert_1.vert.y - vert_0.vert.y); } contact.point = vert_0.parent_p0 + t * (vert_1.parent_p0 - vert_0.parent_p0); return; } else { // add the point inbetween the points where it was found epa_simplex.insert(epa_simplex.begin() + edge.index_1, { support_A, support_B, support }); } } }
bool IsColliding(const Collider &collider_a, const Collider &collider_b, Contacts &contacts) { // quick check with the individual collider AABBs for a quick out if (!collider_a.aabb.Overlap(collider_b.aabb)) return false; // our simplex for this collision test Simplex simplex; // Set initial search direction to the difference of centers Vector2 d = Vector2(1, -1);//Vector2(collider_b.root_trans.PositionWC() - collider_a.root_trans.PositionWC()); // get the first minkowski difference point simplex.Add(Support(collider_a, collider_b, d)); // negate the support point, giving us a vector in the direction of the origin d = -simplex.A().vert; int count = 0; // start looping while (count < 100) { // add a new point to the simplex because we haven't terminated yet simplex.Add(Support(collider_a, collider_b, d)); // see if the simplex is on the correct side of the origin if (Vector2::OppositeDirection(simplex.A().vert, d)) { // if the point added last was not past the origin in the direction of d // then the Minkowski Sum cannot possibly contain the origin since // the last point added is on the edge of the Minkowski Difference return false; } else { // oterwise we need to determine if the origin is in the current simplex // this function will set the next search direction for us if it fails. if (simplex.ContainsOrigin(d)) { // if it does then we know there is a collision // handle the collision with the EPA algorithm EPAHandle(collider_a, collider_b, simplex, contacts); // find the incident edge. if (contacts.size()) { auto &it = contacts.back(); it.info.e.edge_a = collider_a.FindIndex(it.normal); it.info.e.edge_b = collider_b.FindIndex(-it.normal); } return true; } } ++count; } return false; }
void registration1(int sock, string nickName, string pass){ string response = "reg:" + conts.pushContact(sock, nickName, pass); if (send(sock, &(response[0]), response.length(), 0)) perror("send"); cout << &(response[0]) << endl; }