Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
operations_research::math_opt::Enum< E > Struct Template Reference

#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.
 

Detailed Description

template<typename E>
struct operations_research::math_opt::Enum< E >

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.

Definition at line 132 of file enums.h.

Member Typedef Documentation

◆ Proto

template<typename E >
using operations_research::math_opt::Enum< E >::Proto = int

The type of the Proto equivalent to this enum.

(Here we use int as a placeholder so that the code compiles.)

Definition at line 140 of file enums.h.

Member Function Documentation

◆ AllValues()

template<typename E >
absl::Span< const Limit > operations_research::math_opt::Enum< E >::AllValues ( )
static

Returns all possible values of the enum.

Definition at line 41 of file basis_status.cc.

◆ ToOptString()

template<typename E >
std::optional< absl::string_view > operations_research::math_opt::Enum< E >::ToOptString ( E value)
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.

Member Data Documentation

◆ kIsImplemented

template<typename E >
bool operations_research::math_opt::Enum< E >::kIsImplemented = false
staticconstexpr

Must be true in all implementation. This is used with std::enable_if to condition the implementation of some overloads.

Definition at line 135 of file enums.h.

◆ kProtoUnspecifiedValue

template<typename E >
Proto operations_research::math_opt::Enum< E >::kProtoUnspecifiedValue = {}
staticconstexpr

The value Proto enum that represents the unspecified case.

Definition at line 143 of file enums.h.


The documentation for this struct was generated from the following files: