#ifndef CONTACT_LIST_HPP #define CONTACT_LIST_HPP #include #include "Contact.hpp" #include using std::cin; using std::cout; using std::endl; // NOTE: ALL USES OF TERM LIST REFER TO A SHORTHAND FORM OF ContactList, NOT AN ACTUAL LIST. // ContactList's DATA SAVING IS IN AN ARRAY FORMAT namespace myStructures { template class ContactList { public: ContactList(size_t length); //Creates contact list of this size ContactList() = default; ContactList(const CList* contacts, const size_t& length); //Makes a copy of another contact list ~ContactList(); ContactList(const ContactList& copy); //deep copy constructor ContactList& operator=(ContactList& rhs); //deep copy assignment ContactList(ContactList&& move) noexcept; //reference(move) constructor ContactList& operator=(ContactList&& rhs) noexcept; //reference(move) assignment void Print() const; // print contact list calling print on each element size_t Size() const; // return the size of the contact list void Append(const CList& data); // add contact to back of list void Prepend(const CList& data); // add contact to the front of the list (add as first) void RemoveLast(); // delete last contact in the list void RemoveFirst(); // delete first contact in the list void Extract(const CList& data); // delete this contact (and return it) void InsertAfter(const CList& data, const CList& after); // insert contact data after 'after' contact. search for specific contact and insert contact after it. void InsertBefore(const CList& data, const CList& before); // same as after, but inserts contact in front of searched contact void Clear(); // deletes all contacts, empties the list, and clears it all. CList& Last(); // returning last contact reference in list CList Last() const; // returns copy of the last contact in list CList& First(); // returns first contact reference CList First() const; // returns first contact copy CList& operator[](const int& index); // returns contact reference via [] overload CList operator[](int& index); // returns contact copy via [] overload explicit operator bool() const; // overloads ContactList to return true/false as boolean // operator bool operator==(const ContactList& rhs) const; //if(newContactList == oldContactList) bool Empty() const; // is the list empty? CList* AllocateContactList(const size_t& length); private: CList* contacts_{ nullptr }; size_t length_{ 10 }; // entire length of array size_t size_{ 1 }; // number of actual elements }; template ContactList::ContactList(size_t length) { contacts_ = AllocateContactList(length); } template ContactList::ContactList(const CList* contacts, const size_t& length) { contacts_ = AllocateContactList(length); for(auto i = 0u; i < length; i++) { contacts_[i] = contacts[i]; } } template ContactList::~ContactList() { delete[] contacts_; contacts_ = nullptr; } template ContactList::ContactList(const ContactList& copy) { length_ = copy.length_; size_ = copy.size_; contacts_ = AllocateContactList(copy.length_); for (auto i = 0u; i < length_; i++) { contacts_[i] = copy[i]; } } template ContactList& ContactList::operator=( ContactList& rhs) { if (this != &rhs) { delete[] contacts_; contacts_ = nullptr; contacts_ = AllocateContactList(rhs.length_); size_ = rhs.size_; for (auto i = 0u; i < length_; i++) { contacts_[i] = rhs[i]; } } return *this; } template ContactList::ContactList(ContactList&& move) noexcept { *this = std::move(move); } template ContactList& ContactList::operator=(ContactList&& rhs) noexcept { if(this!= &rhs) { delete[] contacts_; contacts_ = nullptr; contacts_ = rhs.contacts_; length_ = rhs.length_; size_ = rhs.size_; rhs.contacts_ = nullptr; } } template void ContactList::Print() const { for(auto i = 0u; i < length_; i++) { contacts_[i].print(); } } template size_t ContactList::Size() const { } template void ContactList::Append(const CList& data) { size_t index = 0; // what ifs // what if: end of the array is the beginning (empty) if (size_ == 0) { index = 0; } // what if: in the body of the array if(size_ > 0 && size_ < length_) { index = size_; } // what if: end of the array //length_ == 10; //size_ == 10; // contacts_[10] is out of bounds if(size_ >= length_) { //increase size of array //*this = ContactList(contacts_, length_ * 2); ContactList newContacts(contacts_, length_ * 2); *this = newContacts; } // what if: the array is full // Add to the end of the array contacts_[index] = data; size_++; } template void ContactList::Prepend(const CList& data) { } template void ContactList::RemoveLast() { } template void ContactList::RemoveFirst() { } template void ContactList::Extract(const CList& data) { } template void ContactList::InsertAfter(const CList& data, const CList& after) { } template void ContactList::InsertBefore(const CList& data, const CList& before) { } template void ContactList::Clear() { } template CList& ContactList::Last() { } template CList ContactList::Last() const { } template CList& ContactList::First() { } template CList ContactList::First() const { } template CList& ContactList::operator[](const int& index) { return contacts_[index]; } template CList ContactList::operator[](int& index) { return *this; } template ContactList::operator bool() const { } template bool ContactList::operator==(const ContactList& rhs) const { } template bool ContactList::Empty() const { } template CList* ContactList::AllocateContactList(const size_t& length) { CList* storage = nullptr; length_ = length; storage = new CList[length]{}; return storage; } } #endif CONTACT_LIST_HPP