79#ifndef OR_TOOLS_MATH_OPT_CPP_ENUMS_H_
80#define OR_TOOLS_MATH_OPT_CPP_ENUMS_H_
86#include "absl/log/check.h"
87#include "absl/strings/string_view.h"
88#include "absl/types/span.h"
201std::optional<typename EnumProto<P>::Cpp>
EnumFromProto(P proto_value);
234 typename = std::enable_if_t<Enum<E>::kIsImplemented>>
237 if (opt_str.has_value()) {
240 out <<
"<invalid enum (" <<
static_cast<std::underlying_type_t<E>
>(
value)
253 typename = std::enable_if_t<Enum<E>::kIsImplemented>>
254std::ostream&
operator<<(std::ostream& out,
const std::optional<E> opt_value) {
255 if (opt_value.has_value()) {
258 out <<
"<unspecified>";
279std::optional<typename EnumProto<P>::Cpp>
EnumFromProto(
const P proto_value) {
289 CHECK(opt_str.has_value())
290 <<
"invalid value: " <<
static_cast<std::underlying_type_t<E>
>(
value);
323#define MATH_OPT_DEFINE_ENUM(CppEnum, proto_unspecified_value) \
325 struct Enum<CppEnum> { \
326 static constexpr bool kIsImplemented = true; \
327 using Proto = CppEnum##Proto; \
328 static constexpr Proto kProtoUnspecifiedValue = proto_unspecified_value; \
329 static std::optional<absl::string_view> ToOptString(CppEnum value); \
330 static absl::Span<const CppEnum> AllValues(); \
334 struct EnumProto<CppEnum##Proto> { \
335 using Cpp = CppEnum; \
336 static constexpr CppEnum##Proto kMin = CppEnum##Proto##_MIN; \
337 static constexpr CppEnum##Proto kMax = CppEnum##Proto##_MAX; \
338 static constexpr ProtoEnumIsValid kIsValid = CppEnum##Proto##_IsValid; \
An object oriented wrapper for quadratic constraints in ModelStorage.
std::optional< absl::string_view > EnumToOptString(E value)
std::optional< typename EnumProto< P >::Cpp > EnumFromProto(P proto_value)
std::ostream & operator<<(std::ostream &ostr, const IndicatorConstraint &constraint)
std::optional< E > EnumFromString(absl::string_view str)
Enum< E >::Proto EnumToProto(std::optional< E > value)
absl::string_view EnumToString(E value)
bool(*)(int) ProtoEnumIsValid
static constexpr P kMin
The smallest valid enum value.
static constexpr P kMax
The largest valid enum value.
static constexpr ProtoEnumIsValid kIsValid
static constexpr Proto kProtoUnspecifiedValue
The value Proto enum that represents the unspecified case.
static absl::Span< const E > AllValues()
Returns all possible values of the enum.
static constexpr bool kIsImplemented
static std::optional< absl::string_view > ToOptString(E value)