Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
|
#include <enums.h>
Public Types | |
using | Proto = int |
Static Public Member Functions | |
static std::optional< absl::string_view > | ToOptString (E value) |
static absl::Span< const E > | AllValues () |
Returns all possible values of the enum. | |
Static Public Attributes | |
static constexpr bool | kIsImplemented = false |
static constexpr Proto | kProtoUnspecifiedValue = {} |
The value Proto enum that represents the unspecified case. | |
This template is specialized for each enum in the C++ API.
It provides a standard way to query properties of those enums and it is used by some global functions below to implement conversion from/to string or proto enum.
Usage example:
///< Iterating on all enum values. for (const auto solver_type : Enum<SolverType>::AllValues()) { ... }
///< Parsing a flag as an enum. const std::optional<SolverType> solver_type = EnumFromString(absl::GetFlag(FLAGS_solver_type)); if (!solver_type) { return util::InvalidArgumentErrorBuilder() _ << "failed to parse --solver_type value: " << absl::GetFlag(FLAGS_solver_type); }
///< Conversion to string. const SolverType solver_type = ...; LOG(INFO) << "solver: " << solver_type; absl::StrCat(EnumToString(solver_type), "_test"); absl::StrCat(EnumToOptString(solver_type).value(), "_test");
///< Conversion to Proto. const std::optional<SolverType> opt_solver_type = ...; const SolverTypeProto solver_type_proto = EnumToProto(opt_solver_type);
///< Conversion from Proto. const SolverTypeProto solver_type_proto = ...; const std::optional<SolverType> opt_solver_type = EnumFromProto(solver_type_proto);
Implementation note: don't specialize directly and instead use the MATH_OPT_DEFINE_ENUM macro.
using operations_research::math_opt::Enum< E >::Proto = int |
|
static |
Returns all possible values of the enum.
Definition at line 41 of file basis_status.cc.
|
static |
Returns a unique string that represent the enum. Returns nullopt if the input value is not a valid value of the enum.
The returned string should not include the enum name and should be in snake_case (e.g. is the enum is kNoSolutionFound, this should return "no_solution_found").
Please prefer using the global functions EnumToString() (or EnumToOptString() if support for invalid values is needed) instead to benefit from automatic template type deduction.
Definition at line 24 of file basis_status.cc.
|
staticconstexpr |
|
staticconstexpr |