aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/others/irrlicht-1.8.1/tools/GUIEditor/CMemoryReadWriteFile.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/others/irrlicht-1.8.1/tools/GUIEditor/CMemoryReadWriteFile.cpp')
-rw-r--r--src/others/irrlicht-1.8.1/tools/GUIEditor/CMemoryReadWriteFile.cpp95
1 files changed, 95 insertions, 0 deletions
diff --git a/src/others/irrlicht-1.8.1/tools/GUIEditor/CMemoryReadWriteFile.cpp b/src/others/irrlicht-1.8.1/tools/GUIEditor/CMemoryReadWriteFile.cpp
new file mode 100644
index 0000000..0a69587
--- /dev/null
+++ b/src/others/irrlicht-1.8.1/tools/GUIEditor/CMemoryReadWriteFile.cpp
@@ -0,0 +1,95 @@
1// Copyright (C) 2002-2012 Nikolaus Gebhardt
2// This file is part of the "Irrlicht Engine".
3// For conditions of distribution and use, see copyright notice in irrlicht.h
4
5#include "CMemoryReadWriteFile.h"
6
7using namespace irr;
8using namespace io;
9
10CMemoryReadWriteFile::CMemoryReadWriteFile(const c8* filename)
11: Data(), FileName(filename), Pos(0)
12{
13}
14
15
16s32 CMemoryReadWriteFile::write(const void* buffer, u32 sizeToWrite)
17{
18 // no point in writing 0 bytes
19 if (sizeToWrite < 1)
20 return 0;
21
22 // expand size
23 if (Pos + sizeToWrite > Data.size())
24 Data.set_used(Pos+sizeToWrite);
25
26 // copy data
27 memcpy( (void*) &Data[Pos], buffer, (size_t) sizeToWrite);
28
29 Pos += sizeToWrite;
30
31 return sizeToWrite;
32
33}
34
35bool CMemoryReadWriteFile::seek(long finalPos, bool relativeMovement)
36{
37 if (relativeMovement)
38 {
39 if (finalPos + Pos < 0)
40 return 0;
41 else
42 Pos += finalPos;
43 }
44 else
45 {
46 Pos = finalPos;
47 }
48
49 if (Pos > (s32)Data.size())
50 Data.set_used(Pos+1);
51
52 return true;
53
54}
55
56const io::path& CMemoryReadWriteFile::getFileName() const
57{
58 return FileName;
59}
60
61long CMemoryReadWriteFile::getPos() const
62{
63 return Pos;
64}
65
66core::array<c8>& CMemoryReadWriteFile::getData()
67{
68 return Data;
69}
70
71
72long CMemoryReadWriteFile::getSize() const
73{
74 return Data.size();
75}
76
77
78s32 CMemoryReadWriteFile::read(void* buffer, u32 sizeToRead)
79{
80 // cant read past the end
81 if (Pos + sizeToRead >= Data.size())
82 sizeToRead = Data.size() - Pos;
83
84 // cant read 0 bytes
85 if (!sizeToRead)
86 return 0;
87
88 // copy data
89 memcpy( buffer, (void*) &Data[Pos], (size_t) sizeToRead);
90
91 Pos += sizeToRead;
92
93 return sizeToRead;
94}
95