Skip to content

Commit b742949

Browse files
committed
add disk_image abstract class and basic_disk_implementation
- add `disk_image`, `basic_disk_image`, and associated classs to handle to handle reading and writing virtual disk images. - add unit test project for `libcommon` called `libcommon-test`. - add unit tests for `basic_disk_image`.
1 parent 8555604 commit b742949

21 files changed

+2090
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ vcc/disk11.rom
3737
*.swp
3838
*.*~
3939
*~
40+
/packages

Vcc.sln

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sdc", "sdc\sdc.vcxproj", "{
2727
EndProject
2828
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libcommon", "libcommon\libcommon.vcxproj", "{E0AA25BD-5527-475F-8D8B-B549A6311B0C}"
2929
EndProject
30+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libcommon-test", "libcommon-test\libcommon-test.vcxproj", "{B4228078-E3E3-4664-9A84-C8674C71AD76}"
31+
EndProject
3032
Global
3133
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3234
Debug|x86 = Debug|x86
@@ -106,6 +108,12 @@ Global
106108
{E0AA25BD-5527-475F-8D8B-B549A6311B0C}.Legacy|x86.Build.0 = Legacy|Win32
107109
{E0AA25BD-5527-475F-8D8B-B549A6311B0C}.Release|x86.ActiveCfg = Release|Win32
108110
{E0AA25BD-5527-475F-8D8B-B549A6311B0C}.Release|x86.Build.0 = Release|Win32
111+
{B4228078-E3E3-4664-9A84-C8674C71AD76}.Debug|x86.ActiveCfg = Debug|Win32
112+
{B4228078-E3E3-4664-9A84-C8674C71AD76}.Debug|x86.Build.0 = Debug|Win32
113+
{B4228078-E3E3-4664-9A84-C8674C71AD76}.Legacy|x86.ActiveCfg = Debug|Win32
114+
{B4228078-E3E3-4664-9A84-C8674C71AD76}.Legacy|x86.Build.0 = Debug|Win32
115+
{B4228078-E3E3-4664-9A84-C8674C71AD76}.Release|x86.ActiveCfg = Release|Win32
116+
{B4228078-E3E3-4664-9A84-C8674C71AD76}.Release|x86.Build.0 = Release|Win32
109117
EndGlobalSection
110118
GlobalSection(SolutionProperties) = preSolution
111119
HideSolutionNode = FALSE
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Debug|x64">
13+
<Configuration>Debug</Configuration>
14+
<Platform>x64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<PropertyGroup Label="Globals">
22+
<ProjectGuid>{b4228078-e3e3-4664-9a84-c8674c71ad76}</ProjectGuid>
23+
<Keyword>Win32Proj</Keyword>
24+
<WindowsTargetPlatformVersion>10.0.26100.0</WindowsTargetPlatformVersion>
25+
<ConfigurationType>Application</ConfigurationType>
26+
<PlatformToolset>v143</PlatformToolset>
27+
<CharacterSet>Unicode</CharacterSet>
28+
</PropertyGroup>
29+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
30+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
31+
<ImportGroup Label="ExtensionSettings" />
32+
<ImportGroup Label="Shared" />
33+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
34+
<Import Project="..\vcc-base.props" />
35+
<Import Project="..\vcc-debug.props" />
36+
</ImportGroup>
37+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
38+
<Import Project="..\vcc-base.props" />
39+
<Import Project="..\vcc-debug.props" />
40+
</ImportGroup>
41+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
42+
<Import Project="..\vcc-base.props" />
43+
<Import Project="..\vss-release.props" />
44+
</ImportGroup>
45+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
46+
<Import Project="..\vcc-base.props" />
47+
<Import Project="..\vss-release.props" />
48+
</ImportGroup>
49+
<PropertyGroup Label="UserMacros" />
50+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
51+
<OutDir>$(SolutionDir)__obj\$(Platform)\$(Configuration)\vcc\out\</OutDir>
52+
</PropertyGroup>
53+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
54+
<OutDir>$(SolutionDir)__obj\$(Platform)\$(Configuration)\vcc\out\</OutDir>
55+
</PropertyGroup>
56+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
57+
<OutDir>$(SolutionDir)__obj\$(Platform)\$(Configuration)\vcc\out\</OutDir>
58+
</PropertyGroup>
59+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
60+
<OutDir>$(SolutionDir)__obj\$(Platform)\$(Configuration)\vcc\out\</OutDir>
61+
</PropertyGroup>
62+
<ItemDefinitionGroup />
63+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
64+
<ClCompile>
65+
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
66+
<PreprocessorDefinitions>_SILENCE_CXX17_STRSTREAM_DEPRECATION_WARNING;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
67+
</ClCompile>
68+
<Link>
69+
<SubSystem>Console</SubSystem>
70+
</Link>
71+
</ItemDefinitionGroup>
72+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
73+
<ClCompile>
74+
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
75+
<PreprocessorDefinitions>_SILENCE_CXX17_STRSTREAM_DEPRECATION_WARNING;X64;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
76+
</ClCompile>
77+
<Link>
78+
<SubSystem>Console</SubSystem>
79+
</Link>
80+
</ItemDefinitionGroup>
81+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
82+
<ClCompile>
83+
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
84+
<PreprocessorDefinitions>_SILENCE_CXX17_STRSTREAM_DEPRECATION_WARNING;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
85+
</ClCompile>
86+
<Link>
87+
<SubSystem>Console</SubSystem>
88+
</Link>
89+
</ItemDefinitionGroup>
90+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
91+
<ClCompile>
92+
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
93+
<PreprocessorDefinitions>_SILENCE_CXX17_STRSTREAM_DEPRECATION_WARNING;X64;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
94+
</ClCompile>
95+
<Link>
96+
<SubSystem>Console</SubSystem>
97+
</Link>
98+
</ItemDefinitionGroup>
99+
<ItemGroup>
100+
<None Include="packages.config" />
101+
</ItemGroup>
102+
<ItemGroup>
103+
<ClCompile Include="src\media\test_basic_disk_image.cpp" />
104+
</ItemGroup>
105+
<ItemGroup>
106+
<ProjectReference Include="..\libcommon\libcommon.vcxproj">
107+
<Project>{e0aa25bd-5527-475f-8d8b-b549a6311b0c}</Project>
108+
</ProjectReference>
109+
</ItemGroup>
110+
<ItemGroup>
111+
<ClInclude Include="src\media\memory_stream_buffer.h" />
112+
<ClInclude Include="src\media\test_basic_disk_image.h" />
113+
</ItemGroup>
114+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
115+
<ImportGroup Label="ExtensionTargets">
116+
<Import Project="..\packages\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1.7\build\native\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.targets" Condition="Exists('..\packages\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1.7\build\native\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.targets')" />
117+
</ImportGroup>
118+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
119+
<PropertyGroup>
120+
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
121+
</PropertyGroup>
122+
<Error Condition="!Exists('..\packages\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1.7\build\native\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1.7\build\native\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.targets'))" />
123+
</Target>
124+
</Project>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<None Include="packages.config" />
5+
</ItemGroup>
6+
<ItemGroup>
7+
<Filter Include="src">
8+
<UniqueIdentifier>{3d8e57b8-dfc3-42b8-834f-74aeca5764c8}</UniqueIdentifier>
9+
</Filter>
10+
<Filter Include="src\media">
11+
<UniqueIdentifier>{43779a20-4fad-4c5b-abce-e0898a332ecd}</UniqueIdentifier>
12+
</Filter>
13+
</ItemGroup>
14+
<ItemGroup>
15+
<ClCompile Include="src\media\test_basic_disk_image.cpp">
16+
<Filter>src\media</Filter>
17+
</ClCompile>
18+
</ItemGroup>
19+
<ItemGroup>
20+
<ClInclude Include="src\media\memory_stream_buffer.h">
21+
<Filter>src\media</Filter>
22+
</ClInclude>
23+
<ClInclude Include="src\media\test_basic_disk_image.h">
24+
<Filter>src\media</Filter>
25+
</ClInclude>
26+
</ItemGroup>
27+
</Project>

libcommon-test/packages.config

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn" version="1.8.1.7" targetFramework="native" />
4+
</packages>
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#pragma once
2+
#include <vector>
3+
#include <strstream>
4+
5+
6+
// FIXME: strstreambuf is deprecated but used here until a new solution that is
7+
// lighter than the current alternative.
8+
class memory_stream_buffer : public std::strstreambuf
9+
{
10+
public:
11+
using size_type = ::std::size_t;
12+
using buffer_type = ::std::vector<unsigned char>;
13+
using iterator = buffer_type::iterator;
14+
using const_iterator = buffer_type::const_iterator;
15+
using value_type = buffer_type::value_type;
16+
17+
memory_stream_buffer() = default;
18+
19+
void resize(size_type size)
20+
{
21+
buffer_.resize(size);
22+
23+
setg(reinterpret_cast<char_type*>(buffer_.data()),
24+
reinterpret_cast<char_type*>(buffer_.data()),
25+
reinterpret_cast<char_type*>(buffer_.data() + buffer_.size()));
26+
27+
setp(reinterpret_cast<char_type*>(buffer_.data()),
28+
reinterpret_cast<char_type*>(buffer_.data()),
29+
reinterpret_cast<char_type*>(buffer_.data() + buffer_.size()));
30+
}
31+
32+
iterator begin()
33+
{
34+
return buffer_.begin();
35+
}
36+
37+
iterator end()
38+
{
39+
return buffer_.end();
40+
}
41+
42+
const_iterator begin() const
43+
{
44+
return buffer_.begin();
45+
}
46+
47+
const_iterator end() const
48+
{
49+
return buffer_.end();
50+
}
51+
52+
value_type& operator[](size_type index)
53+
{
54+
return buffer_[index];
55+
}
56+
57+
value_type operator[](size_type index) const
58+
{
59+
return buffer_[index];
60+
}
61+
62+
63+
private:
64+
65+
buffer_type buffer_;
66+
};

0 commit comments

Comments
 (0)