Source: fun/ResourceFinder.h
|
|
|
|
// ResourceFinder.h
#ifndef RESOURCEFINDER_H
#define RESOURCEFINDER_H
#include
#include
#include
/**********************************************************************
ResourceFinder - an object for searching through filesystem paths.
** Copyright (C) 2002 stephan beal (sgbeal@users.sourceforge.net).
** All rights reserved.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
**********************************************************************/
namespace fun {
class ResourceFinder
{
public:
typedef QMap QStringStringMap;
/**
calls finder.addPath( path );
*/
friend QString operator += (ResourceFinder &finder, const QString &path);
/**
Creates object with the given path/extension list.
*/
ResourceFinder( QString path = QString(), QString ext = QString(), QString pathsep = QString(":") );
virtual ~ResourceFinder() {};
/**
Returns a ":"-separated string of all paths added via add/setPath().
*/
virtual QString getPath();
/**
Sets the path to p. It may be a ":"-delimited string.
*/
virtual void setPath( QString p );
/**
Adds p to our path. May be ":"-delimited
*/
virtual void addPath( QString p );
void setPathSeparator( QString pathsep ) { this->pathseparator = pathsep; };
QString getPathSeparator() const { return this->pathseparator; };
/**
Adds a "search extension." Sample:
finder.addExtension( ".txt:README" );
Will now try all path combinations with the rightmost characters
matching ext. Be sure to include a period if you want that searched.
*/
virtual void addExtension( QString ext );
/**
like addExtension(), but overwrites extension list.
*/
virtual void setExtensions( QString ext );
/**
Returns the ":"-delimited listed of file extensions to search.
*/
virtual QString getExtensions();
/**
Returns the full path of the given resource, provided it could be found
in all paths or with all extensions added.
Note that this might return a relative path.
*/
QString find( QString resourcename );
protected:
/**
returns the "hit cache" - those items found by find().
*/
ResourceFinder::QStringStringMap & hitCache();
QString cached( QString key );
private:
QStringList paths;
QStringList exts;
static const QString m_not_found;
// QString path;
// QString exts;
QString pathseparator;
QStringStringMap m_hitcache;
};
} // namespace fun
#endif // RESOURCEFINDER_H
| Generated by: stephan on cheyenne on Mon Aug 11 14:06:52 2003, using kdoc 2.0a54. |