bool Snapshot::load(string path) { mGalaxies.reserve(MAX_RESERVE); // Reserve memory bool success = true; // Open Snapshot file ifstream catalogue(path.c_str()); // Read file if (catalogue.is_open()) { printf("Loading Snapshot %s.\n", path.c_str()); // Success on opening files string element; getline(catalogue, element); //Skips first line with parameter names while (!catalogue.eof()) { // Stop at the end of the file // Array of parameters double values[PARAMETERS_TOTAL]; getline(catalogue, element, ','); // First Element is mass values[0] = atof(element.c_str()); // Skip the next element getline(catalogue, element, ','); // Three Position data for (int i = 1; i <= 3; i++) { getline(catalogue, element, ','); values[i] = atof(element.c_str()); } // Skip the next 4 (velocity and uband) getline(catalogue, element, ','); getline(catalogue, element, ','); getline(catalogue, element, ','); getline(catalogue, element, ','); // Load bBand getline(catalogue, element, ','); values[4] = atof(element.c_str()); // Skip to the end of the line getline(catalogue, element, '\n'); // Adding Galaxies mGalaxies.push_back( Galaxy(values[0], values[1], values[2], values[3], values[4])); } // close the catalogue catalogue.close(); printf("Note: Snapshot: Catalogues Reading Successful, %i galaxies.\n", (int) mGalaxies.size()); } else { printf("Warning: Snapshot failed to open file %s! \n", path.c_str()); } return success; }
void Ut_WidgetNotificationSink::testInfoBannerCreationWhenPrivacyIsHonoredAndEnabledAndCatalogPresentPlural() { QString catalogue("translationcatalogue"); m_subject->setHonorPrivacySetting(true); gMGConfPrivateNotificationValue = true; TestNotificationParameters parameters("title1", "subtitle1", "buttonicon1"); parameters.add(NotificationWidgetParameterFactory::genericTextIdKey(), "translationid"); parameters.add(NotificationWidgetParameterFactory::genericTextCatalogueKey(), catalogue); parameters.add(GenericNotificationParameterFactory::countKey(), "2"); QScopedPointer<MBanner> infoBanner(m_subject->createInfoBanner(Notification(3, 1, 2, parameters, Notification::ApplicationEvent, 1020))); QCOMPARE(infoBanner->objectName(), QString("EventBanner")); QCOMPARE(infoBanner->title(), QString("translatedpluralstring 2")); QCOMPARE(infoBanner->subtitle(), QString()); QCOMPARE(infoBanner->iconID(), QString("buttonicon1")); QCOMPARE(gInstalledTrCatalog, catalogue); QCOMPARE(gSetDefaultLocale, gInstalledCatalogLocale); }
void Ut_UnlockNotificationSink::testWhenPrivacyModeOnAndGenericTextIdPresentAndCataloguePresentThenSummaryIsSet() { sink->setLockedState(true); gMGConfPrivateNotificationValue = true; QString catalogue("translationcatalogue"); NotificationParameters params; params.add(NotificationWidgetParameterFactory::genericTextIdKey(), "translationid"); params.add(NotificationWidgetParameterFactory::genericTextCatalogueKey(), catalogue); Notification notification(100, GID, UID, params, Notification::ApplicationEvent, -1); sink->addNotification(notification); QCOMPARE(gInstalledTrCatalog, catalogue); QCOMPARE(gSetDefaultLocale, gInstalledCatalogLocale); QCOMPARE(gUnlockMissedEventsStub->stubCallCount ("addNotification"), 1); QCOMPARE(gUnlockMissedEventsStub->stubLastCallTo("addNotification").parameter<QString>(1), QString("translatedstring")); }
void httpServer::getClientRequest() { QTcpSocket *client = qobject_cast<QTcpSocket *>(sender()); if(client->canReadLine()) { QStringList lines = QString(client->readLine()).split(QRegExp("[ \r\n][ \r\n]*")); if(lines[0] == "GET") { viewMessage(QString::fromUtf8("Envoi du catalogue à ")+client->peerAddress().toString()+":"+QString::number(client->peerPort())); QFile catalogue(QCoreApplication::applicationDirPath()+"/catalog.tmp"); catalogue.open(QIODevice::ReadOnly | QIODevice::Text); QTextStream os(client); QTextStream is(&catalogue); os << "HTTP/1.1 200 OK\r\nServer: TP_Serveur_3208\r\nConnection: Keep-Alive\r\nContent-Type: text/txt\r\nContent-Length: " << catalogue.size() << "\r\n\r\n"; QString line = is.readLine(); while(!line.isNull()) { os << line.toLocal8Bit().constData() << "\r\n"; line = is.readLine(); } catalogue.close(); } } }
void menuUtilisateur(char * idUser) { size_t fin=0; char choix[2]; int retour=0;//retour fonction while(!fin) { printf("-------Menu Utilisateur-------\n"); printf("1)Rechercher produits\n2)Vendre un produit\n3)Compte\n4)Vos Ventes terminée\n0)Quitter\n"); printf("choix: "); if(fgets(choix,2,stdin)==NULL) { perror("probleme dans l'entrée choix\n"); exit(1); // on quitte le programme } supprCara(choix); switch(choix[0]) { case '1': retour=menuRechercherObjet(idUser); if(retour==1) { printf("Chargement catalogue...\n"); if(catalogue(idUser,0)==-1) { printf("le catalogue n'a pu etre ouvert.\n"); } } else if(retour==0) { printf("Le catalogue n'a pu être envoyé, les données envoyées ne sont pas correctes.\n"); } else if(retour==2) { printf("Retour menu.......\n"); } else { printf("Le catalogue n'a pu être envoyé, problème serveur.\n"); } break; case '2': retour=vendre(idUser); if(retour==1) { printf("Votre objet est maintenant disponible sur le catalogue du site.\n"); } else if(retour==0) { printf("L'enregistrement n'a pu se faire, les données envoyées ne sont pas correctes.\n"); } else { printf("L'enregistrement n'a pu se faire, problème serveur.\n"); } break; case '3': retour=informationCompte(idUser); if(retour==1) { printf(".......\n\n"); } else if(retour==0) { printf("Les informations du compte ne sont pas disponibles.\n"); } else { printf("Suite à un problème serveur, nous ne pouvons transmettre les données du compte.\n"); } break; case '4': retour=voirVenteFinie(idUser); if(retour==1) { printf("Chargement catalogue...\n"); if(catalogue(idUser,1)==-1) { printf("le catalogue n'a pu etre ouvert.\n"); } } else if(retour==0) { printf("Le catalogue n'a pu être envoyé, les données envoyées ne sont pas correctes.\n"); } else if(retour==2) { printf("Retour menu.......\n"); } else { printf("Le catalogue n'a pu être envoyé, problème serveur.\n"); } break; case '0': printf("Retour Menu Connexion...\n"); fin=1; break; default: printf("Erreur dans le choix, recommencez.\n"); break; } } return; }