xsens_imu
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
xsens::Cmt1f Class Reference

The low-level file communication class. More...

#include <cmt1.h>

Public Member Functions

 Cmt1f ()
 Default constructor, initializes all members to their default values. More...
 
 ~Cmt1f ()
 Destructor. More...
 
XsensResultValue appendData (const uint32_t length, const void *data)
 Write data to the end of the file. More...
 
XsensResultValue close (void)
 Close the file. More...
 
XsensResultValue closeAndDelete (void)
 Close the file and delete it. More...
 
XsensResultValue create (const char *filename)
 Open an empty file. More...
 
XsensResultValue create (const wchar_t *filename)
 Open an empty file using a unicode path + filename. More...
 
XsensResultValue deleteData (const XsensFilePos start, const uint32_t length)
 Delete the given data from the file. More...
 
XsensResultValue find (const void *needle, const uint32_t needleLength, XsensFilePos &pos)
 Find a string of bytes in the file. More...
 
XsensResultValue flushData (void)
 Flush all data to be written. This function writes any remaining data immediately and does not return until this is done. More...
 
XsensFilePos getFileSize (void) const
 Return the size of the file. More...
 
XsensResultValue getLastResult (void) const
 Return the result code of the last operation. More...
 
XsensResultValue getName (char *filename) const
 Retrieve the filename that was last successfully opened. More...
 
XsensResultValue getName (wchar_t *filename) const
 Retrieve the filename that was last successfully opened in unicode. More...
 
XsensFilePos getReadPos (void) const
 Return the current read position. More...
 
XsensFilePos getWritePos (void) const
 Return the current write position. More...
 
XsensResultValue insertData (const XsensFilePos start, const uint32_t length, const void *data)
 Insert the given data into the file. More...
 
bool isOpen (void) const
 Return whether the file is open or not. More...
 
bool isReadOnly (void) const
 Return whether the file is readonly or not. More...
 
XsensResultValue open (const char *filename, const bool create, const bool readOnly)
 Open a file. More...
 
XsensResultValue open (const wchar_t *filename, const bool create, const bool readOnly)
 Open a file using a unicode filename. More...
 
XsensResultValue readData (const uint32_t maxLength, void *data, uint32_t *length)
 Read data from the file and put it into the data buffer. More...
 
XsensResultValue readData (const uint32_t maxLength, const char terminator, void *data, uint32_t *length)
 Read data from the file and put it into the data buffer. More...
 
XsensResultValue setReadPos (const XsensFilePos pos)
 Set the new absolute read position. More...
 
XsensResultValue setWritePos (const XsensFilePos pos=-1)
 Set the new absolute write position. More...
 
XsensResultValue writeData (const uint32_t length, const void *data)
 Write data to the file. More...
 

Protected Member Functions

void gotoRead (void)
 Change from writing to reading mode. More...
 
void gotoWrite (void)
 Change from reading to writing mode. More...
 

Protected Attributes

FILE * m_handle
 The file handle. More...
 
XsensFilePos m_fileSize
 Contains the size of the file. More...
 
XsensFilePos m_readPos
 The last read position in the file. More...
 
XsensFilePos m_writePos
 The last write position in the file. More...
 
XsensResultValue m_lastResult
 The last result of an operation. More...
 
char m_filename [CMT_MAX_FILENAME_LENGTH]
 Contains the name of the file that was last successfully opened. More...
 
wchar_t m_filename_w [CMT_MAX_FILENAME_LENGTH]
 Contains the name of the file that was last successfully opened using unicode. More...
 
bool m_isOpen
 Indicates if the file is open or not. More...
 
bool m_unicode
 Indicates if we're using the unicode filename or the regular filename. More...
 
bool m_reading
 Indicates whether the last operation was a read or write operation. More...
 
bool m_readOnly
 Indicates if the file was opened in read-only mode. More...
 

Detailed Description

The low-level file communication class.

Constructor & Destructor Documentation

◆ Cmt1f()

xsens::Cmt1f::Cmt1f ( )

Default constructor, initializes all members to their default values.

◆ ~Cmt1f()

xsens::Cmt1f::~Cmt1f ( )

Destructor.

Member Function Documentation

◆ appendData()

XsensResultValue xsens::Cmt1f::appendData ( const uint32_t  length,
const void *  data 
)

Write data to the end of the file.

The function writes the given data to the file at the end. The current write position is also moved to the end of the file.

◆ close()

XsensResultValue xsens::Cmt1f::close ( void  )

Close the file.

◆ closeAndDelete()

XsensResultValue xsens::Cmt1f::closeAndDelete ( void  )

Close the file and delete it.

◆ create() [1/2]

XsensResultValue xsens::Cmt1f::create ( const char *  filename)

Open an empty file.

Test:
does this work for non-existing files? Or do we need a check and create?

◆ create() [2/2]

XsensResultValue xsens::Cmt1f::create ( const wchar_t *  filename)

Open an empty file using a unicode path + filename.

◆ deleteData()

XsensResultValue xsens::Cmt1f::deleteData ( const XsensFilePos  start,
const uint32_t  length 
)

Delete the given data from the file.

The function erases the given data from the file at the given write position. This operation may take a while to complete, but is faster than insertData.

The write position is not changed and the read position is checked for validity.

◆ find()

XsensResultValue xsens::Cmt1f::find ( const void *  needle,
const uint32_t  needleLength,
XsensFilePos pos 
)

Find a string of bytes in the file.

The function searches from the current read position until the given needle is found. If the needle is not found, XsensResultValue::NOT_FOUND is returned. The function will update the seek position to the first character of the found needle.

Parameters
needleThe byte string to find.
needleLengthThe length of the byte string.
posOut: The position where the needle was found. This will point to the first character of the found needle.

