forked from RobotLocomotion/drake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolver_id.h
70 lines (58 loc) · 2.11 KB
/
solver_id.h
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
#pragma once
#include <functional>
#include <ostream>
#include <string>
#include "drake/common/drake_copyable.h"
#include "drake/common/hash.h"
#include "drake/common/reset_after_move.h"
namespace drake {
namespace solvers {
/// Identifies a SolverInterface implementation.
///
/// A moved-from instance is guaranteed to be empty and will not compare equal
/// to any non-empty ID.
class SolverId {
public:
DRAKE_DEFAULT_COPY_AND_MOVE_AND_ASSIGN(SolverId)
~SolverId() = default;
/// Constructs a specific, known solver type. Internally, a hidden
/// identifier is allocated and assigned to this instance; all instances that
/// share an identifier (including copies of this instance) are considered
/// equal. The solver names are not enforced to be unique, though we
/// recommend that they remain so in practice.
explicit SolverId(std::string name);
const std::string& name() const { return name_; }
/// Implements the @ref hash_append concept.
template <class HashAlgorithm>
friend void hash_append(HashAlgorithm& hasher,
const SolverId& item) noexcept {
using drake::hash_append;
hash_append(hasher, int{item.id_});
// We do not send the name_ to the hasher, because the id_ is already
// unique across all instances.
}
private:
friend bool operator==(const SolverId&, const SolverId&);
friend bool operator!=(const SolverId&, const SolverId&);
friend struct std::less<SolverId>;
reset_after_move<int> id_;
std::string name_;
};
bool operator==(const SolverId&, const SolverId&);
bool operator!=(const SolverId&, const SolverId&);
std::ostream& operator<<(std::ostream&, const SolverId&);
} // namespace solvers
} // namespace drake
namespace std {
/* Provides std::less<drake::solvers::SolverId>. */
template <>
struct less<drake::solvers::SolverId> {
bool operator()(const drake::solvers::SolverId& lhs,
const drake::solvers::SolverId& rhs) const {
return lhs.id_ < rhs.id_;
}
};
/* Provides std::hash<drake::solvers::SolverId>. */
template <>
struct hash<drake::solvers::SolverId> : public drake::DefaultHash {};
} // namespace std