High level util for effective file reading and other file operations. More...
#include <SMESH_File.hxx>
Public Member Functions | |
| SMESH_File (const std::string &name, bool open=true) | |
| Creator opening the file for reading by default. | |
| ~SMESH_File () | |
| Destructor closing the file. | |
| std::string | getName () const |
| bool | open () |
| Open file for reading. | |
| void | close () |
| Close the file. | |
| bool | remove () |
| Remove the file. | |
| int | size () const |
| Return file size. | |
| operator const char * () const | |
| bool | operator++ () |
| void | operator+= (int posDelta) |
| bool | eof () const |
| const char * | getPos () const |
| void | setPos (const char *pos) |
| Set cursor to the given position. | |
| std::string | getLine () |
| Skip till current line end and return the skipped string. | |
| void | rewind () |
| Move cursor to the file beginning. | |
| bool | getInts (std::vector< int > &ids) |
| Fill vector by reading out integers from file. | |
Private Attributes | |
| std::string | _name |
| file name | |
| int | _size |
| file size | |
| int | _file |
| void * | _map |
| const char * | _pos |
| current position | |
| const char * | _end |
| position after file end | |
High level util for effective file reading and other file operations.
Definition at line 41 of file SMESH_File.hxx.
| SMESH_File::SMESH_File | ( | const std::string & | name, |
| bool | open = true |
||
| ) |
| SMESH_File::~SMESH_File | ( | ) |
Destructor closing the file.
Definition at line 60 of file SMESH_File.cxx.
References close().
{
close();
}
| void SMESH_File::close | ( | ) |
| bool SMESH_File.eof | ( | ) | const |
Fill vector by reading out integers from file.
Vector size gives number of integers to read
Definition at line 228 of file SMESH_File.cxx.
| std::string SMESH_File::getLine | ( | ) |
| std::string SMESH_File.getName | ( | ) | const |
Definition at line 49 of file SMESH_File.hxx.
{ return _name; }
| const char* SMESH_File.getPos | ( | ) | const |
Definition at line 71 of file SMESH_File.hxx.
{ return _pos; }
| bool SMESH_File::open | ( | ) |
Open file for reading.
Return true if there is something to read
Definition at line 71 of file SMESH_File.cxx.
References _end, _file, _map, _name, _pos, _size, close(), and size().
Referenced by size(), and SMESH_File().
{
int length = size();
if ( !_map && length > 0 )
{
#ifdef WNT
_file = CreateFile(_name.data(), GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
bool ok = ( _file != INVALID_HANDLE_VALUE );
#else
_file = ::open(_name.data(), O_RDONLY );
bool ok = ( _file > 0 );
#endif
if ( ok )
{
#ifdef WNT
_mapObj = CreateFileMapping(_file, NULL, PAGE_READONLY, 0, (DWORD)length, NULL);
_map = (void*) MapViewOfFile( _mapObj, FILE_MAP_READ, 0, 0, 0 );
#else
_map = ::mmap(0,length,PROT_READ,MAP_PRIVATE,_file,0);
if ( _map == MAP_FAILED ) _map = NULL;
#endif
if ( _map != NULL )
{
_size = length;
_pos = (char*) _map;
_end = _pos + _size;
}
else
{
#ifdef WNT
CloseHandle(_mapObj);
CloseHandle(_file);
#else
::close(_file);
#endif
}
}
}
return _pos;
}
| SMESH_File.operator const char * | ( | ) | const |
Definition at line 63 of file SMESH_File.hxx.
{ return _pos; }
| bool SMESH_File.operator++ | ( | ) |
Definition at line 65 of file SMESH_File.hxx.
| void SMESH_File.operator+= | ( | int | posDelta | ) |
Definition at line 67 of file SMESH_File.hxx.
{ _pos+=posDelta; }
| bool SMESH_File::remove | ( | ) |
Remove the file.
Definition at line 143 of file SMESH_File.cxx.
References _name, close(), SMESH_flight_skin.filePath, and MESSAGE.
| void SMESH_File::rewind | ( | ) |
| void SMESH_File::setPos | ( | const char * | pos | ) |
| int SMESH_File::size | ( | ) | const |
const char* SMESH_File._end [private] |
position after file end
Definition at line 92 of file SMESH_File.hxx.
int SMESH_File._file [private] |
Definition at line 88 of file SMESH_File.hxx.
void* SMESH_File._map [private] |
std::string SMESH_File._name [private] |
const char* SMESH_File._pos [private] |
int SMESH_File._size [private] |