* Fix bug in BinaryReader where it wasn't correctly reading in all the data

This commit is contained in:
Antidote 2013-01-29 13:46:05 -08:00
parent 8adb9c0e98
commit 1e2065b352
10 changed files with 672 additions and 640 deletions

View File

@ -139,7 +139,7 @@ public:
*/ */
std::string readUnicode(); std::string readUnicode();
private: protected:
/*! \brief Overload of isOpenForWriting in Stream /*! \brief Overload of isOpenForWriting in Stream
* *
* \return false * \return false

View File

@ -30,14 +30,15 @@ public:
/*! \brief The constructor for an Exception /*! \brief The constructor for an Exception
* \param message The error message to throw * \param message The error message to throw
*/ */
Exception(const std::string& message) : inline Exception(const std::string& message) :
m_message(message) m_message(message)
{}; {
};
/*! \brief Returns the Error message of the exception /*! \brief Returns the Error message of the exception
* \return std::string The error message * \return std::string The error message
*/ */
std::string message() const inline std::string message() const
{ {
return m_message; return m_message;
}; };

View File

@ -32,7 +32,7 @@ public:
/*! \brief The constructor for an FileNotFoundException /*! \brief The constructor for an FileNotFoundException
* \param filename The path of the offending file. * \param filename The path of the offending file.
*/ */
FileNotFoundException(const std::string& filename) : inline FileNotFoundException(const std::string& filename) :
Exception("FileNotFoundException:\nCouldn't not find \"" + filename + "\", please check that it exists."), Exception("FileNotFoundException:\nCouldn't not find \"" + filename + "\", please check that it exists."),
m_filename(filename) m_filename(filename)
{} {}
@ -40,7 +40,7 @@ public:
/*! \brief Returns the path of the offending file. /*! \brief Returns the path of the offending file.
* \return std::string The filename of the file including the path. * \return std::string The filename of the file including the path.
*/ */
std::string filename() const { return m_filename; } inline std::string filename() const { return m_filename; }
private: private:
std::string m_filename; std::string m_filename;
}; };

View File

@ -34,7 +34,7 @@ public:
/*! \brief The constructor for an InvalidOperationException /*! \brief The constructor for an InvalidOperationException
* \param error The error message to throw * \param error The error message to throw
*/ */
InvalidOperationException(const std::string& error) inline InvalidOperationException(const std::string& error)
: Exception("InvalidOperationException:\n" + error) : Exception("InvalidOperationException:\n" + error)
{ {
} }

View File

@ -37,7 +37,34 @@
* return 0; * return 0;
* } * }
* \endcode * \endcode
* \section example_sec BinaryReader example
* \code
* #include "BinaryReader.hpp"
* #include "FileNotFoundException.hpp"
* #include "Exception.hpp"
* int main()
* {
* try
* {
* BinaryReader writer("test.bin");
* std::cout << reader.readByte() << std::endl;
* std::cout << reader.readInt32() << std::endl;
* }
* catch (FileNotFoundException e)
* {
* std::cout << e.message() << std::endl;
* }
* catch (Exception e)
* {
* std::cout << e.message() << std::endl;
* }
* catch(...)
* {
* }
* return 0;
* }
* \endcode
* \section Credits * \section Credits
* Chibi Zelda: AnimeWaterFall on Deviantart * Chibi Zelda: <a href="http://animewaterfall.deviantart.com/art/Chibi-Zelda-331611090">AnimeWaterFall</a> on Deviantart
*/ */
#endif // __MAINPAGE_HPP__ #endif // __MAINPAGE_HPP__

View File

@ -32,6 +32,7 @@
class Stream class Stream
{ {
public: public:
//! \brief Default buffer block size.
static const Uint32 BLOCKSZ; static const Uint32 BLOCKSZ;
/*! \enum Endian /*! \enum Endian

View File

@ -1319,7 +1319,7 @@ MAKEINDEX_CMD_NAME = makeindex
# LaTeX documents. This may be useful for small projects and may help to # LaTeX documents. This may be useful for small projects and may help to
# save some trees in general. # save some trees in general.
COMPACT_LATEX = NO COMPACT_LATEX = YES
# The PAPER_TYPE tag can be used to set the paper type that is used # The PAPER_TYPE tag can be used to set the paper type that is used
# by the printer. Possible values are: a4, letter, legal and # by the printer. Possible values are: a4, letter, legal and

View File

@ -28,3 +28,6 @@ SOURCES += \
src/BinaryWriter.cpp \ src/BinaryWriter.cpp \
src/BinaryReader.cpp src/BinaryReader.cpp
system("exec doxygen libzelda.conf")
system("cd doc/latex && make")
system("cd ../../")

View File

@ -68,7 +68,7 @@ BinaryReader::BinaryReader(const std::string& filename)
done += blocksize; done += blocksize;
std::cout << "Read " << done << " bytes" << std::endl; std::cout << "Read " << done << " bytes" << std::endl;
}while (done < m_length); }while (done < length);
fclose(in); fclose(in);
m_length = length; m_length = length;

View File

@ -188,7 +188,7 @@ void Stream::seek(Int64 position, SeekOrigin origin)
switch (origin) switch (origin)
{ {
case Beginning: case Beginning:
if ((position < 0 || (Uint32)position > m_length) && !m_autoResize) if ((position < 0 || (Int64)position > (Int64)m_length) && !m_autoResize)
{ {
std::stringstream ss; std::stringstream ss;
ss << position; ss << position;
@ -199,7 +199,7 @@ void Stream::seek(Int64 position, SeekOrigin origin)
m_position = position; m_position = position;
break; break;
case Current: case Current:
if (((m_position + position) < 0 || (m_position + position) > m_length) && !m_autoResize) if ((((Int64)m_position + position) < 0 || (m_position + position) > m_length) && !m_autoResize)
{ {
std::stringstream ss; std::stringstream ss;
ss << (m_position + position); ss << (m_position + position);
@ -211,7 +211,7 @@ void Stream::seek(Int64 position, SeekOrigin origin)
m_position += position; m_position += position;
break; break;
case End: case End:
if (((m_length - position < 0) || (m_length - position) > m_length) && !m_autoResize) if ((((Int64)m_length - position < 0) || (m_length - position) > m_length) && !m_autoResize)
{ {
std::stringstream ss; std::stringstream ss;
ss << std::hex << "0x" << (m_length - position); ss << std::hex << "0x" << (m_length - position);