Skip to content

Commit

Permalink
add clean and doc in FileReader
Browse files Browse the repository at this point in the history
issue #29
  • Loading branch information
Valentin Noel committed Dec 2, 2013
1 parent 28357e6 commit de5ecc4
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
9 changes: 6 additions & 3 deletions libraries/FileReader/src/FileReader/FileReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ FileReader::FileReader( std::streambuf* inStream )

size_t FileReader::getLength()
{
size_t position = _fileBuffer.tellg();
size_t currentPosition, length;
currentPosition = _fileBuffer.tellg();

_fileBuffer.seekg( 0, _fileBuffer.end );
size_t length = _fileBuffer.tellg();
_fileBuffer.seekg( position, _fileBuffer.beg );
length = _fileBuffer.tellg();

_fileBuffer.seekg( currentPosition, _fileBuffer.beg );
return length;
}

Expand Down
40 changes: 40 additions & 0 deletions libraries/FileReader/src/FileReader/FileReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,60 @@
namespace file_reader
{

/**
* FileReader, to extract raw data from file.
*/
class FileReader
{
public:

/**
* FileReader's constructor.
* @param inStream Stream buffer from input file.
*/
FileReader( std::streambuf* inStream );

/**
* Get the file length.
* @return File buffer length (in byte).
*/
size_t getLength();

/**
* Get the pointer position within the file.
* @return Offset from the beginning of the file (in byte).
*/
size_t getPosition();

/**
* Extract data from file
* @param[out] data Buffer to fill.
* @param[in] size Buffer size (in byte) to copy.
* @return Whether data have been correctly read and copied from file, or not.
*/
bool readData( char* data, const size_t size );

/**
* Set the pointer at the beginning of the file.
*/
void goToBegin();

/**
* Move the pointer position backward in the stream.
* @param size Number of bytes to take backward.
*/
void goBack ( const std::size_t size );

/**
* Move the pointer position forward in the stream.
* @param size Number of bytes to take forward.
*/
void goForward( const std::size_t size );

/**
* Indicate whether the pointer is at the end of the file stream.
* @return Whether the pointer position corresponds to the end of file, or not.
*/
bool isEndOfFile( );

private:
Expand Down
1 change: 0 additions & 1 deletion libraries/FileReader/test/fileReaderTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ BOOST_AUTO_TEST_SUITE( fileReader_tests_suite01 )
BOOST_AUTO_TEST_CASE( fileReader_init )
{
common::level = common::eLogTrace;
// LOG_INFO( common::level );
}

BOOST_AUTO_TEST_CASE( fileReader_test_streambuffer )
Expand Down

0 comments on commit de5ecc4

Please sign in to comment.