ai_abstractlist.hpp

Go to the documentation of this file.
00001 /* $Id: ai_abstractlist.hpp 19300 2010-03-02 00:38:01Z rubidium $ */
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 
00068   void RemoveItem(int32 item);
00069 
00070 public:
00071   AIAbstractList();
00072   ~AIAbstractList();
00073 
00077   void Clear();
00078 
00084   bool HasItem(int32 item);
00085 
00090   int32 Begin();
00091 
00097   int32 Next();
00098 
00103   bool IsEmpty();
00104 
00110   bool HasNext();
00111 
00116   int32 Count();
00117 
00123   int32 GetValue(int32 item);
00124 
00133   bool SetValue(int32 item, int32 value);
00134 
00142   void Sort(SorterType sorter, bool ascending);
00143 
00152   void AddList(AIAbstractList *list);
00153 
00158   void RemoveAboveValue(int32 value);
00159 
00164   void RemoveBelowValue(int32 value);
00165 
00171   void RemoveBetweenValue(int32 start, int32 end);
00172 
00177   void RemoveValue(int32 value);
00178 
00183   void RemoveTop(int32 count);
00184 
00189   void RemoveBottom(int32 count);
00190 
00196   void RemoveList(AIAbstractList *list);
00197 
00202   void KeepAboveValue(int32 value);
00203 
00208   void KeepBelowValue(int32 value);
00209 
00215   void KeepBetweenValue(int32 start, int32 end);
00216 
00221   void KeepValue(int32 value);
00222 
00227   void KeepTop(int32 count);
00228 
00233   void KeepBottom(int32 count);
00234 
00240   void KeepList(AIAbstractList *list);
00241 
00242 #ifndef DOXYGEN_SKIP
00243 
00246   SQInteger _get(HSQUIRRELVM vm);
00247 
00251   SQInteger _nexti(HSQUIRRELVM vm);
00252 
00256   SQInteger Valuate(HSQUIRRELVM vm);
00257 #else
00258 
00277   void Valuate(void *valuator_function, int params, ...);
00278 #endif /* DOXYGEN_SKIP */
00279 };
00280 
00281 #endif /* AI_LIST_HPP */

Generated on Tue Sep 14 17:06:46 2010 for OpenTTD by  doxygen 1.6.1