-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomedy.cpp
More file actions
80 lines (64 loc) · 1.51 KB
/
Copy pathcomedy.cpp
File metadata and controls
80 lines (64 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm> // std::swap
#include <istream>
#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
#include "comedy.h"
Comedy::Comedy(
const std::string& title,
const std::string& director,
const std::string& data)
{
Movie::Init(title, director, data);
}
Comedy::Comedy(std::istream& input)
{
Movie::Init(input);
}
std::ostream& operator<<(std::ostream& out, const Comedy& movie)
{
out << std::left
<< std::setw(Comedy::kTitleDisplayWidth) << movie.title_
<< std::setw(Comedy::kDirectorDisplayWidth) << movie.director_
<< std::setw(Comedy::kYearDisplayWidth) << movie.year_;
return out;
}
Comedy::Comedy(const Comedy& other)
{
director_ = other.director_;
title_ = other.title_;
year_ = other.year_;
}
Comedy::~Comedy()
{
}
Comedy& Comedy::operator=(Comedy other)
{
std::swap(director_, other.director_);
std::swap(title_, other.title_);
std::swap(year_, other.year_);
return *this;
}
void Comedy::Populate(std::istream& input)
{
std::string title, year;
std::getline(input, title, ',');
input >> year;
boost::algorithm::trim(title);
boost::algorithm::trim(year);
if(!input.fail()) {
title_ = title;
year_ = boost::lexical_cast<int>(year.c_str());
}
validate_input();
}
int Comedy::compare(const Movie& other) const
{
const Comedy& o = static_cast<const Comedy&>(other);
int compare = title_.compare(o.title_);
if(compare != 0)
return compare;
return year_ - o.year_;
}