1 /* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
2 
3 #include "SkirmishAIKey.h"
4 
5 #include "System/creg/creg_cond.h"
6 #include <string>
7 
8 
9 CR_BIND(SkirmishAIKey, )
10 
11 CR_REG_METADATA(SkirmishAIKey, (
12 		CR_MEMBER(shortName),
13 		CR_MEMBER(version),
14 		CR_MEMBER(interface)
15 		))
16 
SkirmishAIKey(const std::string & shortName,const std::string & version,const AIInterfaceKey & interface)17 SkirmishAIKey::SkirmishAIKey(
18 		const std::string& shortName,
19 		const std::string& version,
20 		const AIInterfaceKey& interface)
21 		: shortName(shortName),
22 		version(version),
23 		interface(interface) {}
24 
SkirmishAIKey(const SkirmishAIKey & base,const AIInterfaceKey & interface)25 SkirmishAIKey::SkirmishAIKey(const SkirmishAIKey& base,
26 		const AIInterfaceKey& interface)
27 		: shortName(base.shortName),
28 		version(base.version),
29 		interface(interface) {}
30 
SkirmishAIKey(const SkirmishAIKey & toCopy)31 SkirmishAIKey::SkirmishAIKey(const SkirmishAIKey& toCopy)
32 		: shortName(toCopy.shortName),
33 		version(toCopy.version),
34 		interface(toCopy.interface) {}
35 
~SkirmishAIKey()36 SkirmishAIKey::~SkirmishAIKey() {}
37 
38 
isEqual(const SkirmishAIKey & otherKey) const39 bool SkirmishAIKey::isEqual(const SkirmishAIKey& otherKey) const {
40 
41 	if (shortName == otherKey.shortName) {
42 		return version == otherKey.version;
43 	} else {
44 		return false;
45 	}
46 }
isLessThen(const SkirmishAIKey & otherKey) const47 bool SkirmishAIKey::isLessThen(const SkirmishAIKey& otherKey) const {
48 
49 	if (shortName == otherKey.shortName) {
50 		return version < otherKey.version;
51 	} else {
52 		return shortName < otherKey.shortName;
53 	}
54 }
55 
GetShortName() const56 const std::string& SkirmishAIKey::GetShortName() const {
57 	return shortName;
58 }
GetVersion() const59 const std::string& SkirmishAIKey::GetVersion() const {
60 	return version;
61 }
GetInterface() const62 const AIInterfaceKey& SkirmishAIKey::GetInterface() const {
63 	return interface;
64 }
65 
IsUnspecified() const66 bool SkirmishAIKey::IsUnspecified() const {
67 	return shortName == "";
68 }
IsFullySpecified() const69 bool SkirmishAIKey::IsFullySpecified() const {
70 	return shortName != "" || !interface.IsUnspecified();
71 }
72 
ToString() const73 std::string SkirmishAIKey::ToString() const {
74 	return GetShortName() + " " + GetVersion();
75 }
76 
operator ==(const SkirmishAIKey & otherKey) const77 bool SkirmishAIKey::operator==(const SkirmishAIKey& otherKey) const {
78 	return isEqual(otherKey);
79 }
operator !=(const SkirmishAIKey & otherKey) const80 bool SkirmishAIKey::operator!=(const SkirmishAIKey& otherKey) const {
81 	return !isEqual(otherKey);
82 }
operator <(const SkirmishAIKey & otherKey) const83 bool SkirmishAIKey::operator<(const SkirmishAIKey& otherKey) const {
84 	return isLessThen(otherKey);
85 }
operator >(const SkirmishAIKey & otherKey) const86 bool SkirmishAIKey::operator>(const SkirmishAIKey& otherKey) const {
87 	return !isLessThen(otherKey) && !isEqual(otherKey);
88 }
operator <=(const SkirmishAIKey & otherKey) const89 bool SkirmishAIKey::operator<=(const SkirmishAIKey& otherKey) const {
90 	return isLessThen(otherKey) || isEqual(otherKey);
91 }
operator >=(const SkirmishAIKey & otherKey) const92 bool SkirmishAIKey::operator>=(const SkirmishAIKey& otherKey) const {
93 	return !isLessThen(otherKey);
94 }
95