◆ flushData()

XsensResultValue xsens::Cmt1f::flushData ( void  )

Flush all data to be written. This function writes any remaining data immediately and does not return until this is done.

◆ getFileSize()

XsensFilePos xsens::Cmt1f::getFileSize ( void  ) const
inline

Return the size of the file.

◆ getLastResult()

XsensResultValue xsens::Cmt1f::getLastResult ( void  ) const
inline

Return the result code of the last operation.

◆ getName() [1/2]

XsensResultValue xsens::Cmt1f::getName ( char *  filename) const

Retrieve the filename that was last successfully opened.

Parameters
filenameA buffer for storing the filename. The buffer should be able to hold the filename. A safe size is to make it at least 256 bytes.

◆ getName() [2/2]

XsensResultValue xsens::Cmt1f::getName ( wchar_t *  filename) const

Retrieve the filename that was last successfully opened in unicode.

Parameters
filenameA buffer for storing the filename. The buffer should be able to hold the filename. A safe size is to make it at least 256 wide characters.

◆ getReadPos()

XsensFilePos xsens::Cmt1f::getReadPos ( void  ) const
inline

Return the current read position.

◆ getWritePos()

XsensFilePos xsens::Cmt1f::getWritePos ( void  ) const
inline

Return the current write position.

◆ gotoRead()

void xsens::Cmt1f::gotoRead ( void  )
protected

Change from writing to reading mode.

◆ gotoWrite()

void xsens::Cmt1f::gotoWrite ( void  )
protected

Change from reading to writing mode.

◆ insertData()

XsensResultValue xsens::Cmt1f::insertData ( const XsensFilePos  start,
const uint32_t  length,
const void *  data 
)

Insert the given data into the file.

The function writes the given data to the file at the current write position. This operation may take a while to complete.

The write position is placed at the end of the inserted data.

◆ isOpen()

bool xsens::Cmt1f::isOpen ( void  ) const
inline

Return whether the file is open or not.

◆ isReadOnly()

bool xsens::Cmt1f::isReadOnly ( void  ) const
inline

Return whether the file is readonly or not.

◆ open() [1/2]

XsensResultValue xsens::Cmt1f::open ( const char *  filename,
const bool  create,
const bool  readOnly 
)

Open a file.

Test:
does this work for non-existing files? Or do we need a check and create?

◆ open() [2/2]

XsensResultValue xsens::Cmt1f::open ( const wchar_t *  filename,
const bool  create,
const bool  readOnly 
)

Open a file using a unicode filename.

◆ readData() [1/2]

XsensResultValue xsens::Cmt1f::readData ( const uint32_t  maxLength,
void *  data,
uint32_t *  length 
)

Read data from the file and put it into the data buffer.

This function reads exactly the number of bytes as requested from the file.

Parameters
maxLengthThe amount of data that will be read.
dataPointer to a buffer that will store the read data.
lengthpointer to a variable that will store the number of bytes that were actually read. The parameter may be NULL.

◆ readData() [2/2]

XsensResultValue xsens::Cmt1f::readData ( const uint32_t  maxLength,
const char  terminator,
void *  data,
uint32_t *  length 
)

Read data from the file and put it into the data buffer.

This function reads upp to the number of bytes as requested from the file. The function will also stop if the given terminator character is encountered. The terminator is included in the output buffer.

Parameters
maxLengthThe amount of data that will be read.
dataPointer to a buffer that will store the read data.
terminatorA character that will end the read operation if encountered.
lengthThe actual number of bytes read, including the terminator character, if encountered.

◆ setReadPos()

XsensResultValue xsens::Cmt1f::setReadPos ( const XsensFilePos  pos)

Set the new absolute read position.

The read position is checked against the filesize before committing.

◆ setWritePos()

XsensResultValue xsens::Cmt1f::setWritePos ( const XsensFilePos  pos = -1)

Set the new absolute write position.

The write position is checked against the filesize before committing.

◆ writeData()

XsensResultValue xsens::Cmt1f::writeData ( const uint32_t  length,
const void *  data 
)

Write data to the file.

The function writes the given data to the file at the current write position.

Member Data Documentation

◆ m_filename

char xsens::Cmt1f::m_filename[CMT_MAX_FILENAME_LENGTH]
protected

Contains the name of the file that was last successfully opened.

◆ m_filename_w

wchar_t xsens::Cmt1f::m_filename_w[CMT_MAX_FILENAME_LENGTH]
protected

Contains the name of the file that was last successfully opened using unicode.

◆ m_fileSize

XsensFilePos xsens::Cmt1f::m_fileSize
protected

Contains the size of the file.

◆ m_handle

FILE* xsens::Cmt1f::m_handle
protected

The file handle.

◆ m_isOpen

bool xsens::Cmt1f::m_isOpen
protected

Indicates if the file is open or not.

◆ m_lastResult

XsensResultValue xsens::Cmt1f::m_lastResult
mutableprotected

The last result of an operation.

◆ m_reading

bool xsens::Cmt1f::m_reading
protected

Indicates whether the last operation was a read or write operation.

This value is used to check whether or not a seek is required to perform a requested read or write operation.

◆ m_readOnly

bool xsens::Cmt1f::m_readOnly
protected

Indicates if the file was opened in read-only mode.

◆ m_readPos

XsensFilePos xsens::Cmt1f::m_readPos
protected

The last read position in the file.

◆ m_unicode

bool xsens::Cmt1f::m_unicode
protected

Indicates if we're using the unicode filename or the regular filename.

◆ m_writePos

XsensFilePos xsens::Cmt1f::m_writePos
protected

The last write position in the file.


The documentation for this class was generated from the following files: