ISIS Core Library 0.7.2 (api 3.0.0)
Data Structures | Public Member Functions

isis::data::FilePtr Class Reference

Class to map files into memory. More...

#include <fileptr.hpp>

Inheritance diagram for isis::data::FilePtr:
isis::data::ValueArray< uint8_t > isis::data::ValueArrayBase isis::util::_internal::GenericValue

Data Structures

struct  Closer
struct  GeneratorMap

Public Member Functions

template<typename T >
ValueArray< T > at (size_t offset, size_t len=0, bool swap_endianess=false)
 Get a ValueArray representing the data in the file.
data::ValueArrayReference atByID (unsigned short ID, size_t offset, size_t len=0, bool swap_endianess=false)
 Get a ValueArrayReference to a ValueArray of the requested type.
 FilePtr (const boost::filesystem::path &filename, size_t len=0, bool write=false)
 Create a FilePtr, mapping the given file.
 FilePtr ()
 empty creator - result will not be usefull until filled
bool good ()
void release ()

Detailed Description

Class to map files into memory.

This can be used read only, or for read/write.

Writing to a FilePtr mapping a file read-only is valid. It will not change the mapped file.

This is inherting from ValueArray. Thus this, and all ValueArray created from it will be managed. The mapped file will automatically unmapped and closed after all pointers a deleted.

Definition at line 38 of file fileptr.hpp.


Constructor & Destructor Documentation

isis::data::FilePtr::FilePtr ( )

empty creator - result will not be usefull until filled

Definition at line 169 of file fileptr.cpp.

isis::data::FilePtr::FilePtr ( const boost::filesystem::path &  filename,
size_t  len = 0,
bool  write = false 
)

Create a FilePtr, mapping the given file.

if the write is true:

  • the file will be created if it does not exist
  • the file will be resized to len if it is shorter than len
  • a resize after this creation is NOT possible

if write is false:

  • the length of the pointer will become the size of the file if len is 0 (so the whole file will be mapped)
  • if len is not 0 but less then the filesize, only len bytes of the file will be mapped

creation will fail (good()!=true afterwards) if:

  • open/mmap fail on the given file for any reason
  • if file does not exist, write is true and len is 0
  • if write is false and len is greater then the length of the file or the file does not exist
Parameters:
filenamethe file to map into memory
lenthe requested length of the resulting ValueArray in bytes (automatically set if 0)
writethe file be opened for writing (writing to the mapped memory will write to the file, otherwise it will cause a copy-on-write)

Definition at line 172 of file fileptr.cpp.


Member Function Documentation

template<typename T >
ValueArray<T> isis::data::FilePtr::at ( size_t  offset,
size_t  len = 0,
bool  swap_endianess = false 
) [inline]

Get a ValueArray representing the data in the file.

The resulting ValueArray will use a proxy deleter to keep track of the mapped file. So the file will be unmapped and closed if, and only if all ValueArray created by this function and the FilePtr are closed.

If the FilePtr was opened writing, writing access to this ValueArray objects will result in writes to the file. Otherwise it will just write into memory.

Note that there is no conversion done, just reinterpretation of the raw data in the file.

Parameters:
offsetthe position in the file to start from (in bytes)
lenthe requested length of the resulting ValueArray in elements (if that will go behind the end of the file, a warning will be issued).
swap_endianessif endianess should be swapped when reading data file (ignored when used on files opened for writing)

Definition at line 103 of file fileptr.hpp.

ValueArrayReference isis::data::FilePtr::atByID ( unsigned short  ID,
size_t  offset,
size_t  len = 0,
bool  swap_endianess = false 
)

Get a ValueArrayReference to a ValueArray of the requested type.

The resulting ValueArray will use a proxy deleter to keep track of the mapped file. So the file will be unmapped and closed if, and only if all ValueArray created by this function and the FilePtr are closed.

If the FilePtr was opened writing, writing access to this ValueArray objects will result in writes to the file. Otherwise it will just write into memory.

If the FilePtr was opened reading and the assumed endianess of the file (see parameter) does not fit the endianess of the system an (endianess-converted) deep copy is created.

Parameters:
IDthe requested type (note that there is no conversion done, just reinterpretation of the raw data in the file)
offsetthe position in the file to start from (in bytes)
lenthe requested length of the resulting ValueArray in elements (if that will go behind the end of the file, a warning will be issued).
swap_endianessif endianess should be swapped when reading data file (ignored when used on files opened for writing)

Definition at line 214 of file fileptr.cpp.

bool isis::data::FilePtr::good ( )

Definition at line 206 of file fileptr.cpp.

void isis::data::FilePtr::release ( )

Definition at line 208 of file fileptr.cpp.


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