Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3821Б1ПМ3 Афонин Михаил Дмитриевич #211

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion sln/vc10/bitfield/bitfield.vcxproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
Expand All @@ -14,16 +14,19 @@
<ProjectGuid>{A76282B3-4276-4945-9AF2-3AC68111A828}</ProjectGuid>
<RootNamespace>bitfield</RootNamespace>
<Keyword>Win32Proj</Keyword>
<WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
Expand Down
5 changes: 4 additions & 1 deletion sln/vc10/gtest/gtest.vcxproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
Expand All @@ -14,16 +14,19 @@
<ProjectGuid>{60932AFC-7808-48B7-B3BF-F2BC151C0065}</ProjectGuid>
<RootNamespace>gtest</RootNamespace>
<Keyword>Win32Proj</Keyword>
<WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
Expand Down
5 changes: 4 additions & 1 deletion sln/vc10/sample_prime_numbers/sample_prime_numbers.vcxproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
Expand All @@ -14,16 +14,19 @@
<ProjectGuid>{5D0218F2-E502-414F-BA66-9E76B2785178}</ProjectGuid>
<RootNamespace>sample_prime_numbers</RootNamespace>
<Keyword>Win32Proj</Keyword>
<WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
Expand Down
5 changes: 4 additions & 1 deletion sln/vc10/test_bitfield/test_bitfield.vcxproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
Expand All @@ -14,16 +14,19 @@
<ProjectGuid>{C650C93E-F0A7-4235-9F5F-0DCE78609BFB}</ProjectGuid>
<RootNamespace>test_bitfield</RootNamespace>
<Keyword>Win32Proj</Keyword>
<WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
Expand Down
188 changes: 176 additions & 12 deletions src/tbitfield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,86 +13,250 @@ static TBitField FAKE_BITFIELD(1);

TBitField::TBitField(int len)
{
if (len >= 0)
{
BitLen = len;
MemLen = len * sizeof(TELEM) * 8;
pMem = new TELEM[MemLen];
for (int i = 0; i < MemLen; i++)
{
pMem[i] = 0;
}
}
else
throw "Error";
}

TBitField::TBitField(const TBitField &bf) // конструктор копирования
{
MemLen = bf.MemLen;
BitLen = bf.BitLen;
pMem = new TELEM[MemLen];
for (int i = 0; i < MemLen; i++)
{
pMem[i] = bf.pMem[i];
}
}

TBitField::~TBitField()
{
if (pMem != 0)
{
delete[] pMem;
}
pMem = 0;
MemLen = 0;
BitLen = 0;
}

int TBitField::GetMemIndex(const int n) const // индекс Мем для бита n
{
return FAKE_INT;
if ((n < 0) || (n > BitLen))
{
throw "Error";
}
else
return n >> 5;
}

TELEM TBitField::GetMemMask(const int n) const // битовая маска для бита n
{
return FAKE_INT;
if ((n < 0) && (n < BitLen))
{
throw "Error";
}
return 1 << (n & 31);
}

// доступ к битам битового поля

int TBitField::GetLength(void) const // получить длину (к-во битов)
{
return FAKE_INT;
return BitLen;
}

void TBitField::SetBit(const int n) // установить бит
{
if ((n >= 0) && (n < BitLen))
{
int i = GetMemIndex(n);
int m = GetMemMask(n);
pMem[i] = pMem[i] | m;
}
else
{
throw "Error";
}
}

void TBitField::ClrBit(const int n) // очистить бит
{
if ((n >= 0) && (n < BitLen))
{
int i = GetMemIndex(n);
int m = GetMemMask(n);
pMem[i] = pMem[i] & ~m;
}
else
{
throw "error";
}
}

int TBitField::GetBit(const int n) const // получить значение бита
{
return FAKE_INT;
if ((n >= 0) && (n < BitLen))
{
int i = GetMemIndex(n);
int m = GetMemMask(n);
return (pMem[i] & m);
}
else
{
throw "Error";
}
}

// битовые операции

TBitField& TBitField::operator=(const TBitField &bf) // присваивание
{
return FAKE_BITFIELD;
if (this == &bf)
return *this;
else
{
delete[] pMem;
MemLen = bf.MemLen;
pMem = new TELEM[MemLen];
BitLen = bf.BitLen;
for (int i = 0; i < MemLen; i++)
{
pMem[i] = bf.pMem[i];
}
return *this;
}
}

int TBitField::operator==(const TBitField &bf) const // сравнение
{
return FAKE_INT;
if ((MemLen == bf.MemLen) && (BitLen == bf.BitLen))
{
for (int i = 0; i < MemLen; i++)
{
if (pMem[i] != bf.pMem[i])
return 0;
}
return 1;
}
return 0;
}

int TBitField::operator!=(const TBitField &bf) const // сравнение
{
return FAKE_INT;
if ((MemLen == bf.MemLen) && (BitLen == bf.BitLen))
{
for (int i = 0; i < MemLen; i++)
{
if (pMem[i] == bf.pMem[i])
return 1;
}
return 0;
}
return 1;
}

TBitField TBitField::operator|(const TBitField &bf) // операция "или"
{
return FAKE_BITFIELD;
if (BitLen >= bf.BitLen)
{
TBitField res = TBitField(BitLen);
for (int i = 0; i < MemLen; i++)
{
res.pMem[i] = pMem[i] | bf.pMem[i];
}
return res;
}
else
{
TBitField res = TBitField(bf.BitLen);
for (int i = 0; i < MemLen; i++)
{
res.pMem[i] = pMem[i] | bf.pMem[i];
}
return res;
}
}

TBitField TBitField::operator&(const TBitField &bf) // операция "и"
{
return FAKE_BITFIELD;
if (BitLen >= bf.BitLen)
{
TBitField res = TBitField(BitLen);
for (int i = 0; i < MemLen; i++)
{
res.pMem[i] = pMem[i] & bf.pMem[i];
}
return res;
}
else
{
TBitField res = TBitField(bf.BitLen);
for (int i = 0; i < MemLen; i++)
{
res.pMem[i] = pMem[i] & bf.pMem[i];
}
return res;
}
}

TBitField TBitField::operator~(void) // отрицание
{
return FAKE_BITFIELD;
TBitField res(*this);
for (int i = 0; i < BitLen; i++)
{
if (GetBit(i))
{
res.ClrBit(i);
}
else
res.SetBit(i);
}
return res;
}

// ввод/вывод

istream &operator>>(istream &istr, TBitField &bf) // ввод
{
return istr;
int l;
istr >> l;
TBitField res(l);

char* m = new char[l];
istr >> m;
for (int i = 0; i < bf.BitLen; i++)
{
if (m[i] == 0)
{
bf.ClrBit(i);
}
else
{
if (m[i] == 1)
{
bf.SetBit(i);
}
else
throw "Error";
}
}
return istr;
}

ostream &operator<<(ostream &ostr, const TBitField &bf) // вывод
{
return ostr;
for (int i = 0; i < bf.BitLen; i++)
ostr << bf.GetBit(i);

return ostr;
}
Loading