gfx/graphite2/src/inc/SegCacheStore.h

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:161e44755771
1 /* GRAPHITE2 LICENSING
2
3 Copyright 2010, SIL International
4 All rights reserved.
5
6 This library is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 2.1 of License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should also have received a copy of the GNU Lesser General Public
17 License along with this library in the file named "LICENSE".
18 If not, write to the Free Software Foundation, 51 Franklin Street,
19 Suite 500, Boston, MA 02110-1335, USA or visit their web page on the
20 internet at http://www.fsf.org/licenses/lgpl.html.
21
22 Alternatively, the contents of this file may be used under the terms of the
23 Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public
24 License, as published by the Free Software Foundation, either version 2
25 of the License or (at your option) any later version.
26 */
27 #pragma once
28
29 #ifndef GRAPHITE2_NSEGCACHE
30
31 #include "inc/Main.h"
32 #include "inc/CmapCache.h"
33 #include "inc/SegCache.h"
34
35 namespace graphite2 {
36
37 class SegCache;
38 class Face;
39
40 class SilfSegCache
41 {
42 SilfSegCache(const SilfSegCache &);
43 SilfSegCache & operator = (const SilfSegCache &);
44
45 public:
46 SilfSegCache() : m_caches(NULL), m_cacheCount(0) {};
47 ~SilfSegCache()
48 {
49 assert(m_caches == NULL);
50 }
51 void clear(SegCacheStore * cacheStore)
52 {
53 for (size_t i = 0; i < m_cacheCount; i++)
54 {
55 m_caches[i]->clear(cacheStore);
56 delete m_caches[i];
57 }
58 free(m_caches);
59 m_caches = NULL;
60 m_cacheCount = 0;
61 }
62 SegCache * getOrCreate(SegCacheStore * cacheStore, const Features & features)
63 {
64 for (size_t i = 0; i < m_cacheCount; i++)
65 {
66 if (m_caches[i]->features() == features)
67 return m_caches[i];
68 }
69 SegCache ** newData = gralloc<SegCache*>(m_cacheCount+1);
70 if (newData)
71 {
72 if (m_cacheCount > 0)
73 {
74 memcpy(newData, m_caches, sizeof(SegCache*) * m_cacheCount);
75 free(m_caches);
76 }
77 m_caches = newData;
78 m_caches[m_cacheCount] = new SegCache(cacheStore, features);
79 m_cacheCount++;
80 return m_caches[m_cacheCount - 1];
81 }
82 return NULL;
83 }
84 CLASS_NEW_DELETE
85 private:
86 SegCache ** m_caches;
87 size_t m_cacheCount;
88 };
89
90 class SegCacheStore
91 {
92 SegCacheStore(const SegCacheStore &);
93 SegCacheStore & operator = (const SegCacheStore &);
94
95 public:
96 SegCacheStore(const Face & face, unsigned int numSilf, size_t maxSegments);
97 ~SegCacheStore()
98 {
99 for (size_t i = 0; i < m_numSilf; i++)
100 {
101 m_caches[i].clear(this);
102 }
103 delete [] m_caches;
104 m_caches = NULL;
105 }
106 SegCache * getOrCreate(unsigned int i, const Features & features)
107 {
108 return m_caches[i].getOrCreate(this, features);
109 }
110 bool isSpaceGlyph(uint16 gid) const { return (gid == m_spaceGid) || (gid == m_zwspGid); }
111 uint16 maxCmapGid() const { return m_maxCmapGid; }
112 uint32 maxSegmentCount() const { return m_maxSegments; };
113
114 CLASS_NEW_DELETE
115 private:
116 SilfSegCache * m_caches;
117 uint8 m_numSilf;
118 uint32 m_maxSegments;
119 uint16 m_maxCmapGid;
120 uint16 m_spaceGid;
121 uint16 m_zwspGid;
122 };
123
124 } // namespace graphite2
125
126 #endif
127

mercurial