Qt 4.8
Classes | Macros | Typedefs | Functions
qresource.cpp File Reference
#include "qresource.h"
#include "qresource_p.h"
#include "qresource_iterator_p.h"
#include "qset.h"
#include "qhash.h"
#include "qmutex.h"
#include "qdebug.h"
#include "qlocale.h"
#include "qglobal.h"
#include "qvector.h"
#include "qdatetime.h"
#include "qbytearray.h"
#include "qstringlist.h"
#include <qshareddata.h>
#include <qplatformdefs.h>
#include "private/qabstractfileengine_p.h"
#include "private/qcore_unix_p.h"
#include <sys/mman.h>
#include <errno.h>

Go to the source code of this file.

Classes

class  QDynamicBufferResourceRoot
 
class  QDynamicFileResourceRoot
 
class  QResourceFileEnginePrivate
 
class  QResourcePrivate
 
class  QResourceRoot
 
class  QStringSplitter
 

Macros

#define MAP_FAILED   -1
 
#define MAP_FILE   0
 
#define QT_USE_MMAP
 

Typedefs

typedef QList< QResourceRoot * > ResourceList
 

Functions

static QString cleanPath (const QString &_path)
 
 Q_DECLARE_TYPEINFO (QResourceRoot, Q_MOVABLE_TYPE)
 
Q_CORE_EXPORT void qInitResourceIO ()
 
Q_CORE_EXPORT bool qRegisterResourceData (int version, const unsigned char *tree, const unsigned char *name, const unsigned char *data)
 
static QString qt_resource_fixResourceRoot (QString r)
 
Q_CORE_EXPORT bool qUnregisterResourceData (int version, const unsigned char *tree, const unsigned char *name, const unsigned char *data)
 

Macro Definition Documentation

◆ MAP_FAILED

#define MAP_FAILED   -1

◆ MAP_FILE

#define MAP_FILE   0

◆ QT_USE_MMAP

#define QT_USE_MMAP

Definition at line 944 of file qresource.cpp.

Typedef Documentation

◆ ResourceList

Definition at line 162 of file qresource.cpp.

Function Documentation

◆ cleanPath()

static QString cleanPath ( const QString _path)
static

Definition at line 148 of file qresource.cpp.

Referenced by QResourcePrivate::ensureChildren(), QResourcePrivate::load(), and QDir::temp().

149 {
150  QString path = QDir::cleanPath(_path);
151  // QDir::cleanPath does not remove two trailing slashes under _Windows_
152  // due to support for UNC paths. Remove those manually.
153  if (path.startsWith(QLatin1String("//")))
154  path.remove(0, 1);
155  return path;
156 }
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
static QString cleanPath(const QString &path)
Removes all multiple directory separators "/" and resolves any "."s or ".."s found in the path...
Definition: qdir.cpp:2082
QString & remove(int i, int len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
Definition: qstring.cpp:1867

◆ Q_DECLARE_TYPEINFO()

Q_DECLARE_TYPEINFO ( QResourceRoot  ,
Q_MOVABLE_TYPE   
)

Referenced by cleanPath().

◆ qInitResourceIO()

Q_CORE_EXPORT void qInitResourceIO ( )

Definition at line 1512 of file qresource.cpp.

1512 { } // ### Qt 5: remove

◆ qRegisterResourceData()

Q_CORE_EXPORT bool qRegisterResourceData ( int  version,
const unsigned char *  tree,
const unsigned char *  name,
const unsigned char *  data 
)

Definition at line 850 of file qresource.cpp.

852 {
853  QMutexLocker lock(resourceMutex());
854  if(version == 0x01 && resourceList()) {
855  bool found = false;
856  QResourceRoot res(tree, name, data);
857  for(int i = 0; i < resourceList()->size(); ++i) {
858  if(*resourceList()->at(i) == res) {
859  found = true;
860  break;
861  }
862  }
863  if(!found) {
864  QResourceRoot *root = new QResourceRoot(tree, name, data);
865  root->ref.ref();
866  resourceList()->append(root);
867  }
868  return true;
869  }
870  return false;
871 }
bool ref()
Atomically increments the value of this QAtomicInt.
const char * name
static const char * data(const QByteArray &arr)
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QAtomicInt ref
Definition: qresource.cpp:121

◆ qt_resource_fixResourceRoot()

static QString qt_resource_fixResourceRoot ( QString  r)
static

Definition at line 1052 of file qresource.cpp.

Referenced by QResource::registerResource(), and QResource::unregisterResource().

1052  {
1053  if(!r.isEmpty()) {
1054  if(r.startsWith(QLatin1Char(':')))
1055  r = r.mid(1);
1056  if(!r.isEmpty())
1057  r = QDir::cleanPath(r);
1058  }
1059  return r;
1060 }
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
static QString cleanPath(const QString &path)
Removes all multiple directory separators "/" and resolves any "."s or ".."s found in the path...
Definition: qdir.cpp:2082
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ qUnregisterResourceData()

Q_CORE_EXPORT bool qUnregisterResourceData ( int  version,
const unsigned char *  tree,
const unsigned char *  name,
const unsigned char *  data 
)

Definition at line 873 of file qresource.cpp.

875 {
876  QMutexLocker lock(resourceMutex());
877  if(version == 0x01 && resourceList()) {
878  QResourceRoot res(tree, name, data);
879  for(int i = 0; i < resourceList()->size(); ) {
880  if(*resourceList()->at(i) == res) {
881  QResourceRoot *root = resourceList()->takeAt(i);
882  if(!root->ref.deref())
883  delete root;
884  } else {
885  ++i;
886  }
887  }
888  return true;
889  }
890  return false;
891 }
const char * name
bool deref()
Atomically decrements the value of this QAtomicInt.
static const char * data(const QByteArray &arr)
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QAtomicInt ref
Definition: qresource.cpp:121