-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Working Set container without inheritance
- Loading branch information
1 parent
baac10c
commit 4cf500a
Showing
15 changed files
with
1,305 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#pragma once | ||
#pragma once | ||
#include "GroupContainer.h" | ||
|
||
// Абстрактный класс: дерево | ||
class AbstractTree : public GroupContainer | ||
{ | ||
public: | ||
// конструктор | ||
AbstractTree(MemoryManager & mem) : GroupContainer(mem) {} | ||
|
||
// деструктор | ||
virtual ~AbstractTree() {} | ||
|
||
class Iterator : public Container::Iterator | ||
{ | ||
public: | ||
// Переход к родительской вершине. Возвращает false если текущая вершина - корень или end(). | ||
virtual bool goToParent() = 0; | ||
|
||
// Переход к дочерней вершине № child_index. Возвращает false если дочерней вершины с таким номером нет. | ||
virtual bool goToChild(int child_index) = 0; | ||
}; | ||
|
||
// Добавление элемента как дочернюю вершину № child_index вершины, на которую | ||
// указывает итератор. В случае успешного добавления функция возвращает значение 0, в случае неудачи 1. | ||
virtual int insert(Iterator * iter, int child_index, void* elem, size_t size) = 0; | ||
|
||
// Удаление вершины, на которую указывает итератор. Если leaf_only==1 и вершина не является листом, возвращает false | ||
// !!! Примечание: метод remove удаляет вершину вместе со всеми ее потомками | ||
virtual bool remove(Iterator * iter, int leaf_only) = 0; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#pragma once | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <cstring> | ||
#include <stdlib.h> | ||
#include <iostream> | ||
#include "MemoryManager.h" | ||
#include "Mem.h" | ||
|
||
using namespace std; | ||
|
||
// Базовый класс для всех абстрактных контейнеров | ||
class Container | ||
{ | ||
protected: | ||
MemoryManager& _memory; | ||
public: | ||
// Базовый класс для исключений, которые запускает контейнер | ||
struct Error | ||
{ | ||
char msg[256]; | ||
Error(const char* err_msg) | ||
{ | ||
strcpy(msg, err_msg); | ||
} | ||
}; | ||
|
||
class Iterator | ||
{ | ||
public: | ||
// Возврашает явно указатель на элемент, на который указывает итератор в данный момент. | ||
// Неявно возвращает размер данных | ||
virtual void* getElement(size_t & size) = 0; | ||
|
||
// Возвращает true, если есть следующий элемент, иначе false. | ||
virtual bool hasNext() = 0; | ||
|
||
// Переход к следующему элементу. | ||
virtual void goToNext() = 0; | ||
|
||
// проверка на равенство итераторов | ||
virtual bool equals(Iterator * right) = 0; | ||
}; | ||
|
||
Container(MemoryManager& mem) : _memory(mem) {} | ||
|
||
// Функция возвращает значение, равное количеству элементов в контейнере. | ||
virtual int size() = 0; | ||
|
||
// Функция возвращает значение, равное максимальной вместимости контейнера в байтах. | ||
virtual size_t max_bytes() = 0; //сколько свободной | ||
|
||
// Функция возвращает указатель на итератор, указывающий на первый найденный | ||
// в контейнере элемент. Если элемент не найден, возвращается пустой указатель. | ||
virtual Iterator* find(void* elem, size_t size) = 0; | ||
|
||
// Создание итератора, соответствующего данному типу контейнера. | ||
virtual Iterator* newIterator() = 0; | ||
|
||
// Функция возвращает указатель на итератор, указывающий на первый элемент | ||
// контейнера. Если контейнер пустой, возвращается нулевой указатель. | ||
virtual Iterator* begin() = 0; | ||
|
||
// Функция возвращает указатель на итератор, указывающий позицию за последним | ||
// элементом контейнера. Если контейнер пустой, возвращается нулевой указатель. | ||
virtual Iterator* end() = 0; | ||
|
||
// Удаление элемента из позиции, на которую указывает итератор iter. | ||
// После удаления итератор указывает на следующий за удаленным элемент. | ||
virtual void remove(Iterator* iter) = 0; | ||
|
||
// Удаление всех элементов из контейнера. | ||
virtual void clear() = 0; | ||
|
||
// Если контейнер пуст возвращает true, иначе false | ||
virtual bool empty() = 0; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
<?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>16.0</VCProjectVersion> | ||
<ProjectGuid>{2C08DEEC-A3EF-441E-A7F6-E989BD6B8872}</ProjectGuid> | ||
<RootNamespace>Containercontest</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>v142</PlatformToolset> | ||
<CharacterSet>Unicode</CharacterSet> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> | ||
<ConfigurationType>Application</ConfigurationType> | ||
<UseDebugLibraries>false</UseDebugLibraries> | ||
<PlatformToolset>v142</PlatformToolset> | ||
<WholeProgramOptimization>true</WholeProgramOptimization> | ||
<CharacterSet>Unicode</CharacterSet> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> | ||
<ConfigurationType>Application</ConfigurationType> | ||
<UseDebugLibraries>true</UseDebugLibraries> | ||
<PlatformToolset>v142</PlatformToolset> | ||
<CharacterSet>Unicode</CharacterSet> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> | ||
<ConfigurationType>Application</ConfigurationType> | ||
<UseDebugLibraries>false</UseDebugLibraries> | ||
<PlatformToolset>v142</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" /> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
<LinkIncremental>true</LinkIncremental> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | ||
<LinkIncremental>true</LinkIncremental> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
<LinkIncremental>false</LinkIncremental> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | ||
<LinkIncremental>false</LinkIncremental> | ||
</PropertyGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<SDLCheck>true</SDLCheck> | ||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
<ConformanceMode>true</ConformanceMode> | ||
<DisableSpecificWarnings>4996</DisableSpecificWarnings> | ||
</ClCompile> | ||
<Link> | ||
<SubSystem>Console</SubSystem> | ||
<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> | ||
<DisableSpecificWarnings>4996</DisableSpecificWarnings> | ||
</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>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
<ConformanceMode>true</ConformanceMode> | ||
<DisableSpecificWarnings>4996</DisableSpecificWarnings> | ||
</ClCompile> | ||
<Link> | ||
<SubSystem>Console</SubSystem> | ||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | ||
<OptimizeReferences>true</OptimizeReferences> | ||
<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> | ||
<DisableSpecificWarnings>4996</DisableSpecificWarnings> | ||
</ClCompile> | ||
<Link> | ||
<SubSystem>Console</SubSystem> | ||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | ||
<OptimizeReferences>true</OptimizeReferences> | ||
<GenerateDebugInformation>true</GenerateDebugInformation> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemGroup> | ||
<ClInclude Include="AbstractTree.h" /> | ||
<ClInclude Include="Container.h" /> | ||
<ClInclude Include="GroupContainer.h" /> | ||
<ClInclude Include="Mem.h" /> | ||
<ClInclude Include="MemoryManager.h" /> | ||
<ClInclude Include="Set.h" /> | ||
<ClInclude Include="SetAbstract.h" /> | ||
<ClInclude Include="Tree.h" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClCompile Include="main.cpp" /> | ||
<ClCompile Include="Set.cpp" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Text Include="Text.txt" /> | ||
</ItemGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | ||
<ImportGroup Label="ExtensionTargets"> | ||
</ImportGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<ItemGroup> | ||
<Filter Include="Исходные файлы"> | ||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> | ||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions> | ||
</Filter> | ||
<Filter Include="Файлы заголовков"> | ||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> | ||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions> | ||
</Filter> | ||
<Filter Include="Файлы ресурсов"> | ||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> | ||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> | ||
</Filter> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClInclude Include="GroupContainer.h"> | ||
<Filter>Файлы заголовков</Filter> | ||
</ClInclude> | ||
<ClInclude Include="Container.h"> | ||
<Filter>Файлы заголовков</Filter> | ||
</ClInclude> | ||
<ClInclude Include="Mem.h"> | ||
<Filter>Файлы заголовков</Filter> | ||
</ClInclude> | ||
<ClInclude Include="MemoryManager.h"> | ||
<Filter>Файлы заголовков</Filter> | ||
</ClInclude> | ||
<ClInclude Include="SetAbstract.h"> | ||
<Filter>Файлы заголовков</Filter> | ||
</ClInclude> | ||
<ClInclude Include="Set.h"> | ||
<Filter>Файлы заголовков</Filter> | ||
</ClInclude> | ||
<ClInclude Include="AbstractTree.h"> | ||
<Filter>Файлы заголовков</Filter> | ||
</ClInclude> | ||
<ClInclude Include="Tree.h"> | ||
<Filter>Файлы заголовков</Filter> | ||
</ClInclude> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClCompile Include="Set.cpp"> | ||
<Filter>Исходные файлы</Filter> | ||
</ClCompile> | ||
<ClCompile Include="main.cpp"> | ||
<Filter>Исходные файлы</Filter> | ||
</ClCompile> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Text Include="Text.txt"> | ||
<Filter>Файлы ресурсов</Filter> | ||
</Text> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#pragma once | ||
#include "Container.h" | ||
|
||
// Áàçîâûé êëàññ äëÿ íåêîòîðîé ãðóïïû àáñòðàêòíûõ êîíòåéíåðîâ | ||
class GroupContainer : public Container | ||
{ | ||
public: | ||
GroupContainer(MemoryManager & mem) : Container(mem) {} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#pragma once | ||
#include "MemoryManager.h" | ||
|
||
// Ïðîñòåéøèé ìåíåäæåð ïàìÿòè, èñïîëüçóåò ::new è ::delete | ||
class Mem : public MemoryManager | ||
{ | ||
public: | ||
Mem(size_t sz) : MemoryManager(sz) {} | ||
|
||
void* allocMem(size_t sz) // êàæäûé ðàç âûçûâàåòñÿ ïðè èíñåðòå | ||
{ | ||
return new char[sz]; //ïîáàéòîâî âûäåëÿåì ïàìÿòü | ||
} | ||
|
||
void freeMem(void* ptr) | ||
{ | ||
delete[] ptr; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#pragma once | ||
#include <stdlib.h> | ||
|
||
// Áàçîâûé êëàññ ìåíåäæåðà ïàìÿòè | ||
class MemoryManager { | ||
private: | ||
size_t _size; | ||
public: | ||
MemoryManager(size_t sz) : _size(sz) {} | ||
|
||
size_t size() | ||
{ | ||
return _size; | ||
} | ||
|
||
virtual size_t maxBytes() { return -1; } | ||
|
||
virtual void* allocMem(size_t sz) = 0; | ||
|
||
virtual void freeMem(void* ptr) = 0; | ||
}; |
Oops, something went wrong.