TrinityCore
CommonPredicates.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef TRINITY_COMMONPREDICATES_H
19#define TRINITY_COMMONPREDICATES_H
20
21#include "Define.h"
22#include <utility>
23
24class Unit;
25class WorldObject;
26
27enum Powers : int8;
28
29namespace Trinity
30{
31 namespace Predicates
32 {
35 {
36 public:
37 IsVictimOf(Unit const* attacker);
38 bool operator()(WorldObject const* obj) const { return obj && (_victim == obj); }
39 private:
41 };
42
45 {
46 public:
47 PowerPctOrderPred(Powers power, bool ascending = true) : _power(power), _ascending(ascending) { }
48
49 bool operator()(WorldObject const* objA, WorldObject const* objB) const;
50 bool operator()(Unit const* a, Unit const* b) const;
51
52 private:
54 bool const _ascending;
55 };
56
59 {
60 public:
61 HealthPctOrderPred(bool ascending = true) : _ascending(ascending) { }
62
63 bool operator()(WorldObject const* objA, WorldObject const* objB) const;
64 bool operator() (Unit const* a, Unit const* b) const;
65
66 private:
67 bool const _ascending;
68 };
69
70 template <typename PRED>
72 {
73 public:
74 Inverter(PRED&& p) : _child(std::move(p)) { }
75
76 template <typename... Args>
77 bool operator()(Args&&... args)
78 {
79 return !_child(std::forward<Args>(args)...);
80 }
81
82 template <typename... Args>
83 bool operator()(Args&&... args) const
84 {
85 return !_child(std::forward<Args>(args)...);
86 }
87
88 private:
89 PRED _child;
90 };
91
92 template <typename PRED>
94 Inverter<PRED> Invert(PRED&& p) { return Inverter<PRED>(std::forward<PRED>(p)); }
95 }
96}
97
98#endif //TRINITY_COMMONPREDICATES_H
#define TC_GAME_API
Definition: Define.h:123
int8_t int8
Definition: Define.h:140
Powers
Binary predicate for sorting Units based on percent value of health.
bool operator()(Args &&... args)
bool operator()(Args &&... args) const
Only returns true for the given attacker's current victim, if any.
bool operator()(WorldObject const *obj) const
Binary predicate for sorting Units based on percent value of a power.
PowerPctOrderPred(Powers power, bool ascending=true)
Definition: Unit.h:627
Inverter< PRED > Invert(PRED &&p)
Inverts the given predicate to return the opposite result.
STL namespace.