summaryrefslogtreecommitdiff
path: root/glcdskin/cache.h
blob: 3862b51bc958fee538069c729110a7963dae7e3d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
 * GraphLCD skin library
 *
 * cache.h  -  image cache
 *
 * This file is released under the GNU General Public License. Refer
 * to the COPYING file distributed with this package.
 *
 */

#ifndef _GLCDSKIN_CACHE_H_
#define _GLCDSKIN_CACHE_H_

#include <stdint.h>

#include <string>
#include <vector>

#include <glcdgraphics/image.h>

namespace GLCD
{

class cSkin;

class cImageItem
{
private:
    std::string path;
    uint64_t counter;
    cImage * image;
public:
    cImageItem(const std::string & path, cImage * image);
    ~cImageItem();

    const std::string & Path() const { return path; }
    uint64_t Counter() const { return counter; }
    cImage * Image() { return image; }
    void ResetCounter() { counter = 0; }
    void IncCounter() { counter += 1; }
};

class cImageCache
{
private:
    cSkin * skin;
    size_t size;
    std::vector <cImageItem *> images;
    std::vector <std::string> failedpaths;

    cImageItem * LoadImage(const std::string & path);
public:
    cImageCache(cSkin * Parent, int Size);
    ~cImageCache();

    cImage * Get(const std::string & path);
};

} // end of namespace

#endif