Google OR-Tools v9.12
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
proto_enum_utils.h File Reference
#include <iterator>
#include <type_traits>
#include "absl/types/span.h"
#include "google/protobuf/descriptor.pb.h"

Go to the source code of this file.

Classes

class  google::protobuf::contrib::utils::ProtoEnumIterator< E >
 Generic Proto enum iterator. More...
 
class  google::protobuf::contrib::utils::EnumeratedProtoEnumView< E >
 
class  google::protobuf::contrib::utils::internal::RepeatedEnumView< E >
 
class  google::protobuf::contrib::utils::internal::RepeatedEnumView< E >::Iterator
 

Namespaces

namespace  google
 
namespace  google::protobuf
 
namespace  google::protobuf::contrib
 
namespace  google::protobuf::contrib::utils
 
namespace  google::protobuf::contrib::utils::internal
 

Macros

#define REPEATED_ENUM_ADAPTER(var, field)
 

Functions

template<typename E>
bool google::protobuf::contrib::utils::operator== (const ProtoEnumIterator< E > &a, const ProtoEnumIterator< E > &b)
 
template<typename E>
bool google::protobuf::contrib::utils::operator!= (const ProtoEnumIterator< E > &a, const ProtoEnumIterator< E > &b)
 
template<typename E>
EnumeratedProtoEnumView< E > google::protobuf::contrib::utils::EnumerateEnumValues ()
 

Macro Definition Documentation

◆ REPEATED_ENUM_ADAPTER

#define REPEATED_ENUM_ADAPTER ( var,
field )
Value:

Returns a view that allows to iterate directly over the enum values in an enum repeated field, wrapping the repeated field with a type-safe iterator that provides access to the enum values.

for (Enum enum : REPEATED_ENUM_ADAPTER(message, repeated_enum_field)) { ... }

It provides greater safety than iterating over the enum directly, as the following will fail to type-check:

.proto RightEnum enum = 5;

client .cc for (WrongEnum e : REPEATED_ENUM_ADAPTER(proto, enum)) { <- Error: Cannot cast from RightEnum to WrongEnum }

Note
As per http://shortn/_CYfjpruK6N, unrecognized enum values are treated differently between proto2 and proto3.

For proto2, they are stripped out from the message when read, so all unrecognized enum values from the wire format will be skipped when iterating over the wrapper (this is the same behavior as iterating over the RepeatedField<int> directly).

For proto3, they are left as-is, so unrecognized enum values from the wire format will still be returned when iterating over the wrapper (this is the same behavior as iterating over the RepeatedField<int> directly).

Definition at line 164 of file proto_enum_utils.h.