fsfw/src/fsfw/util/ObjectId.h

39 lines
1.1 KiB
C
Raw Normal View History

2022-07-29 14:15:05 +02:00
#ifndef FSFW_UTIL_OBJECTID_H
#define FSFW_UTIL_OBJECTID_H
#include <functional>
2022-07-29 15:54:17 +02:00
#include "UnsignedByteField.h"
#include "fsfw/objectmanager.h"
class ObjectId : public UnsignedByteField<object_id_t> {
2022-07-29 14:15:05 +02:00
public:
2022-07-29 15:54:17 +02:00
ObjectId(object_id_t id, const char* name) : UnsignedByteField<object_id_t>(id), name_(name) {}
[[nodiscard]] const char* name() const { return name_; }
2022-07-29 14:15:05 +02:00
2022-07-29 15:54:17 +02:00
[[nodiscard]] object_id_t id() const { return getValue(); }
2022-07-29 14:15:05 +02:00
2022-07-29 15:54:17 +02:00
bool operator==(const ObjectId& other) const { return id() == other.id(); }
2022-07-29 14:15:05 +02:00
2022-07-29 15:54:17 +02:00
bool operator!=(const ObjectId& other) const { return id() != other.id(); }
2022-07-29 14:15:05 +02:00
2022-07-29 15:54:17 +02:00
bool operator<(const ObjectId& other) const { return id() < other.id(); }
2022-07-29 14:15:05 +02:00
2022-07-29 15:54:17 +02:00
bool operator>(const ObjectId& other) const { return id() > other.id(); }
2022-07-29 14:15:05 +02:00
2022-07-29 15:54:17 +02:00
bool operator>=(const ObjectId& other) const { return id() >= other.id(); }
2022-07-29 14:15:05 +02:00
2022-07-29 15:54:17 +02:00
bool operator<=(const ObjectId& other) const { return id() <= other.id(); }
2022-07-29 14:15:05 +02:00
private:
const char* name_;
};
2022-07-29 15:54:17 +02:00
template <>
struct std::hash<ObjectId> {
std::size_t operator()(ObjectId const& s) const noexcept { return std::hash<uint32_t>{}(s.id()); }
2022-07-29 14:15:05 +02:00
};
#endif // FSFW_UTIL_OBJECTID_H