Pārlūkot izejas kodu

- StreamReader now should be able to deal with files opened in text mode.
# rename StreamReader::_Begin() to InternBegin(), underscore+capital letter is reserved in C++.

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@988 67173fc5-114c-0410-ac8e-9d2fd5bffc1f

aramis_acg 14 gadi atpakaļ
vecāks
revīzija
af8058498e
1 mainītis faili ar 12 papildinājumiem un 5 dzēšanām
  1. 12 5
      code/StreamReader.h

+ 12 - 5
code/StreamReader.h

@@ -91,7 +91,7 @@ public:
 		, le(le)
 		, le(le)
 	{
 	{
 		ai_assert(stream); 
 		ai_assert(stream); 
-		_Begin();
+		InternBegin();
 	}
 	}
 
 
 	// ---------------------------------------------------------------------
 	// ---------------------------------------------------------------------
@@ -100,7 +100,7 @@ public:
 		, le(le)
 		, le(le)
 	{
 	{
 		ai_assert(stream);
 		ai_assert(stream);
-		_Begin();
+		InternBegin();
 	}
 	}
 
 
 	// ---------------------------------------------------------------------
 	// ---------------------------------------------------------------------
@@ -303,8 +303,13 @@ private:
 	}
 	}
 
 
 	// ---------------------------------------------------------------------
 	// ---------------------------------------------------------------------
-	void _Begin() {
+	void InternBegin() {
 		if (!stream) {
 		if (!stream) {
+			// incase someone wonders: StreamReader is frequently invoked with
+			// no prior validation whether the input stream is valid. Since
+			// no one bothers changing the error message, this message here
+			// is passed down to the caller and 'unable to open file'
+			// simply describes best what happened.
 			throw DeadlyImportError("StreamReader: Unable to open file");
 			throw DeadlyImportError("StreamReader: Unable to open file");
 		}
 		}
 
 
@@ -314,8 +319,10 @@ private:
 		}
 		}
 
 
 		current = buffer = new int8_t[s];
 		current = buffer = new int8_t[s];
-		stream->Read(current,s,1);
-		end = limit = &buffer[s];
+		const size_t read = stream->Read(current,1,s);
+		// (read < s) can only happen if the stream was opened in text mode, in which case FileSize() is not reliable
+		ai_assert(read <= s);
+		end = limit = &buffer[read];
 	}
 	}
 
 
 private:
 private: