cache.h 2 KB
Newer Older
1
/***************************************************************************
2
                          cache.h  -  description
3
                             -------------------
4
    begin                : Sat Sep 7 2002
5
    copyright            : (C) 2002 by Scott Wheeler
6
    email                : wheeler@kde.org
7
 ***************************************************************************/
8 9 10 11 12 13 14 15 16 17

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

18 19
#ifndef CACHE_H
#define CACHE_H
20

21 22 23
#include <qdatastream.h>

#include "stringhash.h"
24

25
class Tag;
26 27 28 29
class Playlist;
class PlaylistCollection;

typedef QValueList<Playlist *> PlaylistList;
30

31
class Cache : public FileHandleHash
32
{
33
public:
34
    static Cache *instance();
35
    void save();
36

37 38 39
    static void loadPlaylists(PlaylistCollection *collection);
    static void savePlaylists(const PlaylistList &playlists);

40 41
protected:
    Cache();
42
    void load();
43

44
private:
45
    static Cache *m_cache;
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
    static const int m_currentVersion = 1;
};

/**
 * A simple QDataStream subclass that has an extra field to indicate the cache
 * version.
 */

class CacheDataStream : public QDataStream
{
public:
    CacheDataStream(QIODevice *d) : QDataStream(d), m_cacheVersion(0) {}
    CacheDataStream(QByteArray a, int mode) : QDataStream(a, mode), m_cacheVersion(0) {}

    virtual ~CacheDataStream() {}

    int cacheVersion() const { return m_cacheVersion; }
    void setCacheVersion(int v) { m_cacheVersion = v; }
    
private:
    int m_cacheVersion;
67 68 69
};

#endif