diff options
Diffstat (limited to 'libraries/irrlicht-1.8/source/Irrlicht/CLimitReadFile.cpp')
-rw-r--r-- | libraries/irrlicht-1.8/source/Irrlicht/CLimitReadFile.cpp | 254 |
1 files changed, 127 insertions, 127 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CLimitReadFile.cpp b/libraries/irrlicht-1.8/source/Irrlicht/CLimitReadFile.cpp index 51afaad..98bee08 100644 --- a/libraries/irrlicht-1.8/source/Irrlicht/CLimitReadFile.cpp +++ b/libraries/irrlicht-1.8/source/Irrlicht/CLimitReadFile.cpp | |||
@@ -1,127 +1,127 @@ | |||
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 "CLimitReadFile.h" | 5 | #include "CLimitReadFile.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 | CLimitReadFile::CLimitReadFile(IReadFile* alreadyOpenedFile, long pos, | 14 | CLimitReadFile::CLimitReadFile(IReadFile* alreadyOpenedFile, long pos, |
15 | long areaSize, const io::path& name) | 15 | long areaSize, const io::path& name) |
16 | : Filename(name), AreaStart(0), AreaEnd(0), Pos(0), | 16 | : Filename(name), AreaStart(0), AreaEnd(0), Pos(0), |
17 | File(alreadyOpenedFile) | 17 | File(alreadyOpenedFile) |
18 | { | 18 | { |
19 | #ifdef _DEBUG | 19 | #ifdef _DEBUG |
20 | setDebugName("CLimitReadFile"); | 20 | setDebugName("CLimitReadFile"); |
21 | #endif | 21 | #endif |
22 | 22 | ||
23 | if (File) | 23 | if (File) |
24 | { | 24 | { |
25 | File->grab(); | 25 | File->grab(); |
26 | AreaStart = pos; | 26 | AreaStart = pos; |
27 | AreaEnd = AreaStart + areaSize; | 27 | AreaEnd = AreaStart + areaSize; |
28 | } | 28 | } |
29 | } | 29 | } |
30 | 30 | ||
31 | 31 | ||
32 | CLimitReadFile::~CLimitReadFile() | 32 | CLimitReadFile::~CLimitReadFile() |
33 | { | 33 | { |
34 | if (File) | 34 | if (File) |
35 | File->drop(); | 35 | File->drop(); |
36 | } | 36 | } |
37 | 37 | ||
38 | 38 | ||
39 | //! returns how much was read | 39 | //! returns how much was read |
40 | s32 CLimitReadFile::read(void* buffer, u32 sizeToRead) | 40 | s32 CLimitReadFile::read(void* buffer, u32 sizeToRead) |
41 | { | 41 | { |
42 | #if 1 | 42 | #if 1 |
43 | if (0 == File) | 43 | if (0 == File) |
44 | return 0; | 44 | return 0; |
45 | 45 | ||
46 | s32 r = AreaStart + Pos; | 46 | s32 r = AreaStart + Pos; |
47 | s32 toRead = core::s32_min(AreaEnd, r + sizeToRead) - core::s32_max(AreaStart, r); | 47 | s32 toRead = core::s32_min(AreaEnd, r + sizeToRead) - core::s32_max(AreaStart, r); |
48 | if (toRead < 0) | 48 | if (toRead < 0) |
49 | return 0; | 49 | return 0; |
50 | File->seek(r); | 50 | File->seek(r); |
51 | r = File->read(buffer, toRead); | 51 | r = File->read(buffer, toRead); |
52 | Pos += r; | 52 | Pos += r; |
53 | return r; | 53 | return r; |
54 | #else | 54 | #else |
55 | const long pos = File->getPos(); | 55 | const long pos = File->getPos(); |
56 | 56 | ||
57 | if (pos >= AreaEnd) | 57 | if (pos >= AreaEnd) |
58 | return 0; | 58 | return 0; |
59 | 59 | ||
60 | if (pos + (long)sizeToRead >= AreaEnd) | 60 | if (pos + (long)sizeToRead >= AreaEnd) |
61 | sizeToRead = AreaEnd - pos; | 61 | sizeToRead = AreaEnd - pos; |
62 | 62 | ||
63 | return File->read(buffer, sizeToRead); | 63 | return File->read(buffer, sizeToRead); |
64 | #endif | 64 | #endif |
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 | bool CLimitReadFile::seek(long finalPos, bool relativeMovement) | 69 | bool CLimitReadFile::seek(long finalPos, bool relativeMovement) |
70 | { | 70 | { |
71 | #if 1 | 71 | #if 1 |
72 | Pos = core::s32_clamp(finalPos + (relativeMovement ? Pos : 0 ), 0, AreaEnd - AreaStart); | 72 | Pos = core::s32_clamp(finalPos + (relativeMovement ? Pos : 0 ), 0, AreaEnd - AreaStart); |
73 | return true; | 73 | return true; |
74 | #else | 74 | #else |
75 | const long pos = File->getPos(); | 75 | const long pos = File->getPos(); |
76 | 76 | ||
77 | if (relativeMovement) | 77 | if (relativeMovement) |
78 | { | 78 | { |
79 | if (pos + finalPos > AreaEnd) | 79 | if (pos + finalPos > AreaEnd) |
80 | finalPos = AreaEnd - pos; | 80 | finalPos = AreaEnd - pos; |
81 | } | 81 | } |
82 | else | 82 | else |
83 | { | 83 | { |
84 | finalPos += AreaStart; | 84 | finalPos += AreaStart; |
85 | if (finalPos > AreaEnd) | 85 | if (finalPos > AreaEnd) |
86 | return false; | 86 | return false; |
87 | } | 87 | } |
88 | 88 | ||
89 | return File->seek(finalPos, relativeMovement); | 89 | return File->seek(finalPos, relativeMovement); |
90 | #endif | 90 | #endif |
91 | } | 91 | } |
92 | 92 | ||
93 | 93 | ||
94 | //! returns size of file | 94 | //! returns size of file |
95 | long CLimitReadFile::getSize() const | 95 | long CLimitReadFile::getSize() const |
96 | { | 96 | { |
97 | return AreaEnd - AreaStart; | 97 | return AreaEnd - AreaStart; |
98 | } | 98 | } |
99 | 99 | ||
100 | 100 | ||
101 | //! returns where in the file we are. | 101 | //! returns where in the file we are. |
102 | long CLimitReadFile::getPos() const | 102 | long CLimitReadFile::getPos() const |
103 | { | 103 | { |
104 | #if 1 | 104 | #if 1 |
105 | return Pos; | 105 | return Pos; |
106 | #else | 106 | #else |
107 | return File->getPos() - AreaStart; | 107 | return File->getPos() - AreaStart; |
108 | #endif | 108 | #endif |
109 | } | 109 | } |
110 | 110 | ||
111 | 111 | ||
112 | //! returns name of file | 112 | //! returns name of file |
113 | const io::path& CLimitReadFile::getFileName() const | 113 | const io::path& CLimitReadFile::getFileName() const |
114 | { | 114 | { |
115 | return Filename; | 115 | return Filename; |
116 | } | 116 | } |
117 | 117 | ||
118 | 118 | ||
119 | IReadFile* createLimitReadFile(const io::path& fileName, IReadFile* alreadyOpenedFile, long pos, long areaSize) | 119 | IReadFile* createLimitReadFile(const io::path& fileName, IReadFile* alreadyOpenedFile, long pos, long areaSize) |
120 | { | 120 | { |
121 | return new CLimitReadFile(alreadyOpenedFile, pos, areaSize, fileName); | 121 | return new CLimitReadFile(alreadyOpenedFile, pos, areaSize, fileName); |
122 | } | 122 | } |
123 | 123 | ||
124 | 124 | ||
125 | } // end namespace io | 125 | } // end namespace io |
126 | } // end namespace irr | 126 | } // end namespace irr |
127 | 127 | ||