42_CPP00/ex01/Contact.cpp
Camille Chauvet 67fbbf113b init
2023-05-17 16:41:46 +00:00

61 lines
1.3 KiB
C++

#include <ios>
#include <ostream>
#include <sstream>
#include <string>
#include <iostream>
#include <iomanip>
#include "Contact.hpp"
#include "utils.hpp"
Contact::Contact(std::string first_name, std::string last_name, std::string nickname, std::string phone_number)
{
this->nickname = nickname;
this->last_name = last_name;
this->first_name = first_name;
this->phone_number = phone_number;
}
Contact::Contact()
{
this->first_name = "";
this->last_name = "";
this->phone_number = "";
this->phone_number = "";
}
Contact::~Contact()
{
}
Contact &Contact::operator=(const Contact &contact)
{
this->first_name = contact.first_name;
this->last_name = contact.last_name;
this->nickname = contact.nickname;
this->phone_number = contact.phone_number;
return (*this);
}
bool Contact::isValid() const
{
return (!(this->first_name == "" || this->last_name == "" || this->nickname == "" || this->phone_number == ""));
}
std::string Contact::to_string() const
{
std::stringstream ss;
ss << std::setw(10) << truncated(this->first_name) << "|"
<< std::setw(10) << truncated(this->last_name) << "|"
<< std::setw(10) << truncated(this->nickname) << "|"
<< std::setw(10) << truncated(this->phone_number);
return(ss.str());
}
std::ostream& operator<<(std::ostream& os, const Contact& contact)
{
os << contact.to_string() << std::endl;
return (os);
}