File: IAILibraryManager.h

package info (click to toggle)
spring 0.81.2.1%2Bdfsg1-6
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 28,496 kB
  • ctags: 37,096
  • sloc: cpp: 238,659; ansic: 13,784; java: 12,175; awk: 3,428; python: 1,159; xml: 738; perl: 405; sh: 297; makefile: 267; pascal: 228; objc: 192
file content (124 lines) | stat: -rw-r--r-- 4,011 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
	Copyright (c) 2008 Robin Vobruba <hoijui.quaero@gmail.com>

	This program 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; either version 2 of the License, or
	(at your option) any later version.

	This program 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.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _IAILIBRARYMANAGER_H
#define _IAILIBRARYMANAGER_H

#include "AIInterfaceLibraryInfo.h"
#include "SkirmishAILibraryInfo.h"

#include <vector>
#include <map>
#include <set>

class AIInterfaceKey;
class SkirmishAIKey;
class CSkirmishAILibrary;

/**
 * @brief manages AIs and AI interfaces
 * @see CAILibraryManager
 */
class IAILibraryManager {

public:
	virtual ~IAILibraryManager() {}

	typedef std::set<AIInterfaceKey> T_interfaceSpecs;
	typedef std::set<SkirmishAIKey> T_skirmishAIKeys;

	virtual const T_interfaceSpecs& GetInterfaceKeys() const = 0;
	virtual const T_skirmishAIKeys& GetSkirmishAIKeys() const = 0;

	typedef std::map<const AIInterfaceKey, CAIInterfaceLibraryInfo*>
			T_interfaceInfos;
	typedef std::map<const SkirmishAIKey, CSkirmishAILibraryInfo*>
			T_skirmishAIInfos;

	virtual const T_interfaceInfos& GetInterfaceInfos() const = 0;
	virtual const T_skirmishAIInfos& GetSkirmishAIInfos() const = 0;

	typedef std::map<const AIInterfaceKey, std::set<std::string> > T_dupInt;
	typedef std::map<const SkirmishAIKey, std::set<std::string> >
			T_dupSkirm;

	// The following three methods return sets of files which contain duplicate
	// infos. These methods can be used for issueing warnings.
	virtual const T_dupInt& GetDuplicateInterfaceInfos() const = 0;
	virtual const T_dupSkirm& GetDuplicateSkirmishAIInfos() const = 0;

	SkirmishAIKey ResolveSkirmishAIKey(const SkirmishAIKey& skirmishAIKey)
			const;
protected:
	virtual std::vector<SkirmishAIKey> FittingSkirmishAIKeys(
			const SkirmishAIKey& skirmishAIKey) const = 0;
public:
	/**
	 * A Skirmish AI (its library) is only really loaded when it is not yet
	 * loaded.
	 */
	virtual const CSkirmishAILibrary* FetchSkirmishAILibrary(
			const SkirmishAIKey& skirmishAIKey) = 0;
	/**
	 * A Skirmish AI is only unloaded when ReleaseSkirmishAILibrary() is called
	 * as many times as GetSkirmishAILibrary() was.
	 * loading and unloading of the interfaces
	 * is handled internally/automatically.
	 */
	virtual void ReleaseSkirmishAILibrary(const SkirmishAIKey& skirmishAIKey) = 0;
	/** Unloads all currently Skirmish loaded AIs. */
	virtual void ReleaseAllSkirmishAILibraries() = 0;

	/** Unloads all currently loaded AIs and interfaces. */
	virtual void ReleaseEverything() = 0;

public:
	/** Guaranteed to not return NULL. */
	static IAILibraryManager* GetInstance();
	static void OutputAIInterfacesInfo();
	static void OutputSkirmishAIInfo();

protected:
	/**
	 * Compares two version strings.
	 * Splits the version strings at the '.' signs, and compares the parts.
	 * If the number of parts do not match, then the string with less parts
	 * is filled up with '.0' parts at its right, eg:
	 * version 1: 0.1.2   -> 0.1.2.0
	 * version 2: 0.1.2.3 -> 0.1.2.3
	 * The left most part has the highest significance.
	 * Comparison of the individual parts is done with std::string::compare(),
	 * which implies for example that letters > numbers.
	 * examples:
	 * ("2", "1") -> 1
	 * ("1", "1") -> 0
	 * ("1", "2") -> -1
	 * ("0.1.1", "0.1") -> 1
	 * ("1.a", "1.9") -> 1
	 * ("1.a", "1.A") -> 1
	 */
	static int VersionCompare(
			const std::string& version1,
			const std::string& version2);

private:
	static IAILibraryManager* myAILibraryManager;
};

#define aiLibManager IAILibraryManager::GetInstance()

#endif // _IAILIBRARYMANAGER_H