aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConnor McDowell <[email protected]>2024-03-09 13:15:04 -0800
committerConnor McDowell <[email protected]>2024-03-09 13:15:04 -0800
commitb3081ea8c62621818ecc8826f836922f7a29738d (patch)
tree12c7cb5cf999c907037bf91984b4b445e64e680f
parentcopy and move constructs and operators filled (diff)
downloadhomework-8-connormcdowell275-b3081ea8c62621818ecc8826f836922f7a29738d.tar.xz
homework-8-connormcdowell275-b3081ea8c62621818ecc8826f836922f7a29738d.zip
continuing work
-rw-r--r--My structures/Contact.hpp4
-rw-r--r--My structures/ContactList.hpp117
-rw-r--r--My structures/My structures.vcxproj1
-rw-r--r--My structures/My structures.vcxproj.filters1
4 files changed, 121 insertions, 2 deletions
diff --git a/My structures/Contact.hpp b/My structures/Contact.hpp
index 17f20c1..15c8317 100644
--- a/My structures/Contact.hpp
+++ b/My structures/Contact.hpp
@@ -94,13 +94,13 @@ namespace myStructures
}
template <class C>
- contact<C>::contact(contact&& move)
+ contact<C>::contact(contact&& move) noexcept
{
*this = move;
}
template <class C>
- contact<C>& contact<C>::operator=(contact&& rhs)
+ contact<C>& contact<C>::operator=(contact&& rhs) noexcept
{
if (this != &rhs)
{
diff --git a/My structures/ContactList.hpp b/My structures/ContactList.hpp
new file mode 100644
index 0000000..61e5e7c
--- /dev/null
+++ b/My structures/ContactList.hpp
@@ -0,0 +1,117 @@
+#ifndef CONTACT_LIST_HPP
+#define CONTACT_LIST_HPP
+
+#include <algorithm>
+
+namespace myStructures
+{
+ template<class CList>
+ class ContactList
+ {
+ public:
+ ContactList() = default;
+ ContactList(size_t length); //Creates contact list of this size
+ 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=(const ContactList& rhs); //deep copy assignment
+
+ ContactList(ContactList&& move) noexcept; //reference(move) constructor
+ ContactList& operator=(ContactList&& rhs) noexcept; //reference(move) assignment
+
+ private:
+ CList* contacts_{ nullptr };
+ size_t length_{ 0 }; // entire length of array
+ size_t size_{ 0 }; // number of actual elements
+
+ CList* AllocateContactList(const size_t& length);
+ };
+
+
+ template <class CList>
+ ContactList<CList>::ContactList(size_t length)
+ {
+ contacts_ = AllocateContactList(length);
+ }
+
+ template <class CList>
+ ContactList<CList>::ContactList(const CList* contacts, const size_t& length)
+ {
+ contacts_ = AllocateContactList(length);
+
+ for(auto i = 0u; i < length; i++)
+ {
+ contacts_[i] = contacts[i];
+ }
+ }
+
+ template <class CList>
+ ContactList<CList>::~ContactList()
+ {
+ delete[] contacts_;
+ contacts_ = nullptr;
+ }
+
+ template <class CList>
+ ContactList<CList>::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 CList>
+ ContactList<CList>& ContactList<CList>::operator=(const 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 <class CList>
+ ContactList<CList>::ContactList(ContactList&& move) noexcept
+ {
+ *this = std::move(move);
+ }
+
+ template <class CList>
+ ContactList<CList>& ContactList<CList>::operator=(ContactList&& rhs) noexcept
+ {
+
+ }
+
+ template <class CList>
+ CList* ContactList<CList>::AllocateContactList(const size_t& length)
+ {
+ CList* storage = nullptr;
+
+ length_ = length;
+
+ storage = new CList[length]{};
+
+ return storage;
+ }
+}
+
+
+
+
+
+
+#endif CONTACT_LIST_HPP \ No newline at end of file
diff --git a/My structures/My structures.vcxproj b/My structures/My structures.vcxproj
index d95515e..e886d91 100644
--- a/My structures/My structures.vcxproj
+++ b/My structures/My structures.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/My structures/My structures.vcxproj.filters b/My structures/My structures.vcxproj.filters
index 0ee3180..deeda6d 100644
--- a/My structures/My structures.vcxproj.filters
+++ b/My structures/My structures.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