aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYana Blashchishina <[email protected]>2024-03-10 14:49:57 -0700
committerYana Blashchishina <[email protected]>2024-03-10 14:49:57 -0700
commita6a5a946428e192a873bbc94fa1b3d5e8f7696ad (patch)
treec1ceb23d0309e855ebc7b5de5a4042b9de804a66
parenterrors :( (diff)
downloadhomework-8-yanablash-a6a5a946428e192a873bbc94fa1b3d5e8f7696ad.tar.xz
homework-8-yanablash-a6a5a946428e192a873bbc94fa1b3d5e8f7696ad.zip
defining functions
-rw-r--r--Homework 8/MyStructures/ContactList.hpp149
-rw-r--r--Homework 8/MyStructures/MyStructures.vcxproj1
-rw-r--r--Homework 8/MyStructures/MyStructures.vcxproj.filters1
3 files changed, 151 insertions, 0 deletions
diff --git a/Homework 8/MyStructures/ContactList.hpp b/Homework 8/MyStructures/ContactList.hpp
new file mode 100644
index 0000000..b8e981f
--- /dev/null
+++ b/Homework 8/MyStructures/ContactList.hpp
@@ -0,0 +1,149 @@
+#ifndef CONTACT_LIST
+#define CONTACT_LIST
+
+#include <algorithm>
+
+namespace MySStructures
+{
+ template<class C>
+ class ContactList
+ {
+ ContactList() = default;
+ ContactList(size_t length); //Creates contact list of this size
+ ContactList(const C* contacts, const size_t& length); //Makes a copy of another contact list
+ ~ContactList();
+
+ ContactList(const ContactList& copy); //deep copy constructor
+ ContactList& operator=(const ContactList& rhs); //deep copy assignment
+
+ ContactList(ContactList&& move); //reference(move) constructor
+ ContactList& operator=(ContactList&& rhs); //reference(move) assignment
+
+ void Print() const; //Print the Contact List, calling Print on each element.
+ size_t Size() const; //Return the size of the contact list
+
+ void Append(const C& data); //Add contact to back of list
+ void Prepend(const C& data); //add contact as first contact
+ void RemoveLast(); //removes last contact
+ void RemoveFirst(); //removes first contact
+ void Extract(const C& data); //delete this contact: data
+ void InsertAfter(const C& data, const C& after); //insert contact data after 'after' contact
+ void InsertBefore(const C& data, const C& before); //insert contact data before 'before' contact
+ void Clear(); //Deletes all contacts, empties the list, nothing left!
+
+ C& Last(); //returns last contact reference in list
+ C Last() const; //returns copy of last contact in list
+ C& First(); //returns first contact reference in lsit
+ C First() cosnt; //returns first contact copy
+
+ C& operator[](const int& index);
+ C operator[](const int& index) const;
+ explicit operator bool() const;
+
+ bool operator==(const ContactList<C>& rhs) const;
+ bool Empty() const;
+
+
+
+
+
+ private:
+ C* contacts_{ nullptr };
+ size_t length_{ 0 }; //entire length of array
+ size_t size_{ 0 }; //number of actual numbers
+
+ C* AllocateContactList(const size_t& length);
+ };
+
+ template <class C>
+ ContactList<C>::ContactList(size_t length)
+ {
+ contacts_ = AllocateContactList(length);
+ }
+
+ template <class C>
+ ContactList<C>::ContactList(const C* contacts, const size_t& length)
+ {
+ contacts_ = AllocateContactList(length);
+
+ for (auto i = 0u; i < length; ++i)
+ {
+ contacts_[i] = contacts[i];
+ }
+ }
+
+ template <class C>
+ ContactList<C>::~ContactList()
+ {
+ delete[] contacts_;
+ contacts_ = nullptr;
+ }
+
+ template <class C>
+ ContactList<C>::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 <class C>
+ ContactList<C>& ContactList<C>::operator=(const ContactList& rhs)
+ {
+ if (this != &rhs)
+ {
+ delete[] contacts_;
+ contacts_ = nullptr;
+
+ contacts_ = AllocateContactsList(rhs.length_);
+ size_ = rhs.size_;
+
+ for (auto i = 0u; i < length_; ++i)
+ {
+ contacts_[i] = copy[i];
+ }
+ }
+ return *this;
+ }
+
+ template <class C>
+ ContactList<C>::ContactList(ContactList&& move)
+ {
+ *this = std::move(move);
+ }
+
+ template <class C>
+ ContactList<C>& ContactList<C>::operator=(ContactList&& rhs)
+ {
+ if (this != &rhs)
+ {
+ delete[] contacts_;
+ contacts_ = nullptr;
+
+ contacts_ = rhs.contacts_;
+ length_ = rhs.length_;
+ size_ = rhs.size_;
+
+ rhs.contacts_ = nullptr;
+
+ }
+ }
+ template <class C>
+ C* ContactList<C>::AllocateContactList(const size_t& length)
+ {
+ C* storage = nullptr;
+
+ length_ = length;
+
+ storage = new C[length]{};
+
+ return storage;
+ }
+}
+
+
+#endif \ No newline at end of file
diff --git a/Homework 8/MyStructures/MyStructures.vcxproj b/Homework 8/MyStructures/MyStructures.vcxproj
index 4cfc769..ee62017 100644
--- a/Homework 8/MyStructures/MyStructures.vcxproj
+++ b/Homework 8/MyStructures/MyStructures.vcxproj
@@ -128,6 +128,7 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="Contact.hpp" />
+ <ClInclude Include="ContactList.hpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
diff --git a/Homework 8/MyStructures/MyStructures.vcxproj.filters b/Homework 8/MyStructures/MyStructures.vcxproj.filters
index 0ee3180..deeda6d 100644
--- a/Homework 8/MyStructures/MyStructures.vcxproj.filters
+++ b/Homework 8/MyStructures/MyStructures.vcxproj.filters
@@ -2,5 +2,6 @@
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClInclude Include="Contact.hpp" />
+ <ClInclude Include="ContactList.hpp" />
</ItemGroup>
</Project> \ No newline at end of file