ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
cloudViewer::utility::filesystem::CFile Class Reference

#include <FileSystem.h>

Public Member Functions

 ~CFile ()
 The destructor closes the file automatically. More...
 
bool Open (const std::string &filename, const std::string &mode)
 Open a file. More...
 
std::string GetError ()
 Returns the last encountered error for this file. More...
 
void Close ()
 Close the file. More...
 
int64_t CurPos ()
 Returns current position in the file (ftell). More...
 
int64_t GetFileSize ()
 Returns the file size in bytes. More...
 
int64_t GetNumLines ()
 Returns the number of lines in the file. More...
 
const char * ReadLine ()
 
template<class T >
size_t ReadData (T *data, size_t num_elems)
 
size_t ReadData (void *data, size_t elem_size, size_t num_elems)
 
FILE * GetFILE ()
 Returns the underlying C FILE pointer. More...
 

Detailed Description

RAII Wrapper for C FILE* Throws exceptions in situations where the caller is not usually going to have proper handling code:

  • using an unopened CFile
  • errors and ferror from underlying calls (fclose, ftell, fseek, fread, fwrite, fgetpos, fsetpos)
  • reading a line that is too long, caller is unlikely to have proper code to handle a partial next line If you would like to handle any of these issues by not having your code throw, use try/catch (const std::exception &e) { ... }

Definition at line 219 of file FileSystem.h.

Constructor & Destructor Documentation

◆ ~CFile()

cloudViewer::utility::filesystem::CFile::~CFile ( )

The destructor closes the file automatically.

Definition at line 737 of file FileSystem.cpp.

References Close().

Member Function Documentation

◆ Close()

void cloudViewer::utility::filesystem::CFile::Close ( )

Close the file.

Definition at line 750 of file FileSystem.cpp.

References GetError(), and LogError.

Referenced by Open(), and ~CFile().

◆ CurPos()

◆ GetError()

std::string cloudViewer::utility::filesystem::CFile::GetError ( )

◆ GetFILE()

◆ GetFileSize()

◆ GetNumLines()

int64_t cloudViewer::utility::filesystem::CFile::GetNumLines ( )

Returns the number of lines in the file.

Definition at line 793 of file FileSystem.cpp.

References GetError(), LogError, and SEEK_SET.

Referenced by cloudViewer::t::io::ReadPointCloudFromTXT(), and cloudViewer::t::io::ReadPointCloudFromXYZI().

◆ Open()

◆ ReadData() [1/2]

template<class T >
size_t cloudViewer::utility::filesystem::CFile::ReadData ( T *  data,
size_t  num_elems 
)
inline

Read data to a buffer.

Parameters
dataThe data buffer to be written into.
num_elementsNumber of elements to be read. The byte size of the element is determined by the size of buffer type.

Definition at line 253 of file FileSystem.h.

References data.

Referenced by cloudViewer::t::io::ReadPointCloudFromSPLAT().

◆ ReadData() [2/2]

size_t cloudViewer::utility::filesystem::CFile::ReadData ( void *  data,
size_t  elem_size,
size_t  num_elems 
)

Read data to a buffer.

Parameters
dataThe data buffer to be written into.
elem_sizeElement size in bytes.
num_elemsNumber of elements to read.

Definition at line 847 of file FileSystem.cpp.

References data, and LogError.

◆ ReadLine()

const char * cloudViewer::utility::filesystem::CFile::ReadLine ( )

Throws if we hit buffer maximum. In most cases, calling code is only capable of processing a complete line, if it receives a partial line it will probably fail and it is very likely to fail/corrupt on the next call that receives the remainder of the line.

Definition at line 820 of file FileSystem.cpp.

References DEFAULT_IO_BUFFER_SIZE, and LogError.

Referenced by cloudViewer::t::io::DepthNoiseSimulator::DepthNoiseSimulator(), cloudViewer::io::ReadPointCloudFromPTS(), cloudViewer::t::io::ReadPointCloudFromPTS(), cloudViewer::t::io::ReadPointCloudFromTXT(), cloudViewer::io::ReadPointCloudFromXYZ(), cloudViewer::t::io::ReadPointCloudFromXYZI(), cloudViewer::io::ReadPointCloudFromXYZN(), and cloudViewer::io::ReadPointCloudFromXYZRGB().


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