Main MRPT website > C++ reference for MRPT 1.5.9
List of all members | Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions
xsens::Cmt1f Class Reference

Detailed Description

The low-level file communication class.

Definition at line 204 of file cmt1.h.

#include <xSens_MT3/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 CmtFilePos start, const uint32_t length)
 Delete the given data from the file. More...
 
XsensResultValue find (const void *needle, const uint32_t needleLength, CmtFilePos &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...
 
CmtFilePos 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...
 
CmtFilePos getReadPos (void) const
 Return the current read position. More...
 
CmtFilePos getWritePos (void) const
 Return the current write position. More...
 
XsensResultValue insertData (const CmtFilePos 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 CmtFilePos pos)
 Set the new absolute read position. More...
 
XsensResultValue setWritePos (const CmtFilePos 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...
 
CmtFilePos m_fileSize
 Contains the size of the file. More...
 
CmtFilePos m_readPos
 The last read position in the file. More...
 
CmtFilePos 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...
 

Private Member Functions

 Cmt1f (const Cmt1f &ref)
 This object cannot be copied, so this function is not implemented. More...
 

Constructor & Destructor Documentation

◆ Cmt1f() [1/2]

xsens::Cmt1f::Cmt1f ( const Cmt1f ref)
private

This object cannot be copied, so this function is not implemented.

◆ Cmt1f() [2/2]

xsens::Cmt1f::Cmt1f ( )

Default constructor, initializes all members to their default values.

Definition at line 662 of file cmt1.cpp.

References m_filename, m_fileSize, m_isOpen, m_lastResult, m_reading, m_readOnly, m_readPos, m_unicode, m_writePos, and XRV_OK.

◆ ~Cmt1f()

xsens::Cmt1f::~Cmt1f ( )

Destructor.

Definition at line 677 of file cmt1.cpp.

References close().

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.

Definition at line 684 of file cmt1.cpp.

References FSEEK_R, FTELL, m_fileSize, m_handle, m_isOpen, m_lastResult, m_reading, m_readOnly, m_writePos, XRV_NOFILEOPEN, XRV_OK, and XRV_READONLY.

Referenced by xsens::Cmt2f::writeMessage().

◆ close()

XsensResultValue xsens::Cmt1f::close ( void  )

◆ closeAndDelete()

XsensResultValue xsens::Cmt1f::closeAndDelete ( void  )

◆ create() [1/2]

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

◆ create() [2/2]

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

◆ deleteData()

XsensResultValue xsens::Cmt1f::deleteData ( const CmtFilePos  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.

Definition at line 862 of file cmt1.cpp.

References FSEEK, gotoWrite(), m_fileSize, m_handle, m_isOpen, m_lastResult, m_readOnly, m_writePos, XRV_BUSY, XRV_ERROR, XRV_INVALIDINSTANCE, XRV_INVALIDPARAM, XRV_NOFILEOPEN, XRV_OK, XRV_OUTOFMEMORY, and XRV_READONLY.

Referenced by xsens::Cmt2f::create().

◆ find()

XsensResultValue xsens::Cmt1f::find ( const void needle,
const uint32_t  needleLength,
CmtFilePos 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.

Definition at line 938 of file cmt1.cpp.

References FSEEK, gotoRead(), m_handle, m_isOpen, m_lastResult, m_readPos, XRV_ENDOFFILE, XRV_NOFILEOPEN, and XRV_OK.

Referenced by xsens::Cmt2f::readMessage().

◆ 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.

Definition at line 997 of file cmt1.cpp.

References m_handle, m_lastResult, and XRV_OK.

◆ getFileSize()

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

Return the size of the file.

Definition at line 284 of file cmt1.h.

References m_fileSize.

Referenced by xsens::Cmt2f::getFileSize().

◆ getLastResult()

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

Return the result code of the last operation.

Definition at line 286 of file cmt1.h.

References m_lastResult.

◆ 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.

Definition at line 1006 of file cmt1.cpp.

References m_filename, m_lastResult, mrpt::system::os::strcpy(), and XRV_OK.

Referenced by xsens::Cmt2f::getName().

◆ 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.

Definition at line 1014 of file cmt1.cpp.

References CMT_MAX_FILENAME_LENGTH, m_filename, m_filename_w, m_lastResult, and XRV_OK.

◆ getReadPos()

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

Return the current read position.

Definition at line 300 of file cmt1.h.

References m_readPos.

Referenced by xsens::Cmt2f::getReadPosition().

◆ getWritePos()

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

Return the current write position.

Definition at line 302 of file cmt1.h.

References m_writePos.

◆ gotoRead()

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

Change from writing to reading mode.

Definition at line 1026 of file cmt1.cpp.

References FSEEK, m_reading, and m_readPos.

Referenced by find(), and readData().

◆ gotoWrite()

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

Change from reading to writing mode.

Definition at line 1037 of file cmt1.cpp.

References FSEEK, m_reading, and m_writePos.

Referenced by deleteData(), insertData(), and writeData().

◆ insertData()

XsensResultValue xsens::Cmt1f::insertData ( const CmtFilePos  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.

Definition at line 1048 of file cmt1.cpp.

References FSEEK, gotoWrite(), m_fileSize, m_handle, m_isOpen, m_lastResult, m_readOnly, m_writePos, XRV_NOFILEOPEN, XRV_OK, and XRV_READONLY.

◆ isOpen()

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

Return whether the file is open or not.

Definition at line 313 of file cmt1.h.

References m_isOpen.

Referenced by xsens::Cmt2f::close(), xsens::Cmt2f::closeAndDelete(), xsens::Cmt2f::create(), xsens::Cmt2f::isOpen(), and xsens::Cmt2f::open().

◆ isReadOnly()

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

Return whether the file is readonly or not.

Definition at line 315 of file cmt1.h.

References m_isOpen, and m_readOnly.

◆ open() [1/2]

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

◆ open() [2/2]

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

◆ 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.

Definition at line 1218 of file cmt1.cpp.

References gotoRead(), m_handle, m_isOpen, m_lastResult, m_readPos, XRV_ENDOFFILE, XRV_NOFILEOPEN, and XRV_OK.

Referenced by xsens::Cmt2f::readMessage().

◆ 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.

Definition at line 1242 of file cmt1.cpp.

References gotoRead(), m_handle, m_isOpen, m_lastResult, m_readPos, XRV_ENDOFFILE, XRV_NOFILEOPEN, and XRV_OK.

◆ setReadPos()

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

Set the new absolute read position.

The read position is checked against the filesize before committing.

Definition at line 1273 of file cmt1.cpp.

References FSEEK, m_isOpen, m_lastResult, m_reading, m_readPos, XRV_NOFILEOPEN, and XRV_OK.

Referenced by xsens::Cmt2f::readMessage(), and xsens::Cmt2f::setReadPosition().

◆ setWritePos()

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

Set the new absolute write position.

The write position is checked against the filesize before committing.

Definition at line 1290 of file cmt1.cpp.

References FSEEK, FSEEK_R, FTELL, m_isOpen, m_lastResult, m_reading, m_readOnly, m_writePos, XRV_NOFILEOPEN, XRV_OK, and XRV_READONLY.

◆ 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.

Definition at line 1319 of file cmt1.cpp.

References gotoWrite(), m_fileSize, m_handle, m_isOpen, m_lastResult, m_readOnly, m_writePos, XRV_NOFILEOPEN, XRV_OK, and XRV_READONLY.

Referenced by xsens::Cmt2f::create().

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.

Definition at line 221 of file cmt1.h.

Referenced by closeAndDelete(), Cmt1f(), create(), getName(), and open().

◆ 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.

Definition at line 223 of file cmt1.h.

Referenced by closeAndDelete(), create(), getName(), and open().

◆ m_fileSize

CmtFilePos xsens::Cmt1f::m_fileSize
protected

Contains the size of the file.

Definition at line 213 of file cmt1.h.

Referenced by appendData(), close(), closeAndDelete(), Cmt1f(), create(), deleteData(), getFileSize(), insertData(), open(), and writeData().

◆ m_handle

FILE* xsens::Cmt1f::m_handle
protected

The file handle.

Definition at line 211 of file cmt1.h.

Referenced by appendData(), close(), closeAndDelete(), create(), deleteData(), find(), flushData(), insertData(), open(), readData(), and writeData().

◆ m_isOpen

bool xsens::Cmt1f::m_isOpen
protected

Indicates if the file is open or not.

Definition at line 225 of file cmt1.h.

Referenced by appendData(), close(), closeAndDelete(), Cmt1f(), create(), deleteData(), find(), insertData(), isOpen(), isReadOnly(), open(), readData(), setReadPos(), setWritePos(), and writeData().

◆ m_lastResult

XsensResultValue xsens::Cmt1f::m_lastResult
mutableprotected

◆ 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.

Definition at line 233 of file cmt1.h.

Referenced by appendData(), close(), closeAndDelete(), Cmt1f(), create(), gotoRead(), gotoWrite(), open(), setReadPos(), and setWritePos().

◆ m_readOnly

bool xsens::Cmt1f::m_readOnly
protected

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

Definition at line 235 of file cmt1.h.

Referenced by appendData(), close(), closeAndDelete(), Cmt1f(), create(), deleteData(), insertData(), isReadOnly(), open(), setWritePos(), and writeData().

◆ m_readPos

CmtFilePos xsens::Cmt1f::m_readPos
protected

The last read position in the file.

Definition at line 215 of file cmt1.h.

Referenced by close(), closeAndDelete(), Cmt1f(), create(), find(), getReadPos(), gotoRead(), open(), readData(), and setReadPos().

◆ m_unicode

bool xsens::Cmt1f::m_unicode
protected

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

Definition at line 227 of file cmt1.h.

Referenced by closeAndDelete(), Cmt1f(), create(), and open().

◆ m_writePos

CmtFilePos xsens::Cmt1f::m_writePos
protected

The last write position in the file.

Definition at line 217 of file cmt1.h.

Referenced by appendData(), close(), closeAndDelete(), Cmt1f(), create(), deleteData(), getWritePos(), gotoWrite(), insertData(), open(), setWritePos(), and writeData().




Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020