MuseScore  3.4
Music composition and notation
imageStore.h
Go to the documentation of this file.
1 //=============================================================================
2 // MuseScore
3 // Music Composition & Notation
4 //
5 // Copyright (C) 2002-2011 Werner Schweer
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License version 2
9 // as published by the Free Software Foundation and appearing in
10 // the file LICENCE.GPL
11 //=============================================================================
12 
13 #ifndef __IMAGE_CACHE_H__
14 #define __IMAGE_CACHE_H__
15 
16 namespace Ms {
17 
18 class Image;
19 class Score;
20 
21 //---------------------------------------------------------
22 // ImageStoreItem
23 //---------------------------------------------------------
24 
26  QList<Image*> _references;
27  QString _path; // original location of image
28  QString _type; // image type (file extension)
29  QByteArray _buffer;
30  QByteArray _hash; // 16 byte md4 hash of _buffer
31 
32  public:
33  ImageStoreItem(const QString& p);
34  void dereference(Image*);
35  void reference(Image*);
36 
37  const QString& path() const { return _path; }
38  QByteArray& buffer() { return _buffer; }
39  const QByteArray& buffer() const { return _buffer; }
40  bool loaded() const { return !_buffer.isEmpty(); }
41  void setPath(const QString& val);
42  bool isUsed(Score*) const;
43  bool isUsed() const { return !_references.empty(); }
44  void load();
45  QString hashName() const;
46  const QByteArray& hash() const { return _hash; }
47  void set(const QByteArray& b, const QByteArray& h) { _buffer = b; _hash = h; }
48  };
49 
50 //---------------------------------------------------------
51 // ImageStore
52 //---------------------------------------------------------
53 
54 class ImageStore {
55  typedef std::vector<ImageStoreItem*> ItemList;
56  ItemList _items;
57 
58  public:
59  ImageStore() = default;
60  ImageStore(const ImageStore&) = delete;
61  ImageStore& operator=(const ImageStore&) = delete;
62  ~ImageStore();
63 
64  ImageStoreItem* getImage(const QString& path) const;
65  ImageStoreItem* add(const QString& path, const QByteArray&);
66  void clearUnused();
67 
68  typedef ItemList::iterator iterator;
69  typedef ItemList::const_iterator const_iterator;
70 
71  iterator begin() { return _items.begin(); }
72  const_iterator begin() const { return _items.begin(); }
73  iterator end() { return _items.end(); }
74  const_iterator end() const { return _items.end(); }
75  };
76 
77 extern ImageStore imageStore; // this is the global imageStore
78 
79 } // namespace Ms
80 #endif
81 
Definition: image.h:28
void dereference(Image *)
Definition: imageStore.cpp:36
const QByteArray & hash() const
Definition: imageStore.h:46
Definition: imageStore.h:54
QByteArray & buffer()
Definition: imageStore.h:38
iterator begin()
Definition: imageStore.h:71
iterator end()
Definition: imageStore.h:73
QString _path
Definition: imageStore.h:27
QString _type
Definition: imageStore.h:28
ImageStore imageStore
Definition: imageStore.cpp:20
Definition: score.h:391
ItemList _items
Definition: imageStore.h:56
bool loaded() const
Definition: imageStore.h:40
Definition: imageStore.h:25
ImageStoreItem(const QString &p)
Definition: imageStore.cpp:26
const QByteArray & buffer() const
Definition: imageStore.h:39
std::vector< ImageStoreItem * > ItemList
Definition: imageStore.h:55
QString hashName() const
Definition: imageStore.cpp:89
QList< Image * > _references
Definition: imageStore.h:26
Definition: aeolus.cpp:26
const_iterator end() const
Definition: imageStore.h:74
QByteArray _buffer
Definition: imageStore.h:29
void load()
Definition: imageStore.cpp:69
const_iterator begin() const
Definition: imageStore.h:72
void reference(Image *)
Definition: imageStore.cpp:46
bool isUsed() const
Definition: imageStore.h:43
QByteArray _hash
Definition: imageStore.h:30
void setPath(const QString &val)
Definition: imageStore.cpp:105
const QString & path() const
Definition: imageStore.h:37
ItemList::const_iterator const_iterator
Definition: imageStore.h:69
ItemList::iterator iterator
Definition: imageStore.h:68