Qt 4.8
Public Functions | Properties | List of all members
QDynamicFileResourceRoot Class Reference
Inheritance diagram for QDynamicFileResourceRoot:
QDynamicBufferResourceRoot QResourceRoot

Public Functions

QString mappingFile () const
 
 QDynamicFileResourceRoot (const QString &_root)
 
bool registerSelf (const QString &f)
 
virtual ResourceRootType type () const
 
 ~QDynamicFileResourceRoot ()
 
- Public Functions inherited from QDynamicBufferResourceRoot
const ucharmappingBuffer () const
 
virtual QString mappingRoot () const
 
 QDynamicBufferResourceRoot (const QString &_root)
 
bool registerSelf (const uchar *b)
 
 ~QDynamicBufferResourceRoot ()
 
- Public Functions inherited from QResourceRoot
QStringList children (int node) const
 
const uchardata (int node, qint64 *size) const
 
int findNode (const QString &path, const QLocale &locale=QLocale()) const
 
bool isCompressed (int node) const
 
bool isContainer (int node) const
 
bool mappingRootSubdir (const QString &path, QString *match=0) const
 
bool operator!= (const QResourceRoot &other) const
 
bool operator== (const QResourceRoot &other) const
 
 QResourceRoot ()
 
 QResourceRoot (const uchar *t, const uchar *n, const uchar *d)
 
virtual ~QResourceRoot ()
 

Properties

QString fileName
 
unsigned int unmapLength
 
ucharunmapPointer
 

Additional Inherited Members

- Public Types inherited from QResourceRoot
enum  ResourceRootType { Resource_Builtin, Resource_File, Resource_Buffer }
 
- Public Variables inherited from QResourceRoot
QAtomicInt ref
 
- Protected Functions inherited from QResourceRoot
void setSource (const uchar *t, const uchar *n, const uchar *d)
 

Detailed Description

Definition at line 959 of file qresource.cpp.

Constructors and Destructors

◆ QDynamicFileResourceRoot()

QDynamicFileResourceRoot::QDynamicFileResourceRoot ( const QString _root)
inline

Definition at line 967 of file qresource.cpp.

unsigned int unmapLength
Definition: qresource.cpp:964
QDynamicBufferResourceRoot(const QString &_root)
Definition: qresource.cpp:901

◆ ~QDynamicFileResourceRoot()

QDynamicFileResourceRoot::~QDynamicFileResourceRoot ( )
inline

Definition at line 968 of file qresource.cpp.

968  {
969 #if defined(QT_USE_MMAP)
970  if (unmapPointer) {
971  munmap((char*)unmapPointer, unmapLength);
972  unmapPointer = 0;
973  unmapLength = 0;
974  } else
975 #endif
976  {
977  delete [] (uchar *)mappingBuffer();
978  }
979  }
unsigned int unmapLength
Definition: qresource.cpp:964
unsigned char uchar
Definition: qglobal.h:994
const uchar * mappingBuffer() const
Definition: qresource.cpp:903

Functions

◆ mappingFile()

QString QDynamicFileResourceRoot::mappingFile ( ) const
inline

Definition at line 980 of file qresource.cpp.

Referenced by QResource::unregisterResource().

980 { return fileName; }

◆ registerSelf()

bool QDynamicFileResourceRoot::registerSelf ( const QString f)
inline

Definition at line 983 of file qresource.cpp.

Referenced by QResource::registerResource().

983  {
984  bool fromMM = false;
985  uchar *data = 0;
986  unsigned int data_len = 0;
987 
988 #ifdef QT_USE_MMAP
989 
990 #ifndef MAP_FILE
991 #define MAP_FILE 0
992 #endif
993 #ifndef MAP_FAILED
994 #define MAP_FAILED -1
995 #endif
996 
997  int fd = QT_OPEN(QFile::encodeName(f), O_RDONLY,
998 #if defined(Q_OS_WIN)
1000 #else
1001  0666
1002 #endif
1003  );
1004  if (fd >= 0) {
1005  QT_STATBUF st;
1006  if (!QT_FSTAT(fd, &st)) {
1007  uchar *ptr;
1008  ptr = reinterpret_cast<uchar *>(
1009  mmap(0, st.st_size, // any address, whole file
1010  PROT_READ, // read-only memory
1011  MAP_FILE | MAP_PRIVATE, // swap-backed map from file
1012  fd, 0)); // from offset 0 of fd
1013  if (ptr && ptr != reinterpret_cast<uchar *>(MAP_FAILED)) {
1014  data = ptr;
1015  data_len = st.st_size;
1016  fromMM = true;
1017  }
1018  }
1019  ::close(fd);
1020  }
1021 #endif // QT_USE_MMAP
1022  if(!data) {
1023  QFile file(f);
1024  if (!file.exists())
1025  return false;
1026  data_len = file.size();
1027  data = new uchar[data_len];
1028 
1029  bool ok = false;
1030  if (file.open(QIODevice::ReadOnly))
1031  ok = (data_len == (uint)file.read((char*)data, data_len));
1032  if (!ok) {
1033  delete [] data;
1034  data = 0;
1035  data_len = 0;
1036  return false;
1037  }
1038  fromMM = false;
1039  }
1040  if(data && QDynamicBufferResourceRoot::registerSelf(data)) {
1041  if(fromMM) {
1042  unmapPointer = data;
1043  unmapLength = data_len;
1044  }
1045  fileName = f;
1046  return true;
1047  }
1048  return false;
1049  }
#define _S_IREAD
const uchar * data(int node, qint64 *size) const
Definition: qresource.cpp:781
#define MAP_FAILED
#define O_RDONLY
unsigned int unmapLength
Definition: qresource.cpp:964
unsigned char uchar
Definition: qglobal.h:994
unsigned int uint
Definition: qglobal.h:996
const T * ptr(const T &t)
#define MAP_FILE
bool registerSelf(const uchar *b)
Definition: qresource.cpp:907
#define QT_OPEN
Definition: qcore_unix_p.h:186
The QFile class provides an interface for reading from and writing to files.
Definition: qfile.h:65
#define st(var, type, card)
#define Q_OS_WIN
Definition: qglobal.h:270
static QByteArray encodeName(const QString &fileName)
By default, this function converts fileName to the local 8-bit encoding determined by the user&#39;s loca...
Definition: qfile.cpp:528
#define _S_IWRITE

◆ type()

virtual ResourceRootType QDynamicFileResourceRoot::type ( ) const
inlinevirtual

Reimplemented from QDynamicBufferResourceRoot.

Definition at line 981 of file qresource.cpp.

Properties

◆ fileName

QString QDynamicFileResourceRoot::fileName
private

Definition at line 961 of file qresource.cpp.

◆ unmapLength

unsigned int QDynamicFileResourceRoot::unmapLength
private

Definition at line 964 of file qresource.cpp.

◆ unmapPointer

uchar* QDynamicFileResourceRoot::unmapPointer
private

Definition at line 963 of file qresource.cpp.


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