13 |
13 |
14 /** |
14 /** |
15 * Class that creates a linked list which can keep item/value pairs. |
15 * Class that creates a linked list which can keep item/value pairs. |
16 */ |
16 */ |
17 class AIAbstractList : public AIObject { |
17 class AIAbstractList : public AIObject { |
|
18 public: |
|
19 /** Type of sorter */ |
|
20 enum SorterType { |
|
21 SORT_BY_VALUE = 0, |
|
22 SORT_BY_ITEM = 1, |
|
23 }; |
|
24 |
18 private: |
25 private: |
19 AIAbstractListSorter *sorter; |
26 AIAbstractListSorter *sorter; |
|
27 SorterType sorter_type; |
|
28 bool sort_ascending; |
20 |
29 |
21 public: |
30 public: |
22 typedef std::set<int32> AIItemList; ///< The list of items inside the bucket |
31 typedef std::set<int32> AIItemList; ///< The list of items inside the bucket |
23 typedef std::map<int32, AIItemList> AIAbstractListBucket; ///< The bucket list per value |
32 typedef std::map<int32, AIItemList> AIAbstractListBucket; ///< The bucket list per value |
24 typedef std::map<int32, int32> AIAbstractListMap; ///< List per item |
33 typedef std::map<int32, int32> AIAbstractListMap; ///< List per item |
114 * @return true if we could set the item to value, false otherwise. |
123 * @return true if we could set the item to value, false otherwise. |
115 */ |
124 */ |
116 bool SetValue(int32 item, int32 value); |
125 bool SetValue(int32 item, int32 value); |
117 |
126 |
118 /** |
127 /** |
119 * Sort this list by item-value. |
128 * Sort this list by the given sorter and direction. |
|
129 * @param sorter the type of sorter to use |
120 * @param ascending if true, lowest value is on top, else at bottom. |
130 * @param ascending if true, lowest value is on top, else at bottom. |
121 * @note the current item stays at the same place. |
131 * @note the current item stays at the same place. |
122 */ |
132 */ |
123 void SortByItem(bool ascending); |
133 void Sort(SorterType sorter, bool ascending); |
124 |
|
125 /** |
|
126 * Sort this list by the value of the items. |
|
127 * @param ascending if true, lowest value is on top, else at bottom. |
|
128 * @note the current item stays at the same place. |
|
129 */ |
|
130 void SortByValue(bool ascending); |
|
131 |
134 |
132 /** |
135 /** |
133 * Removes all items with a higher value than 'value'. |
136 * Removes all items with a higher value than 'value'. |
134 * @param value the value above which all items are removed. |
137 * @param value the value above which all items are removed. |
135 */ |
138 */ |
151 /** |
154 /** |
152 * Remove all items with this value. |
155 * Remove all items with this value. |
153 * @param value the value to remove. |
156 * @param value the value to remove. |
154 */ |
157 */ |
155 void RemoveValue(int32 value); |
158 void RemoveValue(int32 value); |
|
159 |
|
160 /** |
|
161 * Remove the first count items. |
|
162 * @param count the amount of items to remove. |
|
163 */ |
|
164 void RemoveTop(int32 count); |
|
165 |
|
166 /** |
|
167 * Remove the last count items. |
|
168 * @param count the amount of items to remove. |
|
169 */ |
|
170 void RemoveBottom(int32 count); |
|
171 |
|
172 /** |
|
173 * Remove everything that is in the given list from this list (same item index that is). |
|
174 * @param list the list of items to remove. |
|
175 * @pre list != NULL |
|
176 */ |
|
177 void RemoveList(AIAbstractList *list); |
156 |
178 |
157 /** |
179 /** |
158 * Keep all items with a higher value than 'value'. |
180 * Keep all items with a higher value than 'value'. |
159 * @param value the value above which all items are kept. |
181 * @param value the value above which all items are kept. |
160 */ |
182 */ |
176 /** |
198 /** |
177 * Keep all items with this value. |
199 * Keep all items with this value. |
178 * @param value the value to keep. |
200 * @param value the value to keep. |
179 **/ |
201 **/ |
180 void KeepValue(int32 value); |
202 void KeepValue(int32 value); |
|
203 |
|
204 /** |
|
205 * Keep the first count items, i.e. remove everything except the first count items. |
|
206 * @param count the amount of items to keep. |
|
207 */ |
|
208 void KeepTop(int32 count); |
|
209 |
|
210 /** |
|
211 * Keep the last count items, i.e. remove everything except the last count items. |
|
212 * @param count the amount of items to keep. |
|
213 */ |
|
214 void KeepBottom(int32 count); |
|
215 |
|
216 /** |
|
217 * Keps everything that is in the given list from this list (same item index that is). |
|
218 * @param list the list of items to keep. |
|
219 * @pre list != NULL |
|
220 */ |
|
221 void KeepList(AIAbstractList *list); |
181 |
222 |
182 /** |
223 /** |
183 * The definition how valuators should look. |
224 * The definition how valuators should look. |
184 */ |
225 */ |
185 class Valuator { |
226 class Valuator { |