Example #1
0
// Checks if type is valid. Does this by finding the hash value of the name
// and then checking if the names match if that hash number is already taken.
bool EventManager::validateType(EventType const & type)
{
	if (type.getName() == NULL)
		return false;

	if (type.getId() == 0)
		return false;

	EventTypeSet::iterator it = m_eventTypes.find(type);

	if (it != m_eventTypes.end())
	{
		EventType known = (*it);
		char * const oldName = known.getName();
		char * const newName = type.getName();

		int check = strcmp(oldName, newName);

		assert(check==0 && "Event types hashed wrong!");

		if (check!=0)
			return false;
	}

	return true;
}
int main(int argc, char* argv[]) {

    if (argc < 4) {
        std::cerr << "Usage: " << argv[0] << " <application-key> <username> <password>" << std::endl;
        return 1;
    }

    ExchangeApi exchangeApi(argv[1]);

    if (exchangeApi.login(argv[2], argv[3])) {

        MarketFilter filter;
        ListEventTypesRequest req(filter);

        if (req.isValid()) {
            ListEventTypesResponse resp = exchangeApi.listEventTypes(req);

            if (resp.isSuccess()) {

                std::vector<EventTypeResult> eventTypeResults = resp.getEventTypeResults();
                for (unsigned i = 0; i < eventTypeResults.size(); ++i) {
                    EventTypeResult etr = eventTypeResults[i];
                    EventType et = etr.getEventType();
                    std::cout << et.getId() << " " << et.getName() << std::endl;
                }

            } else {
                std::cout << "request failed: " << resp.getFaultCode() << " " << resp.getFaultString() << std::endl;
            }
        } else {
            std::cout << "invalid request: " << req.toString() << std::endl;
        }

    } else {
        std::cout << "failed to log in" << std::endl;
    }

}