1 /* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */ 2 3 #ifndef I_AI_LIBRARY_MANAGER_H 4 #define I_AI_LIBRARY_MANAGER_H 5 6 #include "AIInterfaceLibraryInfo.h" 7 #include "SkirmishAILibraryInfo.h" 8 9 #include <vector> 10 #include <map> 11 #include <set> 12 13 class AIInterfaceKey; 14 class SkirmishAIKey; 15 class CSkirmishAILibrary; 16 17 /** 18 * @brief manages AIs and AI interfaces 19 * @see CAILibraryManager 20 */ 21 class IAILibraryManager { 22 public: IAILibraryManager()23 IAILibraryManager() {} ~IAILibraryManager()24 virtual ~IAILibraryManager() {} 25 26 typedef std::set<AIInterfaceKey> T_interfaceSpecs; 27 typedef std::set<SkirmishAIKey> T_skirmishAIKeys; 28 29 virtual const T_interfaceSpecs& GetInterfaceKeys() const = 0; 30 virtual const T_skirmishAIKeys& GetSkirmishAIKeys() const = 0; 31 32 typedef std::map<const AIInterfaceKey, CAIInterfaceLibraryInfo*> 33 T_interfaceInfos; 34 typedef std::map<const SkirmishAIKey, CSkirmishAILibraryInfo*> 35 T_skirmishAIInfos; 36 37 virtual const T_interfaceInfos& GetInterfaceInfos() const = 0; 38 virtual const T_skirmishAIInfos& GetSkirmishAIInfos() const = 0; 39 40 typedef std::map<const AIInterfaceKey, std::set<std::string> > T_dupInt; 41 typedef std::map<const SkirmishAIKey, std::set<std::string> > 42 T_dupSkirm; 43 44 /** 45 * Returns a set of files which contain duplicate AI Interface infos. 46 * This can be used for issueing warnings. 47 */ 48 virtual const T_dupInt& GetDuplicateInterfaceInfos() const = 0; 49 /** 50 * Returns a set of files which contain duplicate Skirmish AI infos. 51 * This can be used for issueing warnings. 52 */ 53 virtual const T_dupSkirm& GetDuplicateSkirmishAIInfos() const = 0; 54 /** 55 * Returns a resolved aikey 56 * @see SkirmishAIKey::IsUnspecified() 57 */ 58 SkirmishAIKey ResolveSkirmishAIKey(const SkirmishAIKey& skirmishAIKey) 59 const; 60 61 /** 62 * A Skirmish AI (its library) is only really loaded when it is not yet 63 * loaded. 64 */ 65 virtual const CSkirmishAILibrary* FetchSkirmishAILibrary( 66 const SkirmishAIKey& skirmishAIKey) = 0; 67 /** 68 * A Skirmish AI is only unloaded when ReleaseSkirmishAILibrary() is called 69 * as many times as GetSkirmishAILibrary() was. 70 * loading and unloading of the interfaces 71 * is handled internally/automatically. 72 */ 73 virtual void ReleaseSkirmishAILibrary(const SkirmishAIKey& skirmishAIKey) = 0; 74 75 /** Guaranteed to not return NULL. */ 76 static IAILibraryManager* GetInstance(); 77 /** Should only be called at end of game/process */ 78 static void Destroy(); 79 static void OutputAIInterfacesInfo(); 80 static void OutputSkirmishAIInfo(); 81 82 protected: 83 virtual std::vector<SkirmishAIKey> FittingSkirmishAIKeys( 84 const SkirmishAIKey& skirmishAIKey) const = 0; 85 86 /** 87 * Compares two version strings. 88 * Splits the version strings at the '.' signs, and compares the parts. 89 * If the number of parts do not match, then the string with less parts 90 * is filled up with '.0' parts at its right, eg: 91 * version 1: 0.1.2 -> 0.1.2.0 92 * version 2: 0.1.2.3 -> 0.1.2.3 93 * The left most part has the highest significance. 94 * Comparison of the individual parts is done with std::string::compare(), 95 * which implies for example that letters > numbers. 96 * examples: 97 * ("2", "1") -> 1 98 * ("1", "1") -> 0 99 * ("1", "2") -> -1 100 * ("0.1.1", "0.1") -> 1 101 * ("1.a", "1.9") -> 1 102 * ("1.a", "1.A") -> 1 103 */ 104 static int VersionCompare( 105 const std::string& version1, 106 const std::string& version2); 107 108 private: 109 static IAILibraryManager* myAILibraryManager; 110 }; 111 112 #define aiLibManager IAILibraryManager::GetInstance() 113 114 #endif // I_AI_LIBRARY_MANAGER_H 115