| 1 | #include "Library/Placement/PlacementId.h" |
| 2 | |
| 3 | #include "Library/Base/StringUtil.h" |
| 4 | #include "Library/Placement/PlacementInfo.h" |
| 5 | |
| 6 | namespace al { |
| 7 | |
| 8 | PlacementId::PlacementId() = default; |
| 9 | |
| 10 | PlacementId::PlacementId(const char* id, const char* unitConfig, const char* zoneId) |
| 11 | : mId(id), mUnitConfigName(unitConfig), mZoneId(zoneId) {} |
| 12 | |
| 13 | bool PlacementId::init(const PlacementInfo& info) { |
| 14 | mId = nullptr; |
| 15 | mZoneId = nullptr; |
| 16 | mUnitConfigName = nullptr; |
| 17 | mCommonId = nullptr; |
| 18 | |
| 19 | info.getPlacementIter().tryGetStringByKey(string: &mCommonId, key: "CommonId" ); |
| 20 | info.getZoneIter().tryGetStringByKey(string: &mUnitConfigName, key: "UnitConfigName" ); |
| 21 | info.getZoneIter().tryGetStringByKey(string: &mZoneId, key: "Id" ); |
| 22 | return info.getPlacementIter().tryGetStringByKey(string: &mId, key: "Id" ); |
| 23 | } |
| 24 | |
| 25 | bool PlacementId::isEqual(const PlacementId& otherId) const { |
| 26 | return isEqual(selfId: *this, otherId); |
| 27 | } |
| 28 | |
| 29 | __attribute__((always_inline)) bool PlacementId::isEqual(const PlacementId& selfId, |
| 30 | const PlacementId& otherId) { |
| 31 | if (selfId.getCommonId()) |
| 32 | return otherId.getCommonId() && isEqualString(str1: selfId.getCommonId(), str2: otherId.getCommonId()); |
| 33 | |
| 34 | if (otherId.getCommonId()) |
| 35 | return false; |
| 36 | |
| 37 | if (selfId.getUnitConfigName()) { |
| 38 | return otherId.getUnitConfigName() && |
| 39 | isEqualString(str1: selfId.getUnitConfigName(), str2: otherId.getUnitConfigName()) && |
| 40 | isEqualString(str1: selfId.getZoneId(), str2: otherId.getZoneId()) && selfId.getId() && |
| 41 | otherId.getId() && isEqualString(str1: selfId.getId(), str2: otherId.getId()); |
| 42 | } |
| 43 | |
| 44 | if (otherId.getUnitConfigName()) |
| 45 | return false; |
| 46 | |
| 47 | return selfId.getId() && otherId.getId() && isEqualString(str1: selfId.getId(), str2: otherId.getId()); |
| 48 | } |
| 49 | |
| 50 | bool PlacementId::isValid() const { |
| 51 | return mCommonId || mId; |
| 52 | } |
| 53 | |
| 54 | void PlacementId::makeString(sead::BufferedSafeString* out) const { |
| 55 | if (mCommonId) |
| 56 | out->format(formatStr: mCommonId); |
| 57 | else if (mUnitConfigName) |
| 58 | out->format(formatStr: "%s(%s[%s])" , mId, mUnitConfigName, mZoneId); |
| 59 | else if (mId) |
| 60 | out->format(formatStr: mId); |
| 61 | else |
| 62 | out->format(formatStr: "" ); |
| 63 | } |
| 64 | |
| 65 | StringTmp<128> makeStringPlacementId(const PlacementId* placementId) { |
| 66 | StringTmp<128> string; |
| 67 | if (placementId) |
| 68 | placementId->makeString(out: &string); |
| 69 | return string; |
| 70 | } |
| 71 | |
| 72 | } // namespace al |
| 73 | |