Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.9 kB
2
Indexable
Never
#include "airline_ticket.h"
#include "test_runner.h"

#include <map>
#include <sstream>
#include <iostream>

bool operator<(const Date& lhs, const Date& rhs) {
    return std::tie(lhs.year, lhs.month, lhs.day)
        < std::tie(rhs.year, rhs.month, rhs.day);
}

bool operator<(const Time& lhs, const Time& rhs) {
    return std::tie(lhs.hours, lhs.minutes)
        < std::tie(rhs.hours, rhs.minutes);
}

bool operator==(const Date& lhs, const Date& rhs) {
    return std::tie(lhs.year, lhs.month, lhs.day)
        == std::tie(rhs.year, rhs.month, rhs.day);
}

bool operator==(const Time& lhs, const Time& rhs) {
    return std::tie(lhs.hours, lhs.minutes)
        == std::tie(rhs.hours, rhs.minutes);
}

std::ostream& operator<<(std::ostream& out, const Date& rhs) {
    out << rhs.year << "-" << rhs.month << "-" << rhs.day;
    return out;
}

std::ostream& operator<<(std::ostream& out, const Time& rhs) {
    out << rhs.hours << ":" << rhs.minutes;
    return out;
}

std::istream& operator>>(std::istream& is, Date& d) {
    is >> d.year;
    is.ignore(1);
    is >> d.month;
    is.ignore(1);
    is >> d.day;
    return is;
}

std::istream& operator>>(std::istream& is, Time& t) {
    is >> t.hours;
    is.ignore(1);
    is >> t.minutes;
    return is;
}

#define UPDATE_FIELD(ticket, field, values) \
  {                                         \
    auto it = values.find(#field);          \
    if (it != values.end()) {               \
      istringstream is(it->second);         \
      is >> ticket.field;                   \
    }                                       \
  }


#define UPDATE_FIELD(ticket, field, values)     \
{                                               \
  auto it = values.find(#field);                \
  if (it != values.end())                       \
    Assign(ticket.field, it->second);           \
}