15#ifndef OR_TOOLS_MATH_OPT_ELEMENTAL_SAFE_ATTR_OPS_H_
16#define OR_TOOLS_MATH_OPT_ELEMENTAL_SAFE_ATTR_OPS_H_
21#include "absl/status/status.h"
22#include "absl/status/statusor.h"
23#include "absl/strings/str_cat.h"
30template <
typename AttrType>
37 if (attr < 0 || attr >= Descriptor::NumAttrs()) {
38 return absl::InvalidArgumentError(
39 absl::StrCat(
"invalid attribute ", attr));
41 return static_cast<AttrType
>(attr);
#define ASSIGN_OR_RETURN(lhs, rexpr)
Policy::CheckResultT SetAttr(AttrType a, AttrKeyFor< AttrType > key, ValueTypeFor< AttrType > value)
std::vector< AttrKeyFor< AttrType > > AttrNonDefaults(const AttrType a) const
Return the vector of attribute keys where a is non-default.
int64_t AttrNumNonDefaults(const AttrType a) const
Returns the number of keys where a is non-default.
Policy::template Wrapped< bool > AttrIsNonDefault(AttrType a, AttrKeyFor< AttrType > key) const
Policy::template Wrapped< ValueTypeFor< AttrType > > GetAttr(AttrType a, AttrKeyFor< AttrType > key) const
An object oriented wrapper for quadratic constraints in ModelStorage.
AttrKey< AttrTypeDescriptorT< AttrType >::kNumKeyElements, typename AttrTypeDescriptorT< AttrType >::Symmetry > AttrKeyFor
The type of the AttrKey for attribute type AttrType.
AllAttrs::TypeDescriptor< AllAttrs::GetIndex< AttrT >()> AttrTypeDescriptorT
Returns the descriptor for attribute AttrT.
static absl::StatusOr< ValueType > Get(Elemental *e, int attr, Key key)
static absl::StatusOr< bool > IsNonDefault(Elemental *e, int attr, Key key)
static absl::StatusOr< AttrType > SafeCastAttr(int attr)
AttrKeyFor< AttrType > Key
static absl::Status Set(Elemental *e, int attr, Key key, ValueType value)
AttrTypeDescriptorT< AttrType > Descriptor
typename Descriptor::ValueType ValueType
static absl::StatusOr< int64_t > NumNonDefaults(Elemental *e, int attr)
static absl::StatusOr< std::vector< Key > > GetNonDefaults(Elemental *e, int attr)