Fix code to not include std set directly
[platform/core/uifw/dali-core.git] / dali / internal / event / text / glyph-status / glyph-status-container.h
1 #ifndef __DALI_INTERNAL_GLYPH_STATUS_CONTAINER_H__
2 #define __DALI_INTERNAL_GLYPH_STATUS_CONTAINER_H__
3
4 //
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 //
7 // Licensed under the Flora License, Version 1.0 (the License);
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 //     http://floralicense.org/license/
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an AS IS BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 //
19
20 // INTERNAL INCLUDES
21 #include <dali/public-api/common/set-wrapper.h>
22 #include <dali/internal/event/text/glyph-status/glyph-status.h>
23 #include <dali/internal/common/text-array.h>
24
25 namespace Dali
26 {
27
28 namespace Internal
29 {
30
31 /**
32  *
33  * Maintains a set of reference counted characters (glyph status objects).
34  * The glyph status objects are sorted by character code and font id.
35  *
36  * The class provides an API for inserting glyph status objects into
37  * the container and increasing / decreasing their reference count.
38  *
39  * Once a glyph status object reaches a ref count = 0, it remains in
40  * the container, but a pointer to it is added to the mDeadCharacters list.
41  * The dead character list is sorted by dead time.
42  *
43  * If new glyph objects are inserted when the container is full,
44  * dead characters (ref = 0) are replaced, starting with the oldest first.
45  *
46  * To see what is happening on the console, enable DEBUG_GLYPH_STATUS_CONTAINER in
47  * glyph-status-container-debug.h
48  *
49  */
50 class GlyphStatusContainer
51 {
52
53 public:
54
55   /**
56    * Constructor
57    * @param numberOfCharacters how many characters the container should hold
58    */
59   GlyphStatusContainer( unsigned int numberOfCharacters );
60
61   /**
62    * destructor, non-virtual not intended as a base class.
63    */
64   ~GlyphStatusContainer();
65
66   /**
67    * Increase the reference count of a character
68    * @param[in] character code
69    * @param[in] font id
70    */
71   void IncreaseRefCount( uint32_t charCode, FontId fontId);
72
73   /**
74    * @param[in] charCode character code
75    * @param[in] fontId font id
76    */
77   void DecreaseRefCount( uint32_t charCode, FontId fontId);
78
79   /**
80    * enum to represent the result of a character insertion.
81    */
82   enum InsertResult
83   {
84     INSERTED_OK,            ///< character was inserted in to an empty space
85     REPLACE_DEAD_CHARACTER, ///< character replaced a cached dead character.
86   };
87
88   /**
89    * Insert a new character in to the container
90    * @param[in] charCode character code
91    * @param[in] fontId font id
92    * @param[out] deadUniqueId the id of a dead character, if one was replaced
93    * @return insertion result
94    */
95   InsertResult InsertNewCharacter( uint32_t charCode, FontId fontId, unsigned int& deadUniqueId );
96
97   /**
98    * Find the glyph status object given a character code and font id
99    * @param[in] charCode character code
100    * @param[in] fontId font id
101    * @return glyph status object if it exists, NULL if it doesn't
102    */
103   const GlyphStatus* FindGlyphStatus( uint32_t charCode, FontId fontId) const;
104
105   /**
106    * Return a reference to a glyph status object given a character code and font id
107    * @param[in] charCode character code
108    * @param[in] fontId font id
109    * @return glyph status object
110    */
111   const GlyphStatus& GetStatus( uint32_t charCode, FontId fontId) const;
112
113   /**
114    * Status set typedef. Uses a custom sort function to sort by character code and font id
115    */
116   typedef std::set< GlyphStatus, GlyphStatus::Comparator > StatusSet;
117
118   /**
119    * Get the glyph status set
120    * @todo find a better solution than allowing direct access to the set
121    * @return the glyph status set
122    */
123   const StatusSet& GetStatusSet() const;
124
125   /**
126    * Check if all characters in a text array are marked as loaded
127    * @param[in] text the text array
128    * @param[in] fontId font id
129    * @return true if all characters are loaded false if not
130    */
131   bool IsTextLoaded( const TextArray& text, FontId fontId) const;
132
133   /**
134    * Given a text array, find how many character are loaded and
135    * whether it will fit in to the container.
136    * @param[in] text the text array
137    * @param[in] fontId font id
138    * @param[out] charsNotLoaded how many characters are not loaded
139    * @param[out] fitsInContainer whether the text fits in the container
140    */
141   void GetTextStatus( const TextArray& text,
142                       FontId fontId,
143                       unsigned int& charsNotLoaded,
144                       bool& fitsInContainer ) const;
145
146   /**
147    * Clone the contents of one container, into this container
148    * @param[in] clone the container to clone
149    */
150   void CloneContents( const GlyphStatusContainer& clone );
151
152   /**
153    * Get the list of dead characters
154    * @param[out] deadList to be filled with a list of dead characters
155    */
156   void GetDeadCharacters( std::vector< unsigned int >& deadList );
157
158   /**
159    * Clear dead characters.
160    */
161   void ClearDeadCharacters();
162
163   /**
164    * Check if the container is empty
165    * @return true if container is empty
166    */
167   bool Empty() const;
168
169   /**
170    * @return the container size
171    */
172   unsigned int GetSize() const;
173
174   /**
175    * Clear the container contents.
176    */
177   void ClearContents();
178
179 private:
180
181   /**
182    * Add a character to the dead character list
183    * @param[in] deadCharacter dead character
184    */
185   void AddDeadCharacter( const GlyphStatus* deadCharacter);
186
187   /**
188    * Remove a character from the dead character list.
189    * This happens if a characters reference count goes from 0 -> 1.
190    * @param[in] deadCharacter dead character
191    */
192   void RemoveDeadCharacter( const GlyphStatus* deadCharacter );
193
194   /**
195    * Remove the oldest dead character
196    * @return oldest dead character
197    */
198   const GlyphStatus* RemoveOldestDeadCharacter( );
199
200   /**
201    * Insert a character in to the lookup
202    * @param[in] charCode character code
203    * @param[in] fontId font id
204    */
205   void InsertCharacterIntoLookup(uint32_t charCode, FontId fontId );
206
207   /**
208    * Reset the dead time stamps of all glyph objects in the
209    * dead character list. This is called when mTimeStamp value reaches
210    * GlyphStatus::GetMaximumDeadTime()
211    */
212   void ResetTimeStamps();
213
214   /**
215    * Get the total available space in the container.
216    * This is empty space + space used by dead characters that can be replaced
217    * @return total space
218    */
219   unsigned int TotalAvailableSpace() const;
220
221   unsigned int mContainerSize;  ///< container size
222   unsigned int mEmptySpace;     ///< amount of space that is empty (has never been used)
223
224   /**
225    * Status pointer set typedef, sorted by custom function
226    */
227   typedef std::set< const GlyphStatus*, GlyphStatus::PointerComparator > StatusPointerSet;
228
229   StatusSet                   mCharacterLookup;       ///< set of glyph status objects sorted by font id and character code
230   StatusPointerSet            mDeadCharacters;        ///< set of characters with a ref count of zero, which are still cached.
231   unsigned int                mTimeStamp;             ///< current time stamp
232
233 };
234
235
236 } // namespace Internal
237
238 } // namespace Dali
239
240 #endif // __DALI_INTERNAL_GLYPH_STATUS_CONTAINER_H__