예제 #1
0
void searchByCategory(Data* data){
	clearScreen();
	string answer;
	cout << "\nInsert what category you would like to search for\n"
			"( Agriculture, Animals, BabyAndChildren, Fashion, Home, Job, Leisure,\n"
			"PhonesAndTablets, RealEstate, Services, Sports, Technology, Vehicles,\n"
			"Others ) : ";
	getline(cin, answer);
	vector<Advertisement* > results;
	if (validCategory(answer)){
		Category searchCategory=stringToCategory(answer);
		results=data->searchForAdsCategory(searchCategory);
		saleOrPurchase(results,data);
		SearchMenu menu(data, results);
		menu.createMenu();
	}
	else {
		cout<<"Invalid Category\n"
				"Do you want to search again?(Y/N)?\n";
		getline(cin, answer);
		if (answer=="y"||answer=="Y")
			searchByCategory(data);
		else if(data->getSignedInUser() != NULL)
			signedInMenu(data);
		else
			mainMenu(data);
	}

	if(data->getSignedInUser() != NULL)
		signedInMenu(data);
	else
		mainMenu(data);
}
예제 #2
0
void createBuyingAd(Data* data){
	clearScreen();
	string title, description = "", tmp = "", category, condition;
	float price;

	time_t t = time(0);   // get time now
	struct tm * now = localtime( & t );
	int year=now->tm_year + 1900;
	int month=now->tm_mon + 1 ;
	int day= now->tm_mday;

	Date creationDate(day,month,year);

	cout << "\nTitle: ";
	getline(cin, title);

	cout << "\nCategory: \n ( Agriculture, Animals, BabyAndChildren, Fashion, Home, Job, Leisure,\n"
			"PhonesAndTablets, RealEstate, Services, Sports, Technology, Vehicles,\n"
			"Others ) : ";
	getline(cin,category);
	while (!validCategory(category))
	{
		cout<<"\nWrite a valid Category: ";
		getline(cin,category);
	}
	Category cat = stringToCategory(category);

	cout << "\nDescription: ";
	getline(cin, description);

	cout << "\nPrice: ";
	cin >> price;
	cin.ignore();
	cin.clear();

	Advertisement* ad = new Purchase(data->getSignedInUser(), title, cat, description, price);
	ad->setCreationDate(creationDate);

	cout << "\nIs the price negotiable? (Y/N)\n";
	string answer;
	unsigned int i = 0;
	do{
		if(i > 0)
			cout << "Please introduce a valid option. (Y/N)\n";
		getline(cin,answer);
		if(answer == "N" || answer == "n")
			ad->setNegotiable(false);
		i++;
	}while(answer != "Y" && answer != "y" && answer != "N" && answer != "n");


	data->addAdvertisement(ad);
	cout << "Ad has been successfully created\n";
	signedInMenu(data);
}
예제 #3
0
파일: Logger.cpp 프로젝트: cnxsoft/xibo4arm
Logger::Logger()
{
    m_Flags = ERROR | WARNING | APP;
    string sEnvCategories;
    bool bEnvSet = getEnv("AVG_LOG_CATEGORIES", sEnvCategories);
    if (bEnvSet) {
        m_Flags = ERROR | APP;
        bool bDone = false;
        string sCategory;
        do {
            string::size_type pos = sEnvCategories.find(":");
            if (pos == string::npos) {
                sCategory = sEnvCategories;
                bDone = true;
            } else {
                sCategory = sEnvCategories.substr(0, pos);
                sEnvCategories = sEnvCategories.substr(pos+1);
            }
            long category = stringToCategory(sCategory);
            m_Flags |= category;
        } while (!bDone);
    }
}
void AdDisplayMenu::createMenu() {
	clearScreen();
	AdDisplayMenu::print();
	int input;
	string title, description, category, answer;
	unsigned int i = 0;
	cout << "What option would you like to choose?" << endl;
	if (data->getSignedInUser() == ad->getOwner()) {
		do {
			if (i > 0) {
				cout << "Please introduce a valid option." << endl;
			}
			cin >> input;
			cin.ignore();
			cin.clear();
			i++;

		} while (input < 1 || input > 6);
		switch (input) {
		case 1:
			cout << "Please introduce the new title." << endl;
			getline(cin, title);
			ad->setTitle(title);
			break;
		case 2:
			cout << "Please introduce the new description." << endl;
			getline(cin, description);
			ad->setDescription(description);
			break;
		case 3:
			cout << "Please introduce the new category." << endl;
			getline(cin, category);
			do {
				if (validCategory(category)) {
					ad->setCategory(stringToCategory(category));
					break;
				} else {
					cout << "Invalid category, try again. Press 1 to exit."
							<< endl;
					getline(cin, category);
					if (category == "1")
						break;
				}
			} while (true);
			break;
		case 4:
			cout << "Please introduce the new price." << endl;
			float newPrice;
			cin >> newPrice;
			cin.ignore();
			cin.clear();
			ad->setPrice(newPrice);
			cout << "Please introduce if it is negotiable or not(Y/N)." << endl;
			getline(cin, answer);
			if (answer == "Y" || answer == "y")
				ad->setNegotiable(true);
			else
				ad->setNegotiable(false);
			break;
		case 5:
			ad->getOwner()->removeAdvertisement(ad);
			data->removeAdvertisement(ad);
			signedInMenu(data);
			break;
		case 6:
			signedInMenu(data);
			break;
		default:
			AdDisplayMenu::createMenu();
			break;
		}
	} else {
		do {
			if (i > 0)
void SimpleLoggerRoutingInfo::readInternals(QXmlStreamReader& reader, const QString&)
{
  // Some elements store a map with the key as an attribute such as: "<Level MessageCategory="UserMessage">3</Level>"
  // The nameAttrMapprovides the mapping between the element name and the single attribute used to contain the key.
  QMap<QString, QString> nameAttrMap;
  nameAttrMap["level"] = "MessageCategory";
  nameAttrMap["routing"] = "MessageRouting";
  nameAttrMap["format"] = "MessageComponent";

  QString name;
  QString attributeValue;
  bool foundCharacters = false;
  while (!reader.atEnd())
  {
    if (reader.isStartElement())
    {
      attributeValue = "";
      name = reader.name().toString();
      foundCharacters = false;
      //qDebug(qPrintable(QString("Found start element %1").arg(name)));

      if (QString::compare(name, "LocationRegEx", Qt::CaseInsensitive) == 0)
      {
        if (m_locationRegExp != nullptr)
        {
          delete m_locationRegExp;
          m_locationRegExp = nullptr;
        }
        m_locationRegExp = XMLUtility::readRegExp(reader);
      }
      else if (QString::compare(name, "MessageRegEx", Qt::CaseInsensitive) == 0)
      {
        if (m_messageRegExp != nullptr)
        {
          delete m_messageRegExp;
          m_messageRegExp = nullptr;
        }
        m_messageRegExp = XMLUtility::readRegExp(reader);
      }
      else
      {
        // At a start element that is not a regular expression, so check for the value in the attribute.
        if (nameAttrMap.contains(name.toLower()) && reader.attributes().hasAttribute(nameAttrMap[name.toLower()]))
        {
          attributeValue = reader.attributes().value(nameAttrMap[name.toLower()]).toString();
        }
      }
    }
    else if (reader.isCharacters() && !name.isEmpty())
    {
      QString value = reader.text().toString();
      //qDebug(qPrintable(QString("Found characters for name %1 and value (%2)").arg(name, value)));
      if (name.compare("Enabled", Qt::CaseInsensitive) == 0)
      {
        m_enabled = XMLUtility::stringToBoolean(value);
      }
      else if (name.compare("Name", Qt::CaseInsensitive) == 0)
      {
        setName(value.trimmed());
      }
      else if (attributeValue.length() > 0)
      {
        // These next guys store their value in the attribute as specified in the nameAttrMap.
        if (name.compare("Level", Qt::CaseInsensitive) == 0)
        {
          m_levels->insert(stringToCategory(attributeValue), value.toInt());
        }
        else if (name.compare("Routing", Qt::CaseInsensitive) == 0)
        {
          m_routing->insert(stringToRouting(attributeValue), XMLUtility::stringToBoolean(value));
        }
        else if (name.compare("Format", Qt::CaseInsensitive) == 0)
        {
          m_format.append(QPair<MessageComponent, QString>(stringToComponent(attributeValue), value));
          foundCharacters = true;
        }
      }
      attributeValue = "";
    } else if (reader.isEndElement()) {
      if (QString::compare(reader.name().toString(), "SimpleLoggerRoutingInfo", Qt::CaseInsensitive) == 0)
      {
        return;
      }
      if (name.compare("Format", Qt::CaseInsensitive) == 0 && !foundCharacters)
      {
        m_format.append(QPair<MessageComponent, QString>(stringToComponent(attributeValue), ""));
      }
      name = "";
    }
    reader.readNext();
  }
}