Skip to content

Commit

Permalink
fixed #305
Browse files Browse the repository at this point in the history
  • Loading branch information
Mooophy committed Jul 22, 2015
1 parent 1e96061 commit 2cd0733
Showing 1 changed file with 96 additions and 67 deletions.
163 changes: 96 additions & 67 deletions ch13/ex13_34_36_37.cpp
Original file line number Diff line number Diff line change
@@ -1,106 +1,135 @@
#include "ex13_34_36_37.h"
#include <iostream>

void swap(Message &lhs, Message &rhs) {
using std::swap;
for (auto f : lhs.folders)
f->remMsg(&lhs);
for (auto f : rhs.folders)
f->remMsg(&rhs);

swap(lhs.folders, rhs.folders);
swap(lhs.contents, rhs.contents);

for (auto f : lhs.folders)
f->addMsg(&lhs);
for (auto f : rhs.folders)
f->addMsg(&rhs);
void swap(Message &lhs, Message &rhs)
{
using std::swap;
for (auto f : lhs.folders)
f->remMsg(&lhs);
for (auto f : rhs.folders)
f->remMsg(&rhs);

swap(lhs.folders, rhs.folders);
swap(lhs.contents, rhs.contents);

for (auto f : lhs.folders)
f->addMsg(&lhs);
for (auto f : rhs.folders)
f->addMsg(&rhs);
}

// Message Implementation

void Message::save(Folder &f) {
folders.insert(&f);
f.addMsg(this);
void Message::save(Folder &f)
{
folders.insert(&f);
f.addMsg(this);
}

void Message::remove(Folder &f) {
folders.erase(&f);
f.remMsg(this);
void Message::remove(Folder &f)
{
folders.erase(&f);
f.remMsg(this);
}

void Message::add_to_Folders(const Message &m) {
for (auto f : m.folders)
f->addMsg(this);
void Message::add_to_Folders(const Message &m)
{
for (auto f : m.folders)
f->addMsg(this);
}

Message::Message(const Message &m) : contents(m.contents), folders(m.folders) {
add_to_Folders(m);
Message::Message(const Message &m)
: contents(m.contents), folders(m.folders)
{
add_to_Folders(m);
}

void Message::remove_from_Folders() {
for (auto f : folders)
f->remMsg(this);
folders.clear();
void Message::remove_from_Folders()
{
for (auto f : folders)
f->remMsg(this);
folders.clear();
}

Message::~Message() { remove_from_Folders(); }
Message::~Message()
{
remove_from_Folders();
}

Message &Message::operator=(const Message &rhs) {
remove_from_Folders();
contents = rhs.contents;
folders = rhs.folders;
add_to_Folders(rhs);
return *this;
Message &Message::operator=(const Message &rhs)
{
remove_from_Folders();
contents = rhs.contents;
folders = rhs.folders;
add_to_Folders(rhs);
return *this;
}

void Message::print_debug() { std::cout << contents << std::endl; }
void Message::print_debug()
{
std::cout << contents << std::endl;
}

// Folder Implementation

void swap(Folder &lhs, Folder &rhs) {
using std::swap;
for (auto m : lhs.msgs)
m->remFldr(&lhs);
void swap(Folder &lhs, Folder &rhs)
{
using std::swap;
for (auto m : lhs.msgs)
m->remFldr(&lhs);

for (auto m : rhs.msgs)
m->remFldr(&rhs);
for (auto m : rhs.msgs)
m->remFldr(&rhs);

swap(lhs.msgs, rhs.msgs);
swap(lhs.msgs, rhs.msgs);

for (auto m : lhs.msgs)
m->addFldr(&lhs);
for (auto m : lhs.msgs)
m->addFldr(&lhs);

for (auto m : rhs.msgs)
m->addFldr(&rhs);
for (auto m : rhs.msgs)
m->addFldr(&rhs);
}

void Folder::add_to_Message(const Folder &f) {
for (auto m : f.msgs)
m->addFldr(this);
void Folder::add_to_Message(const Folder &f)
{
for (auto m : f.msgs)
m->addFldr(this);
}

Folder::Folder(const Folder &f) : msgs(f.msgs) { add_to_Message(f); }
Folder::Folder(const Folder &f)
: msgs(f.msgs)
{
add_to_Message(f);
}

void Folder::remove_to_Message() {
for (auto m : msgs)
m->remFldr(this);
msgs->clear();
void Folder::remove_to_Message()
{
for (auto m : msgs)
m->remFldr(this);
msgs.clear();
}

Folder::~Folder() { remove_to_Message(); }
Folder::~Folder()
{
remove_to_Message();
}

Folder &Folder::operator=(const Folder &rhs) {
remove_to_Message();
msgs = rhs.msgs;
add_to_Message(rhs);
return *this;
Folder &Folder::operator=(const Folder &rhs)
{
remove_to_Message();
msgs = rhs.msgs;
add_to_Message(rhs);
return *this;
}

void Folder::print_debug() {
for (auto m : msgs)
std::cout << m->contents << " ";
std::cout << std::endl;
void Folder::print_debug()
{
for (auto m : msgs)
std::cout << m->contents << " ";
std::cout << std::endl;
}

int main() { return 0; }
int main()
{
return 0;
}

0 comments on commit 2cd0733

Please sign in to comment.