ai_abstractlist.hpp

Go to the documentation of this file.
00001 /* $Id$ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
00008  */
00009 
00013 #ifndef AI_ABSTRACTLIST_HPP
00014 #define AI_ABSTRACTLIST_HPP
00015 
00016 #include "ai_object.hpp"
00017 #include <map>
00018 #include <set>
00019 
00020 class AIAbstractListSorter;
00021 
00025 class AIAbstractList : public AIObject {
00026 public:
00027   static const char *GetClassName() { return "AIAbstractList"; }
00028 
00030   enum SorterType {
00031     SORT_BY_VALUE, 
00032     SORT_BY_ITEM,  
00033   };
00034 
00036   static const bool SORT_ASCENDING = true;
00038   static const bool SORT_DESCENDING = false;
00039 
00040 private:
00041   AIAbstractListSorter *sorter; 
00042   SorterType sorter_type;       
00043   bool sort_ascending;          
00044   bool initialized;             
00045   int modifications;            
00046 
00047 public:
00048   typedef std::set<int32> AIItemList;                       
00049   typedef std::map<int32, AIItemList> AIAbstractListBucket; 
00050   typedef std::map<int32, int32> AIAbstractListMap;         
00051 
00052   AIAbstractListMap items;           
00053   AIAbstractListBucket buckets;      
00054 
00055 protected:
00061   void AddItem(int32 item);
00062 
00067   void RemoveItem(int32 item);
00068 
00069 public:
00070   AIAbstractList();
00071   ~AIAbstractList();
00072 
00076   void Clear();
00077 
00083   bool HasItem(int32 item);
00084 
00089   int32 Begin();
00090 
00096   int32 Next();
00097 
00102   bool IsEmpty();
00103 
00109   bool HasNext();
00110 
00115   int32 Count();
00116 
00122   int32 GetValue(int32 item);
00123 
00132   bool SetValue(int32 item, int32 value);
00133 
00141   void Sort(SorterType sorter, bool ascending);
00142 
00151   void AddList(AIAbstractList *list);
00152 
00157   void RemoveAboveValue(int32 value);
00158 
00163   void RemoveBelowValue(int32 value);
00164 
00170   void RemoveBetweenValue(int32 start, int32 end);
00171 
00176   void RemoveValue(int32 value);
00177 
00182   void RemoveTop(int32 count);
00183 
00188   void RemoveBottom(int32 count);
00189 
00195   void RemoveList(AIAbstractList *list);
00196 
00201   void KeepAboveValue(int32 value);
00202 
00207   void KeepBelowValue(int32 value);
00208 
00214   void KeepBetweenValue(int32 start, int32 end);
00215 
00220   void KeepValue(int32 value);
00221 
00226   void KeepTop(int32 count);
00227 
00232   void KeepBottom(int32 count);
00233 
00239   void KeepList(AIAbstractList *list);
00240 
00241 #ifndef DOXYGEN_SKIP
00242 
00245   SQInteger _get(HSQUIRRELVM vm);
00246 
00250   SQInteger _nexti(HSQUIRRELVM vm);
00251 
00255   SQInteger Valuate(HSQUIRRELVM vm);
00256 #else
00257 
00276   void Valuate(void *valuator_function, int params, ...);
00277 #endif /* DOXYGEN_SKIP */
00278 };
00279 
00280 #endif /* AI_LIST_HPP */

Generated on Sat Dec 26 20:05:58 2009 for OpenTTD by  doxygen 1.5.6