diff options
Diffstat (limited to '')
-rw-r--r-- | libraries/irrlicht-1.8/source/Irrlicht/CMemoryFile.cpp | 244 |
1 files changed, 122 insertions, 122 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CMemoryFile.cpp b/libraries/irrlicht-1.8/source/Irrlicht/CMemoryFile.cpp index d25c1f2..cb6b04f 100644 --- a/libraries/irrlicht-1.8/source/Irrlicht/CMemoryFile.cpp +++ b/libraries/irrlicht-1.8/source/Irrlicht/CMemoryFile.cpp | |||
@@ -1,122 +1,122 @@ | |||
1 | // Copyright (C) 2002-2012 Nikolaus Gebhardt | 1 | // Copyright (C) 2002-2012 Nikolaus Gebhardt |
2 | // This file is part of the "Irrlicht Engine". | 2 | // This file is part of the "Irrlicht Engine". |
3 | // For conditions of distribution and use, see copyright notice in irrlicht.h | 3 | // For conditions of distribution and use, see copyright notice in irrlicht.h |
4 | 4 | ||
5 | #include "CMemoryFile.h" | 5 | #include "CMemoryFile.h" |
6 | #include "irrString.h" | 6 | #include "irrString.h" |
7 | 7 | ||
8 | namespace irr | 8 | namespace irr |
9 | { | 9 | { |
10 | namespace io | 10 | namespace io |
11 | { | 11 | { |
12 | 12 | ||
13 | 13 | ||
14 | CMemoryFile::CMemoryFile(void* memory, long len, const io::path& fileName, bool d) | 14 | CMemoryFile::CMemoryFile(void* memory, long len, const io::path& fileName, bool d) |
15 | : Buffer(memory), Len(len), Pos(0), Filename(fileName), deleteMemoryWhenDropped(d) | 15 | : Buffer(memory), Len(len), Pos(0), Filename(fileName), deleteMemoryWhenDropped(d) |
16 | { | 16 | { |
17 | #ifdef _DEBUG | 17 | #ifdef _DEBUG |
18 | setDebugName("CMemoryFile"); | 18 | setDebugName("CMemoryFile"); |
19 | #endif | 19 | #endif |
20 | } | 20 | } |
21 | 21 | ||
22 | 22 | ||
23 | CMemoryFile::~CMemoryFile() | 23 | CMemoryFile::~CMemoryFile() |
24 | { | 24 | { |
25 | if (deleteMemoryWhenDropped) | 25 | if (deleteMemoryWhenDropped) |
26 | delete [] (c8*)Buffer; | 26 | delete [] (c8*)Buffer; |
27 | } | 27 | } |
28 | 28 | ||
29 | 29 | ||
30 | //! returns how much was read | 30 | //! returns how much was read |
31 | s32 CMemoryFile::read(void* buffer, u32 sizeToRead) | 31 | s32 CMemoryFile::read(void* buffer, u32 sizeToRead) |
32 | { | 32 | { |
33 | s32 amount = static_cast<s32>(sizeToRead); | 33 | s32 amount = static_cast<s32>(sizeToRead); |
34 | if (Pos + amount > Len) | 34 | if (Pos + amount > Len) |
35 | amount -= Pos + amount - Len; | 35 | amount -= Pos + amount - Len; |
36 | 36 | ||
37 | if (amount <= 0) | 37 | if (amount <= 0) |
38 | return 0; | 38 | return 0; |
39 | 39 | ||
40 | c8* p = (c8*)Buffer; | 40 | c8* p = (c8*)Buffer; |
41 | memcpy(buffer, p + Pos, amount); | 41 | memcpy(buffer, p + Pos, amount); |
42 | 42 | ||
43 | Pos += amount; | 43 | Pos += amount; |
44 | 44 | ||
45 | return amount; | 45 | return amount; |
46 | } | 46 | } |
47 | 47 | ||
48 | //! returns how much was written | 48 | //! returns how much was written |
49 | s32 CMemoryFile::write(const void* buffer, u32 sizeToWrite) | 49 | s32 CMemoryFile::write(const void* buffer, u32 sizeToWrite) |
50 | { | 50 | { |
51 | s32 amount = static_cast<s32>(sizeToWrite); | 51 | s32 amount = static_cast<s32>(sizeToWrite); |
52 | if (Pos + amount > Len) | 52 | if (Pos + amount > Len) |
53 | amount -= Pos + amount - Len; | 53 | amount -= Pos + amount - Len; |
54 | 54 | ||
55 | if (amount <= 0) | 55 | if (amount <= 0) |
56 | return 0; | 56 | return 0; |
57 | 57 | ||
58 | c8* p = (c8*)Buffer; | 58 | c8* p = (c8*)Buffer; |
59 | memcpy(p + Pos, buffer, amount); | 59 | memcpy(p + Pos, buffer, amount); |
60 | 60 | ||
61 | Pos += amount; | 61 | Pos += amount; |
62 | 62 | ||
63 | return amount; | 63 | return amount; |
64 | } | 64 | } |
65 | 65 | ||
66 | 66 | ||
67 | 67 | ||
68 | //! changes position in file, returns true if successful | 68 | //! changes position in file, returns true if successful |
69 | //! if relativeMovement==true, the pos is changed relative to current pos, | 69 | //! if relativeMovement==true, the pos is changed relative to current pos, |
70 | //! otherwise from begin of file | 70 | //! otherwise from begin of file |
71 | bool CMemoryFile::seek(long finalPos, bool relativeMovement) | 71 | bool CMemoryFile::seek(long finalPos, bool relativeMovement) |
72 | { | 72 | { |
73 | if (relativeMovement) | 73 | if (relativeMovement) |
74 | { | 74 | { |
75 | if (Pos + finalPos > Len) | 75 | if (Pos + finalPos > Len) |
76 | return false; | 76 | return false; |
77 | 77 | ||
78 | Pos += finalPos; | 78 | Pos += finalPos; |
79 | } | 79 | } |
80 | else | 80 | else |
81 | { | 81 | { |
82 | if (finalPos > Len) | 82 | if (finalPos > Len) |
83 | return false; | 83 | return false; |
84 | 84 | ||
85 | Pos = finalPos; | 85 | Pos = finalPos; |
86 | } | 86 | } |
87 | 87 | ||
88 | return true; | 88 | return true; |
89 | } | 89 | } |
90 | 90 | ||
91 | 91 | ||
92 | //! returns size of file | 92 | //! returns size of file |
93 | long CMemoryFile::getSize() const | 93 | long CMemoryFile::getSize() const |
94 | { | 94 | { |
95 | return Len; | 95 | return Len; |
96 | } | 96 | } |
97 | 97 | ||
98 | 98 | ||
99 | //! returns where in the file we are. | 99 | //! returns where in the file we are. |
100 | long CMemoryFile::getPos() const | 100 | long CMemoryFile::getPos() const |
101 | { | 101 | { |
102 | return Pos; | 102 | return Pos; |
103 | } | 103 | } |
104 | 104 | ||
105 | 105 | ||
106 | //! returns name of file | 106 | //! returns name of file |
107 | const io::path& CMemoryFile::getFileName() const | 107 | const io::path& CMemoryFile::getFileName() const |
108 | { | 108 | { |
109 | return Filename; | 109 | return Filename; |
110 | } | 110 | } |
111 | 111 | ||
112 | 112 | ||
113 | IReadFile* createMemoryReadFile(void* memory, long size, const io::path& fileName, bool deleteMemoryWhenDropped) | 113 | IReadFile* createMemoryReadFile(void* memory, long size, const io::path& fileName, bool deleteMemoryWhenDropped) |
114 | { | 114 | { |
115 | CMemoryFile* file = new CMemoryFile(memory, size, fileName, deleteMemoryWhenDropped); | 115 | CMemoryFile* file = new CMemoryFile(memory, size, fileName, deleteMemoryWhenDropped); |
116 | return file; | 116 | return file; |
117 | } | 117 | } |
118 | 118 | ||
119 | 119 | ||
120 | } // end namespace io | 120 | } // end namespace io |
121 | } // end namespace irr | 121 | } // end namespace irr |
122 | 122 | ||