diff options
Diffstat (limited to 'Homework8/MyStructures')
| -rw-r--r-- | Homework8/MyStructures/Contact.hpp | 108 | ||||
| -rw-r--r-- | Homework8/MyStructures/ContactList.hpp | 119 | ||||
| -rw-r--r-- | Homework8/MyStructures/MyStructures.vcxproj | 136 | ||||
| -rw-r--r-- | Homework8/MyStructures/MyStructures.vcxproj.filters | 7 |
4 files changed, 370 insertions, 0 deletions
diff --git a/Homework8/MyStructures/Contact.hpp b/Homework8/MyStructures/Contact.hpp new file mode 100644 index 0000000..f7fda6c --- /dev/null +++ b/Homework8/MyStructures/Contact.hpp @@ -0,0 +1,108 @@ +#ifndef CONTACT_HPP +#define CONTACT_HPP + +namespace MyStructures //variables declared here act as a global variable +{ + template <typename T> + class Contact + { + public: + Contact() = default; + Contact(const char* name, const short age); + + ~Contact() = default; + + Contact(const Contact& copy); //copy constructor + Contact& operator=(const Contact& rhs); //copy assignment + + Contact(Contact&& move); //move constructor + Contact& operator=(Contact&& rhs); //move assignment + + + short GetAge(); + const char* GetName(); + + void SetAge(short age); + void SetName(const char* name); + + void Print(); + + T GetCustomValue(T& newValue); + + private: + const char* name_{}; + short age_{ 0 }; + T custom_value_{}; //one type is declared, it will be custom + + + }; + + + template<typename T> + Contact<T>::Contact(const char* name, const short age) + { + } + + template<typename T> + Contact<T>::Contact(const Contact& copy) + { + } + + template<typename T> + Contact<T>& Contact<T>::operator=(const Contact& rhs) + { + // TODO: insert return statement here + } + + template<typename T> + Contact<T>::Contact(Contact&& move) + { + } + + template<typename T> + Contact<T>& Contact<T>::operator=(Contact&& rhs) + { + // TODO: insert return statement here + } + + + + template<typename T> + short Contact<T>::GetAge() + { + return 0; + } + + template<typename T> + const char* Contact<T>::GetName() + { + return nullptr; + } + + template<typename T> + void Contact<T>::SetAge(short age) + { + } + + template<typename T> + void Contact<T>::SetName(const char* name) + { + } + + template<typename T> + inline void Contact<T>::Print() + { + } + + template<typename T> + T Contact<T>::GetCustomValue(T& newValue) + { + custom_value_ = newValue + return T(); + } + +} + + + +#endif
\ No newline at end of file diff --git a/Homework8/MyStructures/ContactList.hpp b/Homework8/MyStructures/ContactList.hpp new file mode 100644 index 0000000..dd0f4ee --- /dev/null +++ b/Homework8/MyStructures/ContactList.hpp @@ -0,0 +1,119 @@ +#ifndef CONTACT_LIST_HPP +#define CONTACT_LIST_HPP + +namespace MyStructures +{ + template<class C> + class ContactList + { + public: + ContactList() = default; + ContactList(size_t size); //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 + + private: + C* contacts_{ nullptr }; + size_t length_{ 0 }; //entire length of array + size_t size_{ 0 }; //number of actual elements + + C* AllocateContactList(const size_t& length); + }; + template<class C> + ContactList<C>::ContactList(size_t size) + { + contacts_ = AllocateContactList(size); + } + 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_); + + contacts_ AllocateContactList(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) //asking if they're the same object + { + delete[] contacts_; + contacts_ = nullptr; + + contacts_ = AllocateContactList(rhs.length_); + size_ = rhs.size_; + contacts_ AllocateContactList(length); + + for (auto i = 0u; i < length_; ++i) + { + contacts_[i] = rhs[i]; + } + } + return *this; + } + template<class C> + ContactList<C>::ContactList(ContactList&& move) + { + *this = std::move(move); //move shifts addresses + } + 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; //Invalidate the other object + } + template<class C> + C* ContactList<C>::AllocateContactList(const size_t& length) + { + C* storage = nullptr + length_ - length; + + storage = newC[length]{}; + + return storage; + } +}; +} + + + + + + +#endif
\ No newline at end of file diff --git a/Homework8/MyStructures/MyStructures.vcxproj b/Homework8/MyStructures/MyStructures.vcxproj new file mode 100644 index 0000000..92eff89 --- /dev/null +++ b/Homework8/MyStructures/MyStructures.vcxproj @@ -0,0 +1,136 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup Label="ProjectConfigurations"> + <ProjectConfiguration Include="Debug|Win32"> + <Configuration>Debug</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|Win32"> + <Configuration>Release</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Debug|x64"> + <Configuration>Debug</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|x64"> + <Configuration>Release</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + </ItemGroup> + <PropertyGroup Label="Globals"> + <VCProjectVersion>17.0</VCProjectVersion> + <Keyword>Win32Proj</Keyword> + <ProjectGuid>{bf896e58-aec3-431b-9fe4-6f7061977aa2}</ProjectGuid> + <RootNamespace>MyStructures</RootNamespace> + <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <PlatformToolset>v143</PlatformToolset> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <PlatformToolset>v143</PlatformToolset> + <WholeProgramOptimization>true</WholeProgramOptimization> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <PlatformToolset>v143</PlatformToolset> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <PlatformToolset>v143</PlatformToolset> + <WholeProgramOptimization>true</WholeProgramOptimization> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> + <ImportGroup Label="ExtensionSettings"> + </ImportGroup> + <ImportGroup Label="Shared"> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <PropertyGroup Label="UserMacros" /> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <SDLCheck>true</SDLCheck> + <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <ConformanceMode>true</ConformanceMode> + </ClCompile> + <Link> + <SubSystem>Console</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <SDLCheck>true</SDLCheck> + <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <ConformanceMode>true</ConformanceMode> + </ClCompile> + <Link> + <SubSystem>Console</SubSystem> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + <GenerateDebugInformation>true</GenerateDebugInformation> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <SDLCheck>true</SDLCheck> + <PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <ConformanceMode>true</ConformanceMode> + </ClCompile> + <Link> + <SubSystem>Console</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <SDLCheck>true</SDLCheck> + <PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <ConformanceMode>true</ConformanceMode> + </ClCompile> + <Link> + <SubSystem>Console</SubSystem> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + <GenerateDebugInformation>true</GenerateDebugInformation> + </Link> + </ItemDefinitionGroup> + <ItemGroup> + <ClInclude Include="Contact.hpp" /> + <ClInclude Include="ContactList.hpp" /> + </ItemGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> + <ImportGroup Label="ExtensionTargets"> + </ImportGroup> +</Project>
\ No newline at end of file diff --git a/Homework8/MyStructures/MyStructures.vcxproj.filters b/Homework8/MyStructures/MyStructures.vcxproj.filters new file mode 100644 index 0000000..deeda6d --- /dev/null +++ b/Homework8/MyStructures/MyStructures.vcxproj.filters @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="utf-8"?> +<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 |