assignment

profilelio
Status.cpp

#include "Status.h" namespace sdds { Status::Status(char* str, int code) { if (str != NULL) { description = new char[strlen(str) + 1]; strcpy(description, str); } else description = NULL; status_code = code; } Status::Status(const Status& s) { if (!s) { description = new char[strlen(s.description) + 1]; strcpy(description, s.description); } else description = NULL; status_code = s.status_code; } Status& Status::operator=(const Status& s) { if (!s) { description = new char[strlen(s.description) + 1]; strcpy(description, s.description); } else description = NULL; status_code = s.status_code; return *this; } Status::~Status() { delete(description); } Status& Status::operator=(const char* str) { description = new char[strlen(str) + 1]; strcpy(description, str); return *this; } Status& Status::operator=(const int code) { status_code = code; return *this; } Status::operator bool() const { if (description == NULL) return true; else return false; } Status::operator int() const { return status_code; } Status::operator char* () const { return (char*)description; } ostream& operator<<(ostream& out, const Status& s) { if (!s) { if (s.status_code != 0) out << "ERR#" << s.status_code << ": "; out << s.description; } return out; } Status& Status::clear() { description = NULL; status_code = 0; return *this; } }