Skip to content

Commit fa4ec6f

Browse files
ChristopherChristopher
authored andcommitted
Api
1 parent 1fb6cce commit fa4ec6f

File tree

6 files changed

+71
-0
lines changed

6 files changed

+71
-0
lines changed

FileCreator/DataFile.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include "stdafx.h"
2+
#include "DataFile.h"
3+
4+
DataFile::DataFile()
5+
{
6+
this->file = new fstream();
7+
}
8+
9+
DataFile::DataFile(char * path)
10+
{
11+
this->path = path;
12+
13+
this->file = new fstream();
14+
this->file->open(this->path, ios::in | ios::out | ios::trunc | ios::binary);
15+
}
16+
17+
void DataFile::open()
18+
{
19+
this->file->open(this->path, ios::in | ios::out | ios::binary);
20+
}
21+
22+
void DataFile::close()
23+
{
24+
this->file->close();
25+
}
26+
27+
void DataFile::write(char * data, unsigned int position, unsigned int size)
28+
{
29+
this->file->seekp(0, ios::beg);
30+
this->file->seekp(position * size);
31+
32+
this->file->write(data, size);
33+
}
34+
35+
char * DataFile::read(unsigned int position, unsigned int size)
36+
{
37+
char* element = new char();
38+
39+
this->file->seekg(0, ios::beg);
40+
this->file->seekg(position * size);
41+
42+
this->file->read(element, size);
43+
44+
return element;
45+
}

FileCreator/DataFile.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#pragma once
2+
3+
#include <fstream>
4+
5+
class DataFile
6+
{
7+
private:
8+
fstream * file;
9+
char * path;
10+
public:
11+
DataFile();
12+
DataFile(char * path);
13+
void open();
14+
void close();
15+
void write(char * data, unsigned int position, unsigned int size);
16+
char* read(unsigned int position, unsigned int size);
17+
};
18+

FileCreator/FileCreator.cpp

1.1 KB
Binary file not shown.

FileCreator/FileCreator.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,12 @@
147147
</Link>
148148
</ItemDefinitionGroup>
149149
<ItemGroup>
150+
<ClInclude Include="DataFile.h" />
150151
<ClInclude Include="stdafx.h" />
151152
<ClInclude Include="targetver.h" />
152153
</ItemGroup>
153154
<ItemGroup>
155+
<ClCompile Include="DataFile.cpp" />
154156
<ClCompile Include="FileCreator.cpp" />
155157
<ClCompile Include="stdafx.cpp">
156158
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>

FileCreator/FileCreator.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
<ClInclude Include="targetver.h">
2222
<Filter>Header Files</Filter>
2323
</ClInclude>
24+
<ClInclude Include="DataFile.h">
25+
<Filter>Header Files</Filter>
26+
</ClInclude>
2427
</ItemGroup>
2528
<ItemGroup>
2629
<ClCompile Include="stdafx.cpp">
@@ -29,5 +32,8 @@
2932
<ClCompile Include="FileCreator.cpp">
3033
<Filter>Source Files</Filter>
3134
</ClCompile>
35+
<ClCompile Include="DataFile.cpp">
36+
<Filter>Source Files</Filter>
37+
</ClCompile>
3238
</ItemGroup>
3339
</Project>

FileCreator/stdafx.h

126 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)